751-1
} / / An object of class car keeps track of the current
/ / Mileage and the existing fuel supply.
public class Car {
/ / mileage, according to speedometer
private int kmStand;
/ / consumption to 100 km double
private consumption;
/ / volume of the tank, fits more fuel not fit tank volume
private double;
/ / in the tank fuel
private double fuel supply;
/ / General Constructor: Attributes kmStand, consumption,
/ tank volume / and fuel storage initialize
/ / The fuel supply may be not greater than the tank volume.
public Car (int km, double bridged, double volume, double last)
{
kmStand = km;
consumption = bridged;
tank volume = volume;
if (storage volume>)
reserve = volume;
fuel storage = storage;
}
/ / attribute values of the oject car
public String toString () return
{
("mileage" + kmStand + "Usage:" + consumption + "Tank:"
tank volume + + "set: "Fuel supply +);
}
/ / info: Is the current mileage and fuel tank capacity of
public void info ()
{
System.out.println (" kmStand: "+ kmStand +
" fuel supply " + fuel storage);}
/ / drive: We drive the specified number of miles.
/ / The mileage will be adjusted and the fuel supply
/ / reduced accordingly. We can of course only
/ / so far are, as the fuel supply limitations in the tank.
public void run (int km) {
System.out.println ("go (" + km + ")");
/ / here is an explicit cast double -> int int
necessary current range = ( current range
if (km> current range)
km =, int) (fuel supply / consumption * 100) =
kmStand kmStand + km;
fuel supply = Fuel supply - km / 100 * consumption;
System.out.println (km + km on the clock. ");}
refuel / /: This argument specifies liter,
/ / how much fuel should be recharged .
/ / Note: the volume of the tank is limited!
/ / We are allowed to fill up too much fuel.
public void fill (double liter)
{
System.out.println ("fill up (" + l + ")");
if (fuel storage + tank volume liter>)
liter tank volume = - fuel storage;
Fuel tank capacity = fuel supply + Liters;
System.out.println (liters + "liter tank.");}
} / / public class Bus extends Omnibus
car
{/ / Number of seats Number of seats
private int;
/ / General Constructor: kmStand attributes, consumption,
/ / tank volume, fuel capacity and number of seats initialize
public bus (int km, double bridged, double volume, double reservoir, int seats)
{
/ / constructor of the superclass call
super ( km, bridged volume, store);
number of seats = seats;}
/ / Attribute values of the oject Omnibus
public String toString ()
{return
(super.toString () + "seats" + number of seats);
}
}
public class Car
{
/ / Main program to test the Car class
public static void main (String [] args) {
Goggomobil car = new Car (0, 5.0, 50.0, 30.0);
einBus bus = new Bus (0, 5.0, 50.0, 30.0, 12);
System.out.println (Goggomobil);
System.out.println (einBus);
goggoMobil.info ();
goggoMobil.fahren (300);
goggoMobil.info ();
goggoMobil.tanken (45.0); goggoMobil.fahren
(800);
goggoMobil.info () goggoMobil.fahren
(700);
goggoMobil.info ()
Goggomobil. info ();}
Thursday, November 16, 2006
Monday, November 6, 2006
How To Make Fire Bricks
fmt @ 2006-11-06T20: 23:00
} public class Program {
public static void main (String args []) {
zahlenBis int = 100;
/ / adjust numbers: from 2 .. and # of . determine the fields
zahlenVon int = 2;
int = anzFelder zahlenBis - 1;
/ / arrays
int [] numbers = new int field [anzFelder];
boolean [] number info = new boolean [anzFelder];
/ / All figures write
for (int i = 0; i \u0026lt;zahlenFeld.length; i + +, zahlenVon + +)
{
[i] number field = zahlenVon;
}
/ / values for all numbers to true
for (int i = 0; i \u0026lt;zahlenInfo.length; i + +) {
number info [i] = true;}
/ / prime loop
for ( int i = 0; i \u0026lt;zahlenFeld.length; i + +) {
/ / is Prime?
if (number info [i] == true) {
for (int j = i +1, j \u0026lt;zahlenFeld.length j + +) {
if (number info [j] == true & (number field [j] % number of field [i]) == 0) {
number info [j] = false;}
}}
} / / output the primes
for (int i = 0; i \u0026lt;zahlenFeld.length ; i + +) {
if (number info [i] == true) {
System.out.println (number field [i] + "");}
}
}}
} public class Program {
public static void main (String args []) {
zahlenBis int = 100;
/ / adjust numbers: from 2 .. and # of . determine the fields
zahlenVon int = 2;
int = anzFelder zahlenBis - 1;
/ / arrays
int [] numbers = new int field [anzFelder];
boolean [] number info = new boolean [anzFelder];
/ / All figures write
for (int i = 0; i \u0026lt;zahlenFeld.length; i + +, zahlenVon + +)
{
[i] number field = zahlenVon;
}
/ / values for all numbers to true
for (int i = 0; i \u0026lt;zahlenInfo.length; i + +) {
number info [i] = true;}
/ / prime loop
for ( int i = 0; i \u0026lt;zahlenFeld.length; i + +) {
/ / is Prime?
if (number info [i] == true) {
for (int j = i +1, j \u0026lt;zahlenFeld.length j + +) {
if (number info [j] == true & (number field [j] % number of field [i]) == 0) {
number info [j] = false;}
}}
} / / output the primes
for (int i = 0; i \u0026lt;zahlenFeld.length ; i + +) {
if (number info [i] == true) {
System.out.println (number field [i] + "");}
}
}}
Subscribe to:
Posts (Atom)