import java.util.Scanner;
class Employee implements Comparable{
String name;
int salary;
Employee(String name,int salary){
this.name=name;
this.salary=salary;
}
@Override
public int compareTo(Employee o) {
// TODO Auto-generated method stub
return o.salary-this.salary;
}
@Override
public String toString() {
String temp=this.name+" "+salary;
return temp;
}
}
public class SortGame {
public static void main(String[] args) {
Scanner scn =new Scanner(System.in);
int min=scn.nextInt();
int num=scn.nextInt();
Employee[] employ=new Employee[num];
for(int i=0;i<num;i++) {
String name=scn.nextLine();
scn.nextLine();
int salary=scn.nextInt();
employ[i]=new Employee(name, salary);
}
sort(employ);
display(employ);
}
public static <T extends Comparable<T>> void sort(T[] arr) {
for(int counter=0;counter<arr.length-1;counter++) {
for(int j=0;j<arr.length-1-counter;j++) {
if((arr[j].compareTo(arr[j+1]))>0) {
T temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
}
public static <T> void display(T[] arr) {
for (T val : arr) {
System.out.println(val);
}
}
}
My display function is Not Concatenating Employee name.