Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.ArrayList;
- import static java.lang.System.out;
- class Test
- {
- static Scanner sc=new Scanner(System.in);
- public static void main(String[]dog)
- {
- ArrayList<salary> a = new ArrayList<salary>();
- a.add(new salary(111,"Smith",10000));
- a.add(new salary(222,"Anna",20000));
- ArrayList<Hourly> b= new ArrayList<Hourly>();
- b.add(new Hourly(333,"Paul",200));
- b.add(new Hourly(444,"Pete",300));
- //formation1
- for(int i=0;i<2;i++)
- {
- Polymorpysim(a.get(i));
- System.out.println();
- }
- //formation 2
- b.get(0).peymant();
- out.println();
- b.get(1).peymant();
- out.println();
- //----------------------------------------------
- out.print("MENU\n"+
- "1.Salary\n"+
- "2.Hourly\n");
- out.print("\nYou can pick menu :");
- int menu=sc.nextInt();
- if(menu==1){
- int i;
- Scanner sc=new Scanner(System.in);
- out.print("MENU\n"+
- "0.Insert data\n"+
- "1.Search data\n"+
- "2.Edit data\n");
- out.print("\nYou can pick menu :");
- i=sc.nextInt();
- int ID;
- String Name;
- double money;
- if(i==0)
- {
- out.println("=========Insert data=========");
- out.print("pls enter ID: ");
- ID=sc.nextInt();
- out.print("pls enter Name:");
- Name=sc.next();
- out.print("pls enter money :");
- money=sc.nextDouble();
- a.add(new salary(ID,Name,money));
- }
- else if(i==1)
- {
- int k;
- out.println("=========Search data=========");
- out.print("Menu\n"+
- "1.ID\n"+
- "2.Name\n"+
- "pls enter number pick number:");
- k=sc.nextInt();
- if(k==1)
- {
- out.print("enter ID:");
- ID=sc.nextInt();
- for(int j=0;j<a.size();j++)
- {
- if(a.get(j).id==ID)
- {
- out.println("TRUE");
- break;
- }
- else
- {
- out.println("falase");
- break;
- }
- }
- }
- else if(k==2)
- {
- out.print("enter Name:");
- Name=sc.next();
- for(int j=0;j<a.size();j++)
- {
- if(a.get(j).name.equals(Name))
- {
- out.println("TRUE");
- break;
- }
- else
- {
- out.println("falase");
- break;
- }
- }
- }
- }
- else if(i==2)
- {
- int position;
- out.println("=========Edit data=========");
- out.print("pls enter Position: ");
- position=sc.nextInt();
- out.print("pls enter ID: ");
- ID=sc.nextInt();
- out.print("pls enter Name:");
- Name=sc.next();
- out.print("pls enter money :");
- money=sc.nextDouble();
- a.add(position,new salary(ID,Name,money));
- }
- }
- else if (menu==2)
- {
- int i;
- Scanner sc=new Scanner(System.in);
- out.print("MENU\n"+
- "0.Insert data\n"+
- "1.Search data\n"+
- "2.Edit data\n");
- out.print("\nYou can pick menu :");
- i=sc.nextInt();
- int ID;
- String Name;
- double Hours;
- if(i==0)
- {
- out.println("=========Insert data=========");
- out.print("pls enter ID: ");
- ID=sc.nextInt();
- out.print("pls enter Name:");
- Name=sc.next();
- out.print("pls enter hour:");
- Hours=sc.nextDouble();
- a.add(new salary(ID,Name,Hours));
- }
- else if(i==1)
- {
- int k;
- out.println("=========Search data=========");
- out.print("Menu\n"+
- "1.ID\n"+
- "2.Name\n"+
- "pls enter number pick number:");
- k=sc.nextInt();
- if(k==1)
- {
- out.print("enter ID:");
- ID=sc.nextInt();
- for(int j=0;j<a.size();j++)
- {
- if(a.get(j).id==ID)
- {
- out.println("TRUE");
- break;
- }
- else
- {
- out.println("falase");
- break;
- }
- }
- }
- else if(k==2)
- {
- out.print("enter Name:");
- Name=sc.next();
- for(int j=0;j<a.size();j++)
- {
- if(a.get(j).name.equals(Name))
- {
- out.println("TRUE");
- break;
- }
- else
- {
- out.println("falase");
- break;
- }
- }
- }
- }
- else if(i==2)
- {
- int position;
- out.println("=========Edit data=========");
- out.print("pls enter Position: ");
- position=sc.nextInt();
- out.print("pls enter ID: ");
- ID=sc.nextInt();
- out.print("pls enter Name:");
- Name=sc.next();
- out.print("pls enter money hour:");
- Hours=sc.nextDouble();
- a.add(position,new salary(ID,Name,Hours));
- }
- }
- }
- static void Polymorpysim(salary m)
- {
- m.calculateExpense();
- m.peymant();
- }
- }
- abstract class Employee
- {
- int id;
- String name;
- void printDetail()
- {
- out.println("ID : " + id);
- out.println("Name : " + name);
- }
- abstract void peymant();
- }
- interface Expense
- {
- public final double tax =0.05;
- public abstract double calculateExpense();
- }
- class salary extends Employee implements Expense
- {
- double salarY;
- salary(int id,String name,double salarY)
- {
- this.id=id;
- this.name=name;
- this.salarY=salarY;
- }
- public double calculateExpense()
- {
- if(salarY>15000)
- {
- return salarY*tax;
- }
- else
- {
- return 0;
- }
- }
- public void peymant()
- {
- double Netsalary=salarY-calculateExpense();
- printDetail();
- out.println("Salary : " + salarY);
- out.println("Expense : " + calculateExpense());
- out.println("Net Salary : " + Netsalary);
- }
- }
- class Hourly extends Employee
- {
- Scanner shit=new Scanner(System.in);
- int hourRate;
- Hourly(int id,String name,int hourRate)
- {
- this.id=id;
- this.name=name;
- this.hourRate=hourRate;
- }
- void peymant()
- {
- printDetail();
- out.print("Enter Work Hour : ");
- int hour=shit.nextInt();
- /*for(int i=0;i<99;i++)
- {
- System.out.println("\n");
- }*/
- out.println("Hour Rate : " + hourRate);
- out.println("Work Hours : " + hour);
- out.println("NetPayment: "+(hour*hourRate));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment