Question

In: Computer Science

Display nonduplicate names in ascending order) Given one or more text files, each representing a day’s...

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

Solutions

Expert Solution

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!...


Related Solutions

There are two text files, whose names are given by two String variables, file1 and file2....
There are two text files, whose names are given by two String variables, file1 and file2. These text files have the same number of lines. Write a sequence of statements that creates a new file whose name consists concatenating the names of the two text files (with a "-" in the middle) and whose contents of merging the lines of the two files. Thus, in the new file, the first line is the first line from the first file, the...
This is JAVA PROGRAMMING Sort the contents of the two files in ascending order and combine...
This is JAVA PROGRAMMING Sort the contents of the two files in ascending order and combine them into one new file (words.txt). When comparing string order, you must use the compareTo method and make an exception.The source code below is a code that only combines files. Use the comparedTo method to sort the contents of the two files in ascending order.(ex. if(str1.compareTo(str2)<0) {}) <file1.txt> at first   castle   consider   considerable   enlighten   explain   explanation   female   <file2.txt> consideration   considering that   education   educational   endow  ...
Written in MIPS assembly language If given an array which is sorted in ascending order, as...
Written in MIPS assembly language If given an array which is sorted in ascending order, as well as its length and a target value. You are asked to find the index of this target value in the array using binary search algorithm. Here is an example: array 1, 4, 6, 8, 10, 12 length 6 target 8 2 In this case, the returned result should be assigned to be 3, as array[3] is equal to target. (Note: The target will...
list in ascending order the levels of hierarchy of complexity. define each level and provide an...
list in ascending order the levels of hierarchy of complexity. define each level and provide an example for each.
in C++ Given two integer arrays sorted in the ascending order, code the function SortArrays to...
in C++ Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them into one array in the descending order. You need to make sure if the values in the arrays are changed, it will still work. (25 points) #include <iostream> using namespace std; void SortArrays (int a[], int b[], int c[], int size); void printArray(int m[], int length); const int NUM = 5; int main() { int arrA[NUM] = {-2, 31, 43, 55, 67};...
IN MY SQL: - Display each Author’s ID, first and last names and the total number...
IN MY SQL: - Display each Author’s ID, first and last names and the total number of pages for all of the Books they have written. - Display each Book genre as well as the number of Books written in that genre with the column header “Number Of Books” - Display the Author’s first and last name, as well as their ID, and the Book title and number of pages for all of the books they have written that have...
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them...
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them into one array in the descending order. You need to make sure if the values in the arrays are changed, it will still work. (25 points) #include using namespace std; void SortArrays (int a[], int b[], int c[], int size); void printArray(int m[], int length); const int NUM = 5; int main() { int arrA[NUM] = {-2, 31, 43, 55, 67}; int arrB[NUM] =...
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them...
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them into one array in the descending order. You need to make sure if the values in the arrays are changed, it will still work. (25 points) #include <iostream> using namespace std; void SortArrays (int a[], int b[], int c[], int size); void printArray(int m[], int length); const int NUM = 5; int main() { int arrA[NUM] = {-2, 31, 43, 55, 67}; int arrB[NUM]...
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them...
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them into one array in the descending order. You need to make sure if the values in the arrays are changed, it will still work. (25 points) #include <iostream> using namespace std; void SortArrays (int a[], int b[], int c[], int size); void printArray(int m[], int length); const int NUM = 5; int main() { int arrA[NUM] = {-2, 31, 43, 55, 67}; int arrB[NUM]...
a python function that reads two text files and merges in to one Linked List, be...
a python function that reads two text files and merges in to one Linked List, be able to print each Item in the new single Linked List class Node(object): item = -1 next = None def __init__(self, item, next): self.item = item self.next = next ================================ textfile! 979 2744 5409 1364 4948 4994 5089 703 1994 4637 2228 4004 1088 2812 170 5179 2614 238 4523 4849 3592 3258 1951 3440 3977 1247 4076 1824 4759 4855 5430 347 974...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT