Question

It is 2040, and you’ve just begun your new position as a Director of Engineering at...

It is 2040, and you’ve just begun your new position as a Director of Engineering at Facebook. You have interviewed n candidates to be your executive assistant, and assigned each one a score for organization and a score for punctuality. Using merge sort, you must sort your list of candidates in descending order by job suitability, which we here define to be 0.8*organization + 0.2*punctuality. If candidates A and B are tied for job suitability, and candidate A comes before candidate B in the original list, candidate A must come before candidate B in the sorted list as well. You may assume that all candidates have distinct job suitability scores, and that n > 0.

Any algorithms that do not explicitly implement merge sort will receive zero credit.

You will be given as input an integer n (where n is a non-negative integer) on its own line, followed by n lines, each containing a space-separated list of (candidate first name, candidate last name, organization score, punctuality score). You must output n lines, containing the candidate names in decreasing order of job suitability. For example, if you receive the following input:

4

Arya Stark 50 72

Tormund Giantsbane 10 2

Hot Pie 50 72

Podrick Payne 48 81

then you should print the following output:

Podrick Payne

Arya Stark

Hot Pie

Tormund Giantsbane

(Explanation:

Podrick Payne has a a job suitability rating of 0.8*48 + 0.2*81 = 54.6,

Arya Stark has a job suitability rating of 54.4, Hot Pie has a job suitability rating of 54.44,

and Tormund Giantsbane has a job suitability of 8.4.)

Since Arya Stark appears before Hot Pie in the original list, she also appears before Hot Pie in the sorted list.

Code for reading input and writing output has been provided in the Main class; your job is to complete the mergeSort()

function. Be sure to read the code for the ExecutiveAssistant class, which is in its own file. A well-designed solution (IMO) would involve adding a method to this class.

Hint: Keep in mind we already wrote MergeSort in class. Consider referencing that, or adjusting it, to complete this assignment.

PLEASE USE THIS CODE TO FINISH THE TASK

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
  
// get number of lines
int n = Integer.parseInt(sc.nextLine());
  
// for each line, create an ExecutiveAssistant object
ExecutiveAssistant[] candidates = new ExecutiveAssistant[n];
for (int i = 0; i < n; i++) {
// Parse a list of properties
String line = sc.nextLine();
String[] properties = line.split(" ");
  
// add a new ExecutiveAssistant to the array
candidates[i] = new ExecutiveAssistant(
/* firstName */ properties[0],
/* lastName */ properties[1],
/* organizationScore */ Integer.parseInt(properties[2]),
/* punctualityScore */ Integer.parseInt(properties[3])
);
}
  
// sort the ExecutiveAssistant objects
mergeSort(candidates);
  
// print the candidate names
for (int i = 0; i < n; i++) {
System.out.println(candidates[i]);
}
}
  
private static void mergeSort(ExecutiveAssistant[] candidates) {
// TODO complete this
}
}

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

Code

ExecutiveAssistant .java

public class ExecutiveAssistant
{
// properties
private String firstName;
private String lastName;
private int organizationScore;
private int punctualityScore;
  
public ExecutiveAssistant(String firstName,String lastName,int organizationScore,int punctualityScore)
{
// set properties
this.firstName = firstName;
this.lastName = lastName;
this.organizationScore = organizationScore;
this.punctualityScore = punctualityScore;
}
  
@Override
public String toString()
{
return firstName + " " + lastName;
}
public double getJobSuitibilityRating()
{
return (0.8*organizationScore+0.2*punctualityScore);
}
}

Main.java

import java.util.Scanner;

public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
  
// get number of lines
int n = Integer.parseInt(sc.nextLine());
  
// for each line, create an ExecutiveAssistant object
ExecutiveAssistant[] candidates = new ExecutiveAssistant[n];
for (int i = 0; i < n; i++) {
// Parse a list of properties
String line = sc.nextLine();
String[] properties = line.split(" ");
  
// add a new ExecutiveAssistant to the array
candidates[i] = new ExecutiveAssistant(
/* firstName */ properties[0],
/* lastName */ properties[1],
/* organizationScore */ Integer.parseInt(properties[2]),
/* punctualityScore */ Integer.parseInt(properties[3])
);
}
System.out.println("\n\n");
// sort the ExecutiveAssistant objects
mergeSort(candidates);
  
// print the candidate names
for (int i = 0; i < n; i++) {
System.out.println(candidates[i]);
}
}
  
private static void mergeSort(ExecutiveAssistant[] candidates)
{
if(candidates == null) {
return;
}
  
if(candidates.length > 1)
{
int mid = candidates.length / 2;
  
// Split left part
ExecutiveAssistant[] left = new ExecutiveAssistant[mid];
for(int i = 0; i < mid; i++) {
left[i] = candidates[i];
}
  
// Split right part
ExecutiveAssistant[] right = new ExecutiveAssistant[candidates.length - mid];
for(int i = mid; i < candidates.length; i++) {
right[i - mid] = candidates[i];
}
  
mergeSort(left);
mergeSort(right);
  
int i = 0;
int j = 0;
int k = 0;
  
// Merge left and right arrays
while(i < left.length && j < right.length) {
if(left[i].getJobSuitibilityRating() >= right[j].getJobSuitibilityRating()) {
candidates[k] = left[i];
i++;
} else {
candidates[k] = right[j];
j++;
}
k++;
}
  
// Collect remaining elements
while(i < left.length) {
candidates[k] = left[i];
i++; k++;
}
  
while(j < right.length) {
candidates[k] = right[j];
j++; k++;
}
}
}
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
It is 2040, and you’ve just begun your new position as a Director of Engineering at...
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
  • Tried numerous times but I think I'm doing this problem wrong. Will give thumb's up for...

    Tried numerous times but I think I'm doing this problem wrong. Will give thumb's up for help. JAVA starter code: import java.util.Scanner; public class ArraySorter { public static void main(String[] args) { Scanner sc = new Scanner(System.in);    // Read in k, which represents the maximum // distance between a number's current position // and sorted position int k = Integer.parseInt(sc.nextLine());    // Read in the list of numbers int[] numbers; String input = sc.nextLine(); if (input.equals("")) { numbers =...

  • Industrial and Organizational Psychology questions

    Industrial-organizational psychologists are interested in all of the following except1. how to best diagnose clinical disorders and offer therapy to employees.2. how personality characteristics influence work behavior.3. how culture influences people's perceptions of their working environments.4. how people's work affects their home life.An organizational psychologist would be most likely concerned with1. studying the interaction between humans and technology.2. All of the these3. interviewing potential employees.4. helping people organize their schedules and daily planners.5. understanding the emotional and motivational side of...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

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