1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Paraphin [41]
3 years ago
14

Create an ArrayList of Employees (contain id and name) and add 3 Employees to the ArrayList to start. Next, you want to sort the

se Employees by their name using Collections.sort. Refer back to ch 4 and lab 2 part 2 to use comparator and Collections.sort. In order to avoid affecting the original list and employees, clone the ArrayList before using the sort method. To make a deep copy of the ArrayList, implement the clone method of Employee and use it to create a new ArrayList of employees.

Computers and Technology
1 answer:
Anna [14]3 years ago
3 0

Answer:

Kindly note that, you're to replace "at" with shift 2 as the brainly text editor can't accept the symbol

Explanation:

Java code:

import java.util.*; public class Employees { // variables private int id; private String name; // getters public String getName() { return name; } public int getId() { return id; } // constructor public Employees(int id, String name) { this.id = id; this.name = name; } // comparator function based on the name static class compareByName implements Comparator<Employees> { "at"Override public int compare(Employees emp1, Employees emp2) { return emp1.getName().compareTo(emp2.getName()); } } // clone method for arraylist public static ArrayList<Employees> clone(ArrayList<Employees> arr) { ArrayList<Employees> temp = new ArrayList<Employees>(); for(int i=0;i<arr.size();i++) temp.add(arr.get(i)); return temp; } // main method public static void main(String[] args) { Scanner scan = new Scanner(System. in); // reading 3 employees details ArrayList<Employees> arr = new ArrayList<Employees>(); for(int i=0;i<3;i++) { System.out.print("Enter id: "); int id = scan. nextInt(); System.out.print("Enter name: "); scan. nextLine(); String name = scan. nextLine(); arr.add(new Employees(id,name)); } // cloning and sorting ArrayList<Employees> cloneArray = clone(arr); Collections. sort(arr, new compareByName()); // printing System. out. println("Array after cloning: "); for(int i=0;i<cloneArray. size();i++) { System.out.println(cloneArray. get(i). getId() + " " + cloneArray. get(i).getName()); } System. out. println("Array after sorting: "); for(int i=0;i<arr.size();i++) { System. out. println(arr.get(i). getId() + " " + arr.get(i). getName()); } } }  

Kindly check the attached images below for the code screenshot and code output.

You might be interested in
What is a many-to many types of correspondence?
Ann [662]

Answer:

We have many types of correspondences. There are internal correspondences, external correspondences, sales correspondences, and personalized correspondences. By many to many correspondences we mean, a lot of people correspond with a lot many people from another department, company or market, or any set of people in fact. An internal correspondences, sales correspondences, personalized correspondences or external correspondences can be of many to many types, and as well as of others like one to one, many to one and so on.

Explanation:

Please check the answer.

5 0
3 years ago
How do i fix my profile picture it is stretched out
sveta [45]

Answer:

try resetting your account or change the picture and see if the other one is stretched out to

8 0
3 years ago
Print person1's kids, call the incNumKids() method, and print again, outputting text as below. End each line with a newline.
Brilliant_brown [7]

Answer:

Explanation:

The following code was written in Java and modifies the code so that for the given input such as 3 it outputs the exact information shown in the sample output.

import java.util.Scanner;

class CallPersonInfo {

   public static void main(String [] args) {

       Scanner scnr = new Scanner(System.in);

       PersonInfo person1 = new PersonInfo();

       int personsKid;

       System.out.println("How many kids do you have:");

       personsKid = scnr.nextInt();

       person1.setNumKids(personsKid);

       /* Your solution goes here */

       System.out.println("Kids: " + person1.getNumKids());

       person1.incNumKids();

       System.out.println("New Baby, kids now: " + person1.getNumKids());

   }

}

class PersonInfo {

   private int numKids;

   public void setNumKids(int setPersonsKids) {

       numKids = setPersonsKids;

   }

   public void incNumKids() {

       numKids = numKids + 1;

   }

   public int getNumKids() {

       return numKids;

   }

}

4 0
3 years ago
The virus scanning technique that uses rules to determine if a program behaves like a virus is _________ scanning.
andrew-mc [135]

Answer:

Option c: Heuristic

Explanation:

Heuristic scanning is a form of computer virus detection analysis that screen for the suspicious characteristic of the program which maybe a virus. Heuristic scanning is designed to detect those new computer virus, unknown virus or the modified version of the known virus.

To perform heuristic scanning, a weigh-based evaluation algorithm will be adopted to estimate the likelihood of the current scanned program behaves like a virus which can pose a computer threat. If it exceeds a threshold level, an alarm will be triggered.

3 0
3 years ago
These are questions from my Computer/Customer Support Class
vladimir2022 [97]
Hey

1. Workers 

2. im not sure about this on

3. The

Hoped I Helped
5 0
3 years ago
Other questions:
  • I need help someone please help
    6·1 answer
  • The network of satellites monitoring continental movement is referred to as
    7·1 answer
  • All of the following are examples of roadblocks to achieving a goal except
    12·2 answers
  • Differentiate between the broadcasting and telecommunication
    5·1 answer
  • Complete the PizzaCaloriesPerSlice() function to compute the calories for a single slice of pizza. A PizzaCalories() function re
    6·1 answer
  • If your hood suddenly flies up you should turn on your hazard lights and continue driving. True or false?
    10·2 answers
  • True or false Encryption prevents hackers from hacking data?
    8·1 answer
  • Kristi, an event planner, wants to store caterers’ names and contact information in an organized manner. Kristi will MOST LIKELY
    13·1 answer
  • What other jobs would require employees to follow directions very carefully? (Give 4 examples)​
    9·1 answer
  • 9.3 Code Practice
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!