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...

  • 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

  • ONLY NEED THE DRIVER CLASS PLEASE!!! Domain & Comparator Classes: 0.) Design a hierarchy of classes,...

    ONLY NEED THE DRIVER CLASS PLEASE!!! Domain & Comparator Classes: 0.) Design a hierarchy of classes, where the Media superclass has the artistName and the mediaName as the common attributes. Create a subclass called CDMedia that has the additional arrayList of String objects containing the songs per album. Create another subclass called DVDMedia that has the additional year the movie came out, and an arrayList of co-stars for the movie. 1.) The superclass Media will implement Comparable, and will define...

  • 3. Create a program named TestArrayList, and declare an ArrayList with an initial capacity of 10....

    3. Create a program named TestArrayList, and declare an ArrayList with an initial capacity of 10. Insert one copy of the string "Python", five copies of the string "Java" followed by four copies of the string "C++" so that your vector is now filled to сараcity. Add a class method named printArrayList to print out all the elements stored within an ArrayList on separate lines. Test your method to be sure it works a) Add a class method named delete...

  • JAVA Assume that you are developing an Employee class with idNum, firstName, and lastName. – Now,...

    JAVA Assume that you are developing an Employee class with idNum, firstName, and lastName. – Now, you want to keep the Employee objects in an ArrayList. – Develop the correct equals() method of the Employee class. Sample Run 1. Input a number: 100 2. Input a name: Tom 3. More items?(Y/N) y 4. Input a number: 200 5. Input a name: John 6. More items?(Y/N) n 7. The list contains: 8. 100 Tom 9. 200 John 10. Type the number...

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
ADVERTISEMENT