Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


asmit
arraylist
2 Answer(s)      a year and 11 months ago
Posted in : Java Beginners


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


Advertisement
View Answers

August 24, 2012 at 6:10 PM


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;
}
}


August 24, 2012 at 6:10 PM


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);
    }
}


Related Tutorials/Questions & Answers:
arraylist
arraylist   Using arraylist class , what type of exception are throws, how can write a java programe   An ArrayList can throw... ArraylistException { void buildAlphabet() { ArrayList list = new ArrayList
arraylist
arraylist  Hi how can we eliminet duplicate element from arraylist in java? how can we achieve data abstrcation and encapulation in java? how many type of modifier are there in java? Thanks kalins anik   Remove
Advertisements
arraylist
arraylist  Hi How can we eliminet duplicate element from arraylist? How can we find highest salary from arraylist ? How can we highest key value pair from map? Thanks Kalins Naik   Remove duplicates from Arraylist
arraylist
arraylist  Hi i have class A , i have added employee name and id in arraylist, then how can i find out all infomation of class A using emplyee... data into an arraylist and display the data of the particular employee according
arraylist
% *(noOfYearService/2). Store each employee information in different arrayList depending on his
arraylist of an arraylist
arraylist of an arraylist  Can anyone suggest me how to use arraylist of an arraylist?? how to put data into it and get data from it???? becoz i want to make rows and column dynamic which can grow as per requirement?????/ plz
ArrayList
Java Notes: ArrayList java.util.ArrayList allows for expandable arrays, and is the Collections replacement for the older Vector class. An ArrayList has the following advantages over an array: An ArrayList automatically expands
Java ArrayList
Java ArrayList   How to declare unique ArrayList
arraylist and vector
arraylist and vector  what is the diff b/w arraylist and vector
ArrayList
Java Notes: ArrayList java.util.ArrayList allows for expandable arrays, and is the Collections replacement for the older Vector class. An ArrayList has the following advantages over an array: An ArrayList automatically expands
ArrayList and Vector
ArrayList and Vector  hello, Why ArrayList is faster than Vector?   hii, ArrayList is faster than Vector, because ArrayList is not synchronized. Synchronization will reduce the performance of Vector
arraylist in java
arraylist in java  arraylist in java   Array List Example in java
ArrayList object
ArrayList object  i have am ArrayList object it containg data base records in it, now i want to display this ArrayList object data in my jsp programe, plz help me
ArrayList elements
ArrayList elements  how to print ArrayList elements in reverse order... ArrayListReverse { public static void main(String[] args) { ArrayList list=new ArrayList(); list.add("Innova"); list.add("Alto
Java arraylist of arraylist
Java arrayList can make the use of other arrayList.  In one arrayList other arrayList can be added as the object  It works as two dimension array. Example of Java Arraylist of Arraylist import
comparing arraylist of an multi dimensional arraylist
comparing arraylist of an multi dimensional arraylist  can anyone help me in solving the following issue: actually i have an arraylist called dany... have to compare each arraylist with each other. like i have to take 1st arraylist
accessor arrayList
accessor arrayList  how to use an acccessor to return an arraylist?   public List getProductList(String itemName) { List list=new ArrayList(); //Add your item in the list return list; } You may wish to browse
ArrayList in java
ArrayList in java  sir i have a class Student.it contains id,name,marks of students and a parameteraised constructor.now i created an arraylist... to access marks from arraylist
ArrayList programe
ArrayList programe  How to write a java program to accept an array list of Employee objects. search,delete and modify a particular Employee based on Id Number (like ID,Name&Address
Cannot assign an ArrayList to an empty ArrayList
Cannot assign an ArrayList to an empty ArrayList  I have a java file, in which a method returns an ArrayList. This ArrayList is supposed to contain... StudentsManager's methods statically. studByYear(year); returns an ArrayList of all
vector and arraylist
vector and arraylist    suppose i have class A { public static arrylist a1(){} class B{ public static vector b1() {} } my question is how to class B method in Class A and how to get vector object values in class A without
java arraylist
need to create arraylist whose name is same as type value(e.g : list1,list2... which is having type list1 in the arraylist named list1. the problem here... help how to handle this through java arraylist. xml : <?xml version='1.0
arraylist problems?
arraylist problems?   myprogram needs to ask the user for a file name. The file will contain a name on each line. Put each of the names into an ArrayList. After you have put all of the names into the ArrayList search through
Java arraylist, linkedlist
Java arraylist, linkedlist  What is the major difference between LinkedList and ArrayList
Remove multiple elements in arraylist
Remove multiple elements in arraylist   how can we remove multiple values in arrayList? only remove method we used for single remove.but i want to delete multiple value in arrayList
ArrayList as an argument to another class
ArrayList as an argument to another class  how do you pass arraylists as arguments to another class, and how does the method/class accept this arraylist for use
Java ArrayList Example
Java ArrayList Example  How can we use array list in java program..."); array.add("Arun"); System.out.println("ArrayList Size...++){ System.out.println("ArrayList Element"+i+" :"+array.get(i
ArrayList<E>
class. An ArrayList has these characteristics: An ArrayList automatically expands as data is added. Access to any element of an ArrayList is O(1). Insertions and deletions are O(N). An ArrayList has methods for inserting, deleting
Printing ArrayList - JSP-Servlet
Printing ArrayList   I have a code in servlet like this ArrayList total = new ArrayList (); session.setAttribute("efg",total...(request,response); to print the values in ArrayList total, I did this in my JSP
Can ArrayList accept an ImageIcon >>????
Can ArrayList accept an ImageIcon >>????  haw can create ArrayList witch can accept Image ..mean when i use add() method, instead item let me add image to the ArrayList in run time .{should be the program using GUI
Diff between ArrayList and Vector?
Diff between ArrayList and Vector?  What's The Difference between ArrayList and Vector Classes and Can you give me a simple Program for set and List Interface
arraylist with session - JSP-Servlet
arraylist with session  hi how can an arraylist stored in session.. and also how will it access?? pls give me the details with sample code..   Hi friend, Code to solve the problem : Thanks
assigning arraylist to combo box
assigning arraylist to combo box  Hi I am busy coding the Airline Reservation program, i have an arraylist of locations which i want to assing to the combo box. please help
Core Java-ArrayList
Core Java-ArrayList  How do i find duplicates in ArrayList. First i add some elements to ArrayList, then how do i find the duplicates and show the duplicate elements. Give an example
to use ArrayList in the place of Vector
to use ArrayList in the place of Vector  public Enumeration getInterfaces() { ISCMetaType currentType = this; ArrayList allInterfaces = new ArrayList(); while( currentType != null
to use ArrayList in the place of Vector
to use ArrayList in the place of Vector  public Enumeration getInterfaces() { ISCMetaType currentType = this; ArrayList allInterfaces = new ArrayList(); while( currentType != null
Two - dimension arraylist
Two - dimension arraylist  how to create two - dimension arraylist in jsp-servlet
ArrayList - JSP-Interview Questions
ArrayList  i used arraylist in servlet as shown ArrayList total = new ArrayList (); ... total.add(k[i]); session.setAttribute("efg",total... ArrayList(); %> Its not printing the values. do i need to do any
ARRAYLIST CODE - Java Beginners
ARRAYLIST CODE  HELLO SIR,I AM VERY NEW TO JAVA FIELD,HOW TO READ ELEMENTS FROM TWO ARRAYLIST AND PRINT THE ELEMENTS WHICH ARE COMMON TO TWO ARRAYLIST IN ONE LINE AND OTHER IN NEXT LINE,PLZ HELP ME.IN ADVANCE THANK U VERY
set the arraylist values - Struts
set the arraylist values   ResourceIdleReport.jsp <
ArrayList problem - JSP-Servlet
ArrayList problem  Hi, How can I add elements of an ArrayList to HTML combobox or list in java? Hi, You can use the following code: Array List..." name="MYLIST"> <% ArrayList a_list = new ArrayList
arraylist - Java Beginners
arraylist  Hi.. I've an arraylist where i need to add a string array along with other string values. My string array is array[] and arraylist is al i added other string values name,time,date as al.add(name); al.add(time
Convert ArrayList to Array
In this section, you will learn about converting ArrayList to Array
Convert Array to ArrayList
In this section, you will learn about converting Array into ArrayList
Collection : ArrayList Example
This tutorial contains description of Collection ArrayList with example
arraylist problem - Java Beginners
arraylist problem  Hello.... I wrote the following code for adding a string array into an array list along with other strings... and to display...{ ArrayList al = new ArrayList(); for(int i=0;i<10;i++){ String event
arrayList - Java Beginners
must check through the desktop arraylist and notebook arraylist. How can I combine this two arraylist checking for throw out the msg of "Computer list is empty!" Currently I only can check for desktop arraylist empty if no desktop is added
Advertisements
 

 

 

DMCA.com