Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package temp;
- import java.util.*;
- public class RujulCAT {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- // 3 chefs and 3 waiter
- ArrayList<Chef> chefs = new ArrayList<Chef>();
- ArrayList<Waiter> waiters = new ArrayList<Waiter>();
- System.out.println("Creating chefs:");
- for(int i = 0; i < 3; i++) {
- chefs.add(new Chef());
- }
- System.out.println("Creating waiters:");
- for(int i = 0; i < 3; i++) {
- waiters.add(new Waiter());
- }
- // printing name and salary for chefs
- System.out.println("Chefs:");
- for(Chef c : chefs) {
- System.out.println("\nName: " + c.getName() + "\nSalary: " + c.getSalary());
- }
- // printing name and salary for waiters
- System.out.println("Waiters:");
- for(Waiter w : waiters) {
- System.out.println("\nName: " + w.getName() + "\nSalary: " + w.getSalary());
- }
- sc.close();
- }
- }
- abstract class Worker{
- private String name;
- private String number;
- protected double salary;
- abstract void computeSalary();
- public void setName(String name) {
- this.name = name;
- }
- public void setNumber(String number) {
- this.number = number;
- }
- public String getName() {
- return name;
- }
- public String getNumber() {
- return number;
- }
- public double getSalary() {
- return salary;
- }
- }
- class Chef extends Worker{
- private String certificate;
- private double basicPay;
- private double houseRent;
- private double dearness;
- @Override
- void computeSalary() {
- this.houseRent = this.basicPay*0.20;
- this.dearness = this.basicPay*0.28;
- this.salary = this.basicPay + this.houseRent + this.dearness;
- }
- public void setCertificate(String certificate) {
- this.certificate = certificate;
- }
- public void setBasicPay(double basicPay) {
- this.basicPay = basicPay;
- }
- public Chef() {
- Scanner chef_sc = new Scanner(System.in);
- System.out.println("Input Name:");
- setName(chef_sc.nextLine());
- System.out.println("Input mobile number:");
- setNumber(chef_sc.nextLine());
- System.out.println("Input Certificate number:");
- setCertificate(chef_sc.nextLine());
- System.out.println("Input base pay:");
- setBasicPay(chef_sc.nextDouble());
- chef_sc.nextLine();
- computeSalary();
- }
- }
- class Waiter extends Worker{
- private String id;
- private int numDaysWorked;
- @Override
- void computeSalary() {
- this.salary = 40000 + this.numDaysWorked*200;
- }
- public void setId(String id) {
- this.id = id;
- }
- public void setNumDaysWorked(int numDaysWorked) {
- this.numDaysWorked = numDaysWorked;
- }
- public Waiter() {
- Scanner waiter_sc = new Scanner(System.in);
- System.out.println("Input Name:");
- setName(waiter_sc.nextLine());
- System.out.println("Input mobile number:");
- setNumber(waiter_sc.nextLine());
- System.out.println("Input id:");
- setId(waiter_sc.nextLine());
- System.out.println("Input number of days worked:");
- setNumDaysWorked(waiter_sc.nextInt());
- waiter_sc.nextLine();
- computeSalary();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement