
Write a program to calculate a bonus for 10 employees of WAFA Supermarket. The program consists of an abstract class Employee. Each employee contains IC number, name, basicSalary, noOfYearService, set methods for each attributes and an abstract method calculateBonus(). Cashier and Supervisor are the subclasses of Employee class. Both subclasses contain bonus attribute and method calculateBonus(). Bonus for a supervisor is calculated by basicSalary * 25% *noOfYearService while bonus for a cashier is basic salary * 15% *(noOfYearService/2).
Store each employee information in different arrayList depending on his/her position (cashier or supervisor).
The program displays a menu with choices ( 1. to add employee information, 2. to delete employee, 3. to display report). Below is a sample format of a report when a user chooses to display a report..
can help me to identify what set methods that should have in this program..and can help me..give some clue in coding..how to start this program..
View Answers
Post Answer

Here is an application that stores employee object into arraylist.
import java.util.*;
abstract class Employee
{
int icNumber;
String name;
double basicSalary;
int noOfYear;
void setIcNumber(int icNumber){
this.icNumber=icNumber;
}
void setName(String name){
this.name=name;
}
void setBasicSalary(double basicSalary){
this.basicSalary=basicSalary;
}
void setNoOfYear(int noOfYear){
this.noOfYear=noOfYear;
}
abstract double calculateBonus(double sal,int year);
}
class Cashier extends Employee{
int icNumber;
String name;
double basicSalary;
int noOfYear;
double bonus;
Cashier(int icNumber,String name,double basicSalary, int noOfYear,double bonus){
this.icNumber=icNumber;
this.name=name;
this.basicSalary=basicSalary;
this.noOfYear=noOfYear;
this.bonus=bonus;
}
Cashier(){}
public int getIcNumber(){
return icNumber;
}
public String getName(){
return name;
}
public double getBasicSalary(){
return basicSalary;
}
public int getNoOfYear(){
return noOfYear;
}
public double getBonus(){
return bonus;
}
double calculateBonus(double sal,int no){
int y=no/2;
double b=sal*0.15*y;
return b;
}
}
class Supervisor extends Employee{
int icNumber;
String name;
double basicSalary;
int noOfYear;
double bonus;
Supervisor(int icNumber,String name,double basicSalary, int noOfYear,double bonus){
this.icNumber=icNumber;
this.name=name;
this.basicSalary=basicSalary;
this.noOfYear=noOfYear;
this.bonus=bonus;
}
Supervisor(){}
public int getIcNumber(){
return icNumber;
}
public String getName(){
return name;
}
public double getBasicSalary(){
return basicSalary;
}
public int getNoOfYear(){
return noOfYear;
}
public double getBonus(){
return bonus;
}
double calculateBonus(double sal,int no){
double b=sal*0.25*no;
return b;
}
}

continue..
class Supermarket{
public static void main(String[]args){
ArrayList<Cashier> list1=new ArrayList<Cashier>();
ArrayList<Supervisor> list2=new ArrayList<Supervisor>();
Cashier ch=new Cashier();
Supervisor sv=new Supervisor();
list1.add(new Cashier(11,"A",20000,4,ch.calculateBonus(20000,4)));
list1.add(new Cashier(12,"B",25000,2,ch.calculateBonus(25000,2)));
list2.add(new Supervisor(13,"C",5000,2,sv.calculateBonus(5000,2)));
list2.add(new Supervisor(14,"D",15000,6,sv.calculateBonus(15000,6)));
boolean exit=false;
Scanner input=new Scanner(System.in);
do{
System.out.println("1 Add Employee");
System.out.println("2 Delete Employee");
System.out.println("3 Display Report");
System.out.println("4 Exit");
System.out.print("Enter your choice: ");
int choice=input.nextInt();
switch(choice){
case 1:
System.out.println("Enter IC Number: ");
int no=input.nextInt();
System.out.println("Enter Name: ");
String name=input.next();
System.out.println("Enter Basic Salary: ");
double basic=input.nextDouble();
System.out.println("Enter No of Year: ");
int y=input.nextInt();
System.out.println("Enter Employee type(Cashier/Supervisor): ");
String type=input.next();
if(type.equals("Cashier")){
list1.add(new Cashier(no,name,basic,y,ch.calculateBonus(basic,y)));
}
else if(type.equals("Supervisor")){
list2.add(new Supervisor(no,name,basic,y,sv.calculateBonus(basic,y)));
}
break;
case 2:
System.out.println("Enter IC Number to delete: ");
int n=input.nextInt();
System.out.println("Enter Employee type(Cashier/Supervisor): ");
String t=input.nextLine();
if(t.equals("Cashier")){
for(Cashier c: list1){
if(c.getIcNumber()==n){
list1.remove(new Cashier(c.getIcNumber(),c.getName(),c.getBasicSalary(),c.getNoOfYear(),c.getBonus()));
}
}
}
else if(t.equals("Supervisor")){
for(Supervisor s: list2){
if(s.getIcNumber()==n){
list2.remove(new Supervisor(s.getIcNumber(),s.getName(),s.getBasicSalary(),s.getNoOfYear(),s.getBonus()));
}
}
}
break;
case 3:
for(Cashier c: list1){
System.out.println(c.getIcNumber()+"\t"+c.getName()+"\t"+c.getBasicSalary()+"\t"+c.getNoOfYear()+"\t"+c.getBonus());
}
for(Supervisor s: list2){
System.out.println(s.getIcNumber()+"\t"+s.getName()+"\t"+s.getBasicSalary()+"\t"+s.getNoOfYear()+"\t"+s.getBonus());
}
break;
case 4:
exit=true;
System.exit(0);
break;
}
}
while(!exit);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.