Advertisement
bangnokia

java extends

May 11th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.56 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package distance;
  6.  
  7. /**
  8.  *
  9.  * @author t1406g_nvbang
  10.  */
  11. /*
  12.  * To change this template, choose Tools | Templates
  13.  * and open the template in the editor.
  14.  */
  15.  
  16.  
  17. public class showResult {
  18.     public static void main(String[] args) {
  19.         Manager quanLy = new Manager("Nguyen Viet Bang", 10, 100);
  20.         System.out.println(quanLy.calculatepay());
  21.        
  22.         Scientist nhaKhoaHoc = new Scientist("Nguyen Tan dung", 20000, 10);
  23.         System.out.println(nhaKhoaHoc.calculatepay());
  24.        
  25.         Laborer congNhan = new Laborer("Ho chi minh", 2000000, 40);
  26.         System.out.println(congNhan.calculatepay());
  27.                
  28.     }
  29. }
  30. class Employee {
  31.     protected String name;
  32.     protected double salary;
  33.     public Employee (String eName, double eSalary) {
  34.         name = eName;
  35.         salary = eSalary;
  36.     }
  37.     public double calculatepay() {
  38.         return 0;
  39.     }
  40. }
  41.  
  42. class Manager extends Employee {
  43.     private double business_amount;
  44.     public Manager(String mName, double mSalary, double mBusinessAmount) {
  45.         super(mName, mSalary);
  46.         business_amount = mBusinessAmount;
  47.     }
  48.     @Override
  49.     public double calculatepay() {
  50.         double total_pay;
  51.         double commission;
  52.         if (business_amount > 50000) {
  53.             commission = business_amount/10;
  54.         } else {
  55.             commission = business_amount/20;
  56.         }
  57.         total_pay = salary + commission;
  58.         return total_pay;
  59.     }
  60.          
  61. }
  62.  
  63. //class
  64. class Scientist extends Employee {
  65.     private int publication;
  66.     public Scientist(String sName, double sSalary, int sPublication) {
  67.         super(sName,sSalary);
  68.         publication = sPublication;
  69.     }
  70.     @Override
  71.     public double calculatepay() {
  72.         double total_pay;
  73.         total_pay = salary;
  74.         if (publication > 25) {
  75.             total_pay += salary/5;
  76.         }
  77.         else {
  78.             total_pay += salary/10;
  79.         }
  80.         return total_pay;
  81.     }
  82. }
  83.  
  84. //class
  85. class Laborer extends Employee {
  86.     private int hrsworked;
  87.     public Laborer (String lName, double lSalary, int lHrsWorked) {
  88.         super(lName, lSalary);
  89.         hrsworked = lHrsWorked;
  90.     }
  91.     @Override
  92.     public double calculatepay() {
  93.         double total_pay;
  94.         total_pay = salary;
  95.         if (hrsworked > 50) {
  96.             total_pay += salary/100*15;
  97.         } else {
  98.             total_pay += salary/100*8;
  99.         }
  100.         return total_pay;
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement