mdzafir_alvi

Online-1

Aug 6th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.87 KB | None | 0 0
  1. package one;
  2.  
  3. public class One
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         Two tw = new Two();
  8.         Two tw1 = new Two("alvi","01761900889",20.00,5000.00,1.00);
  9.         Three th = new Three();
  10.         Three th1 = new Three("alvi","01761900889",20.00,5000.00,1.00);
  11.        
  12.         /* set using setter and getter method */
  13.         /*
  14.         tw.setname("alvi");
  15.         tw.setmobno("01761900889");
  16.         tw.setage(20.00);
  17.        
  18.         tw.setbasic(5000); // FOR TWO CLASS
  19.         th.setbasic(5000); // FOR THREE CLASS
  20.        
  21.         // IF WE DONT USE tw.setbasic(); and th.setbasic(); two times
  22.         // THE VALUE OF BASIC WONT BE CHANGD SECOND TIME . THAT IS IT WILL
  23.         // BE CHANGED TO 5000 FIRST TIME BUT IT WILL BE REMAIN IN INITIAL
  24.         // VALUE 100 SECOND TIME
  25.        
  26.         tw.setyear(1.00);
  27.         */
  28.        
  29.         /* we must use parameterized constructor , otherwise the basic wont
  30.         be changed
  31.         */
  32.         System.out.println(tw1.salary());
  33.         //System.out.println(th.salary());
  34.         System.out.println(th1.salary());
  35.         //System.out.println(tw.salary());
  36.     }
  37. }
  38.  
  39.  
  40.  
  41. public class Two
  42. {
  43.     public String name = "A";
  44.     public String mobno = "1761900889";
  45.     public double age = 30.00;
  46.     public double basic = 100.00 ;
  47.     public double year = 1.00;
  48.    
  49.     Two()
  50.     {
  51.        
  52.     }
  53.     Two(String name,String mobno,double age,double basic,double year)
  54.     {
  55.         this.name=name;
  56.         this.mobno=mobno;
  57.         this.age=age;
  58.         this.basic=basic;
  59.         this.year=year;
  60.     }
  61.     public void setname(String name)
  62.     {
  63.         this.name=name;
  64.     }
  65.     public void setmobno(String mobno)
  66.     {
  67.         this.mobno=mobno;
  68.     }
  69.     public void setage(double age)
  70.     {
  71.         this.age=age;
  72.     }
  73.     public void setbasic(double basic)
  74.     {
  75.         this.basic=basic;
  76.     }
  77.     public void setyear(double year)
  78.     {
  79.         this.year=year;
  80.     }
  81.     public String getname()
  82.     {
  83.         return name;
  84.     }
  85.     public String getmobno()
  86.     {
  87.         return mobno;
  88.     }
  89.     public double getage()
  90.     {
  91.         return age;
  92.     }
  93.     public double getbasic()
  94.     {
  95.         return basic;
  96.     }
  97.     public double getyear()
  98.     {
  99.         return year;
  100.     }
  101.    
  102.     public double salary()
  103.     {
  104.         double s = basic * 2 * year ;
  105.         return s;
  106.     }
  107. }
  108.  
  109.  
  110.  
  111.  
  112. public class Three extends Two
  113. {
  114.     public double increament = ((basic*75)/100);
  115.     Three()
  116.     {
  117.         super();
  118.     }
  119.     Three(String name,String mobno,double age,double basic,double year)
  120.     {
  121.         this.name=name;
  122.         this.mobno=mobno;
  123.         this.age=age;
  124.         this.basic=basic;
  125.         this.year=year;
  126.     }
  127.  
  128.     public double salary()
  129.     {
  130.         double sa = ( (basic + increament)* 2 * year ) ;
  131.         return sa;
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment