In: Computer Science
Display nonduplicate names in ascending order) Given one or more text files, each representing a day’s attendance in a course and containing the names of the students who attended the course on that particular day, write a program that displays, in ascending order, the names of those students who have attended at least one day of the course. The text file(s) is/are passed as command-line argument(s). USe language java, ide netbeans
package example;
import java.lang.Comparable;
import java.util.Arrays;
public class Student implements Comparable<Student>{
private int day;
private String name;
public Student(int day,String name){
this.day=day;
this.name=name;
}
public int getDay(){
return day;
}
public String getName(){
return name;
}
public int compareTo(Student s){
if(this.day>s.day)
return 1;
return -1;
}
public static void main(String[] args){
Student[] sarr=new Student[3];
sarr[0]=new Student(2,"John");
sarr[1]=new Student(1,"Stove");
sarr[2]=new Student(4,"Johnson");
Arrays.sort(sarr);
int i;
for(i=0;i<sarr.length;i++){
System.out.println(sarr[i].getDay()+" "+sarr[i].getName());
}
}
}
Here is the screenshot of the program which is run in the IDE NetBeans:
Now,here is the output of the program, which is sorted according to the suggestion provided in the question:
Thanks!...