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 ();}
0 comments:
Post a Comment