Vehicle program

Page 1

Java Lab (CS602-GS311) Ms Halima Atiya Lecture(4) public class Vehicles {

public static void main(String[] args) { // TODO code application logic here car rider1 = new car ("Robin","BMW",280,100,200); motorcycle rider2=new motorcycle("john","hiroshima",120,80,200); truck rider3 = new truck("James","Toyta",180,70,200); System.out.printf(" name of the rider:%s\n name of car:%s\n power:%f\n speed:%f\n distance:%f\n time spent driving:%.2f ", rider1.vname,rider1.vtype,rider1.power,rider1.speed,rider1.dis tance,rider1.arrivetime(100, 200)); System.out.printf(" \nname of the rider:%s\n name of car:%s\n power:%f\n speed:%f\n distance:%f\n time spent driving:%.2f ", rider2.vname,rider2.vtype,rider2.power,rider2.speed,rider2.dis tance,rider2.arrivetime(80, 200)); System.out.printf(" \nname of the rider:%s\n name of car:%s\n power:%f\n speed:%f\n distance:%f\n time spent driving:%.2f ", 1


rider3.vname,rider3.vtype,rider3.power,rider3.speed,rider3.dis tance,rider3.arrivetime(70, 200));

} } // Class: VehicleType public class VehicleType { String vname; String vtype; double power; public VehicleType(String vn,String vt, double p) { vname=vn; vtype=vt; power=p; } public double arrivetime(double s,double d) { return d/s; } }

2


// Class : Car public class car extends VehicleType { double speed; double distance;

public car(String vn,String vt, double p,double s,double d) { super (vn,vt,p); speed=s; distance=d;

}

public double arrivetime(double s,double d) { return super.arrivetime(s, d); } } // Class : Motor public class motorcycle extends VehicleType { double speed; double distance; 3


public motorcycle(String vn,String vt, double p,double s,double d) { super (vn,vt,p); speed=s; distance=d;

}

public double arrivetime(double s,double d) { return super.arrivetime(s, d); }

} //Class : Truck public class truck extends VehicleType { double speed; double distance;

public truck(String vn,String vt, double p,double s,double d) 4


{ super (vn,vt,p); speed=s; distance=d;

}

public double arrivetime(double s,double d) { return super.arrivetime(s, d); }

}

FB: Ms H Programmer Good luck 5


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.