Problem: Design an employee class that stores the following members: Idnum: empl
ID: 3838124 • Letter: P
Question
Problem: Design an employee class that stores the following members:
Idnum: employee id number
Name: employee name
Salary: employee salary
Get_employee gets info of the employee
Use constructor and destructor, overloading operator <<, and any other methods that you need.
Create templates for a dynamic stack that can hold objects of the class described above along with any other data types.
The program should have a loop that asks the user if he or she wishes to add or drop an employee.
At any stage, user should able to display the stack contents.
When the user finishes the program, it should display the final contents of the stack.
Test your program for set of 5 names.
Explanation / Answer
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class Employee {
public int empid;
public string name;
public float Salary;
public Employee(int id, string nm,double sal){
id = empid;
nm=name;
Sal = salary;
}
public Employee(string nm,double sal){
id = GUID();
nm=name;
Sal = salary;
}
public int getEmpid(){
return empid;
}
public int getName(){
return nm;
}
public double getSalary(){
return sal;
}
public void getempdata()
{
for (Employee item : emplist) {
System.out.println(item.getEmpid() + " " + item.getName()+" "+item.getSalary());
}
}
finally
{
System.gc();
}
public static void main(String[]args){
List<Employee> emplist= new ArrayList<Employee>();
do
{
Scanner sc = new Scanner(System.in);
System.out.printf("employee id:")
int id = sc.nextInt();
System.out.printf("employee name:")
string nm = sc.nextstring();
System.out.printf("salary:");
float sal= sc.nextDouble();
emplist.add(new Employee(e, s));
System.out.printf("press Yes to see data")
string disp = sc.nextString();
if(disp=="y") getempdata();
System.out.printf("press 1 want to continue 0 to stop")
int val = sc.nextInt();
}
while (val)
//---------------------------------------------for polymorphism
List<Employee> emplistpol= new ArrayList<Employee>();
while (empList.size() < 7) {
Scanner sc = new Scanner(System.in);
System.out.printf("employee name:")
string nm = sc.nextstring();
System.out.printf("salary:");
float sal= sc.nextDouble();
emplistpol.add(new Employee(e, s));
}
for (Employee item : emplist) {
System.out.println(item.getEmpid() + " " + item.getName()+" "+item.getSalary());
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.