Assignment 1 Array List
Assignment 1 Array List
Assignment 1 Array List
Sid# : 2020844414
Course: CSC508
Group#: CS2304C
Assign#: #1
*/
EMPLOYEE CLASS
public Employee(){}
this.empName= name;
this.id = id;
this.salary = salary;
//accessor
return empName;
}
public String getID()
return id;
return salary;
//mutator
this.empName = name;
this.id = id;
this.salary = salary;
return "Name: "+ empName + " ID: "+id + " Salary(RM): " +salary;
}
ARRAYLIST CLASS
//Default constructor
public MyArrayList()
capacity = INITIAL_CAPACITY;
return size == 0;
//exercise 3
//method isFull()
return true;
//insert front
else
} //end add
//insert at back
else
}
//GET OBJECT DATA
else
return theData[index];
} //end get
System.out.println(theData[i]);
System.out.println();
}
MAIN CLASS
import java.util.Scanner;
double avg=0,total=0;
//input data
String id =sc.nextLine();
empList.insertAtBack(emp[i]);
//Employee that has salary more than 5000 will store in empHigh list
if(emp[j].getSalary()>5000)
empHigh.insertAtBack(empList.get(j));
}
for(int t =0; t<empList.size();t++)
//total salary
total += emp[t].getSalary();
double max=emp[0].getSalary(),min=emp[0].getSalary();
for(int m=1;m<empList.size();m++)
if(emp[m].getSalary()>max)
max = emp[m].getSalary();
if(emp[m].getSalary()<min)
min = emp[m].getSalary();
avg = total/empList.size();
System.out.println("Detail in empList:");
empList.display();
System.out.println("Detail in empHigh:");
empHigh.display();
System.out.println("Total salary(RM):"+total);
}
OUTPUT