اسباب بازی سازی
پنجشنبه, ۱۵ آبان ۱۳۹۹، ۰۱:۱۱ ق.ظ
package ir.javacup.toyfactory; public class Car extends Toy { public Car(double basePrice,ToySize size) { super(basePrice,size); } public double getPrice() { ToySize hj=this.size; //System.out.println(hj); switch(hj) { case SMALL: return 2*this.getBasePrice(); case MEDIUM: return 2.5*this.getBasePrice(); case LARGE: return 3*this.getBasePrice(); default: return -1; } } }
package ir.javacup.toyfactory; public class Toy { private double basePrice; protected ToySize size; public Toy(double basePrice,ToySize size) { this.basePrice=basePrice; this.size=size; } public double getBasePrice() { return this.basePrice; } public double getPrice() { switch (size) { case SMALL: return basePrice; case MEDIUM: return basePrice*(1.5); case LARGE: return basePrice*2; default: return -1; } } public double getPrice(double discount) { return ((1.0)-discount/(100.0))*this.getPrice(); } } enum ToySize{ SMALL,LARGE,MEDIUM; }
۹۹/۰۸/۱۵