/** * @author Ali Asadiyan */ public class tax { protected String taxName; protected int percent;
/** Creates a new instance of tax */ public tax() {//Empty Constructor taxName=" "; percent=0; }
public tax (String s, int p){//default cons... taxName=s; percent=p; }
public tax (tax tx){ //Copy Cons.... taxName=tx.taxName; percent=tx.percent; }
public void setTaxName (String s){ if (s != null) taxName=s; else taxName=" "; }
public void setPercent (int p){ if(1 < p && p < 99) percent = p; else System.out.println("This Input Number Is Wrong!");
}
public String getTaxName(){ return taxName; }
public int getPercent(){ return percent; }
public int calc(int n){ return (100-percent)*n/100; } }
package tax;
/** * @author Ali Asadiyan */ public class zone extends tax { private int zonePrice;
/** Creates a new instance of zone */ public zone() { super(); zonePrice=0; } public zone(String zoneName,int zonePercent,int zonePrice){ super(zoneName,20); zonePrice=10; }
public zone (zone zn){ super(zn); zonePrice=12; }
public void setZone(String z){ super.setTaxName(z); } public void getZone(){ super.getTaxName(); } public int calc(int n) { return super.calc(n-zonePrice); }
}
package tax;
/** * @author Ali Asadiyan */ public class Main { public static void main(String[] args) { tax MyTax = new tax("Ali",12); zone MyZone = new zone("AHMAD",12,5);
System.out.println("% Maliat " + MyTax.getTaxName()+" of(251) is: "+ MyTax.calc(251)); System.out.println("gomrok percent "+MyZone.getTaxName()+" of(251) is: "+MyZone.calc(251));