The program reads a text file with student records (first name, last name and gr
ID: 3661202 • Letter: T
Question
The program reads a text file with student records (first name, last name and grade) and prints them on the terminal window. Then it prints three separate lists of excellent students, ok students and failure students according to their grades: excellent (> 89), ok [60,89], and failure (< 60). Finally, the program prints the total number of students, their grade average, and the students with highest and lowest grade. For example, if the input text file includes the following data: John Smith 90 Al Clark 80 Ann Miller 75 Sue Taylor 55 the program prints the following: Studentts with excellent grades: John Smith 90 Students with ok grades Al Clark 80 Ann Miller 75 Students with failure grades: Sue Taylor 55 Total number of students: 4 Average grade: 75 Highest grade: John Smith 90 Lowest grade: Sue Taylor 55 Requirements and restrictions: Define a class Student to represent the student information (student names and grade). Do NOT use public instance variables. Use an array of objects of class Student to store the student information. Print the students in the grade categories from the array and find the students with highest and lowest grade using the array only. When you write your program use proper names for the variables suggesting their purpose. format your code accordingly using indentation and spacing. use multiple line comment in the beginning of the code and write your name, e-mail address, class, and section. for each line of code add a short comment to explain its meaning. Extra credit (up to x points) will be given for extending the program to sort the array of students by grade and print the sorted array. Use the bubble sort algorithm as implemented in array.java. This is the array.java code-- import java.util.Scanner; class array { public static void main (String[] args) { Scanner scan = new Scanner(System.in); int [] a = new int [100]; int i, n = 0, min, max; float total = 0; System.out.println ("Type a sequence of numbers separated by blanks (Ctrl-Z to end):"); while (scan.hasNext()) { a[n] = scan.nextInt(); n = n + 1; } min = a[0]; max = a[0]; for (i = 0; i < n; i++) { if (max < a[i]) max = a[i]; if (min > a[i]) min = a[i]; total = total + a[i]; } System.out.print ("You entered " + n + " numbers: "); System.out.print ("Min = " + min + ", Max = " + max + ", Average = " + total/n); int t, swap = 0; do { swap = 0; for (i=0; ia[i+1]) { t=a[i]; a[i]=a[i+1]; a[i+1]=t; swap++; } } while (swap>0); System.out.print (" Sorted: "); for (i=0; iExplanation / Answer
class AddRationals { public static void main (String[] args) { String div; int a, b, c, d, e, f; //declairs the integers Scanner scan = new Scanner(System.in); System.out.print("Type a rational number (a / b): "); //tells user to type in a rational number a = scan.nextInt(); div = scan.next("/"); b = scan.nextInt(); System.out.print("Type another rational number (c / d): "); //tells user to type in another rational number c = scan.nextInt(); div = scan.next("/"); d = scan.nextInt(); System.out.print("Type another rational number (e / f): "); //tells user to type in another rational number e = scan.nextInt(); div = scan.next("/"); f = scan.nextInt(); Rational p = new Rational(a,b); // p points to a new instance of Rational Rational q = new Rational(c,d); // q points to a new instance of Rational Rational t = new Rational(e,f); Rational r = p.sum(q); // no need of new here, sum returns a new Ratonal object Rational s = r.sum(t); System.out.println(p + " + " + q + " + " + t + " = " + s); //Adds P + Q + T and finds S s.reduce(); System.out.println("Reduced sum is: " + s); // Prints the sum if (p.lessThan(q) && p.lessThan(t)) System.out.println("Minimum is " + p); //Prints the Minimum else System.out.println("Minimum is " + q); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.