Skip to content

Instantly share code, notes, and snippets.

@peter279k
Last active May 25, 2017
Embed
What would you like to do?
TQC+ JAVA
class Car {
public int engine = 0;
public int airCond = 0;
public String carMode = "";
public double cost() {
if(this.carMode.equals("basic")) {
return (double)this.engine + (double)this.airCond + 5000;
} else if(this.carMode.equals("SLuxCar")) {
return (double)this.engine + (double)this.airCond + 10000 + (double)new Sound().getCost();
} else {
return (double)this.engine + (double)this.airCond + 10000;
}
}
public double price() {
return (double)this.cost() * 1.2;
}
}
class BasicCar extends Car {
public BasicCar(int cc, String airMode) {
this.engine = new Engine(cc).getCost();
this.airCond = new Aircond(airMode).getCost();
this.carMode = "basic";
}
}
class LuxCar extends Car {
public LuxCar(int cc, String airMode) {
this.engine = new Engine(cc).getCost();
this.airCond = new Aircond(airMode).getCost();
this.carMode = "lux";
}
}
public class JPA06_2 {
public static void main(String args[]){
BasicCar bc = new BasicCar(1600,"Manual");
System.out.println("Basic cost: " + bc.cost());
System.out.println("Basic price: " + bc.price());
LuxCar lc = new LuxCar(2000,"Auto");
System.out.println("Lux cost: " + lc.cost());
System.out.println("Lux price: " + lc.price());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment