Last active
May 25, 2017 11:46
-
-
Save peter279k/824cd554cf9fb40ede900022a5d26c1d to your computer and use it in GitHub Desktop.
TQC+ JAVA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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