Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TQC+ JAVA
class PC extends Base {
public PC() {
this.cost = new CPU(2.4).getCost() + new HD("160G").getCost() + 500;
this.price = (new CPU(2.4).getCost() + new HD("160G").getCost()) * 1.8;
}
}
class MultiPC extends Base {
public MultiPC(int num, int num2) {
this.cost = (new CPU(2.4).getCost() * num + new HD("160G").getCost() * num2) * 1.2;
this.price = (new CPU(2.4).getCost() * num + new HD("160G").getCost() * num2) * 1.8;
}
}
class JPA06_2 {
public static void main(String args[]){
PC pc = new PC();
System.out.println("PC cost:"+pc.getCost()+", price:"+pc.getPrice());
MultiPC multipc1 = new MultiPC(2, 4);
System.out.println("MultiPC: 2CPU, 4HD, cost:"+multipc1.getCost()+", price:"+multipc1.getPrice());
MultiPC multipc2 = new MultiPC(4, 8);
System.out.println("MultiPC: 4CPU, 8HD, cost:"+multipc2.getCost()+", price:"+multipc2.getPrice());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.