Question: import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; import java.io.File; public class Classy { public static void main(String[] args){ //Prepare scanner object for taking input Scanner keyboard
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; import java.io.File; public class Classy {
public static void main(String[] args){
//Prepare scanner object for taking input Scanner keyboard = new Scanner(System.in); File file = new File(keyboard.nextLine());
// read n from user int n = keyboard.nextInt(); keyboard.nextLine(); int maxLevels = 0;
//Strings taken directly from user String[] rawData = new String[n]; String[] names = new String[n];
//read Data from user for (int i = 0; i
//find maximum never of levels for(int i = 0; i maxLevels){ maxLevels = rawData[i].split(" ").length - 2; } }
//creating array to store levels of classes int[][] levels = new int[n][maxLevels];
//Parsing and storing data from rawData to levels and names array for (int i = 0; i
String[] x = rawData[i].split(" "); names[i] = x[0].substring(0, x[0].length() - 1);
for (int j = 0; j
int len = x.length - 2;
if(j
/* Gives a relative rank based on classes of different persons If both persons have same class then they will be assigned equal rank. Rank is assigned according to a weight with higher weight of upper levels and lower weight of lower levels So basically rank is weight multiplied by class number class number are as follows upper class - 3 middle class - 2 lower class - 1 */ int[][] rankScore = new int[n][2]; for (int i = 0; i
//This is used to sort the array rankScore according to our rules //i.e we want higher rank on top and people will same rank should come in //Alphabetical order Arrays.sort(rankScore, new Comparator
if(aScore != bScore){ return Integer.compare(bScore, aScore); }else{ return names[aPosition].compareTo(names[bPosition]); } } });
//Finally print the names using sorted indexes from rankScore for (int i = 0; i
The code below only outputs the sample input, i need to add a file reader that reads a txt file with more than 5 (like a 1000 names )names and outputs them based on their class. read the instruction on the attchment pleace and add comments on your code.

![public static void main(String[] args){ //Prepare scanner object for taking input Scanner](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f31637261ab_96666f3163695dcc.jpg)
Sample Input Sample output queen elizabeth mom upper upper lower middle class. inom dad: middle middle lower middle class. dad. queenelizabeth upper upper class unclebob chair lower lower class chair unclebob: middle lower middle class Sample Input Sample output 10 mona. rich lower upper class mary rich mona: upper upper class Charles dave middle lower class tom Charles middle class violet tom: middle class William: lower middle class William carl Carl lower class dave violet middle class frank frank: lower class mary: upper class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
