Question

in Java Create a custom class Employee with field like name , empNo and salary. a....

in Java Create a custom class Employee with field like name , empNo and salary. a. Create 5 objects b. Add all objects to ArrayList c. Print all employee details from ArrayList . d. Remove employee having salary less than 5000 $ [12] e. Insert a new employee object with more salary value at same index at which other object was removed. *

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#source code:

import java.util.*;
class Employee{
String name;
int empNo;
int Salary;
Employee(String name,int empNo,int Salary){
this.name=name;
this.empNo=empNo;
this.Salary=Salary;
}
public static void main(String args[]){
Employee emp1=new Employee("suresh",3,12000);
Employee emp2=new Employee("vishnu",5,8000);
Employee emp3=new Employee("prasad",4,9000);
Employee emp4=new Employee("gangarao",2,4000);
Employee emp5=new Employee("kumari",1,15000);
Employee emp6=new Employee("siva",7,11000);
ArrayList<Employee> emplist=new ArrayList<Employee>();
emplist.add(emp1);
emplist.add(emp2);
emplist.add(emp3);
emplist.add(emp4);
emplist.add(emp5);
Iterator iterStart=emplist.iterator();
System.out.println("Employee details:");
while(iterStart.hasNext()){
Employee eachEmp=(Employee)iterStart.next();
System.out.println(eachEmp.name+" "+eachEmp.empNo+" "+eachEmp.Salary);
}
System.out.println("Employee details remove whose salary less than 5000:");
Iterator iterStart2=emplist.iterator();
int store=0,valid=0;
while(iterStart2.hasNext()){
Employee eachEmp=(Employee)iterStart2.next();
if(eachEmp.Salary<5000){
valid=store;
iterStart2.remove();
}
store=store+1;
}

Iterator iterStart3=emplist.iterator();
while(iterStart3.hasNext()){
Employee eachEmp=(Employee)iterStart3.next();
System.out.println(eachEmp.name+" "+eachEmp.empNo+" "+eachEmp.Salary);
}
System.out.println("Adding Employee to ArrayList");
emplist.add(emp6);
Iterator iterStart5=emplist.iterator();
while(iterStart5.hasNext()){
Employee eachEmp=(Employee)iterStart5.next();
System.out.println(eachEmp.name+" "+eachEmp.empNo+" "+eachEmp.Salary);


}

}

}

#output:

#if you have any doubt comment below....

Add a comment
Know the answer?
Add Answer to:
in Java Create a custom class Employee with field like name , empNo and salary. a....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Task 2: Write a program where you create an ArrayList object that can store letters....

    Java Task 2: Write a program where you create an ArrayList object that can store letters. Show how can you add a letter to the ArrayList, remove a letter from theArrayList, replace a letter in the ArrayList, insert a letter in a specific location in the ArrayList, and display all the letters in the ArrayList. Task 3: Write a program where you create an ArrayList object that can store Circle object (you created circle class in your previous PAs). Create...

  • In Java: Executable Class create an array of Employee objects. You can copy the array you...

    In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...

  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

  • Create a java project and create Student class. This class should have the following attributes, name...

    Create a java project and create Student class. This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist. You should save at least 10 student objects in this arraylist using loop statement. Then iterate through...

  • JAVA PROGRAMMING Create an Employee class which implements Comparable<Employee> The constructor consists of an employee’s first...

    JAVA PROGRAMMING Create an Employee class which implements Comparable<Employee> The constructor consists of an employee’s first name and an employee’s salary, both of which are instance variables. Create accessor and mutator methods for both of these variables Write an equals method that returns true if the salaries are equal with one cent and the names are exactly equal Write a compareTo method that returns 1 if the salary of this employee is greater than the salary of the comparable, -1...

  • Part 1 Start by designing the Employee class Employee holds the following private attributes: a count...

    Part 1 Start by designing the Employee class Employee holds the following private attributes: a count of employees (a static variable called NUM_EMP)* an employee’s last name an employee’s first name an employeeNumber (a String that is unique – that will use the NUM_EMP)* a department a jobTitle an annual salary (e.g., 45000). NOTE: *NUM_EMP should start off as zero and get updated every time a new Employee is created. The employeeNumber always starts with empl_ followed by the current...

  • project-8c Write a class named Employee that has data members for an employee's name, ID_number, salary,...

    project-8c Write a class named Employee that has data members for an employee's name, ID_number, salary, and email_address (you must use those names - don't make them private). Write a function named make_employee_dict that takes as parameters a list of names, a list of ID numbers, a list of salaries and a list of email addresses (which are all the same length). The function should take the first value of each list and use them to create an Employee object....

  • Create a Java application, that support the following: Create an Employee class, which holds following information:...

    Create a Java application, that support the following: Create an Employee class, which holds following information: Employee First Name Employee Last Name Employee Phone Number Employee Address Employee id Employee Title Employee salary Create an application that uses the Employee class Constructors –Getters and setters A minimum of 3 constructors including default constructor equals() method Helper methods toString() method Create an array of 5 Employee objects Use a Scanner to read in 5 employee information Change 2 employees information (3-items...

  • Java Framework Collection Assign. Create a class called ArrayListExample Create a ArrayList object called languageList which...

    Java Framework Collection Assign. Create a class called ArrayListExample Create a ArrayList object called languageList which accept type of String Add English, French, Italian and Arabic strings into languageList array object Print languageList using Iterator object Sort ArrayList object alphabetically Print languageList using Iterator object Solution will produce following: ArrayListExample class ArrayList object called languageList ArrayListExampleTest class with main method

  • Create a class Employee. Your Employee class should include the following attributes: First name (string) Last...

    Create a class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyEmployee that inherits from the Employee class. HourEmployee must use the inherited parent class variables and add in HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT