Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code from assignment 4 (which is required for this question): import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; class Student { private String name; ArrayList

Code from assignment 4 (which is required for this question):

import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; 
class Student { private String name; ArrayList testscores = new ArrayList(); public Student(String name, ArrayList testscores) { this.name = name; this.testscores = testscores; } /** * This method calculates the average of the test scores of the students * * @return the average of the test scores */ public float getAverage() { float sum = 0; for(int i = 0; i  
 public class maintester { public static void main(String[] args) { System.out.print("Enter the name of the input data file: "); Scanner read = new Scanner(System.in); String file_path = read.next(); read.close(); ArrayList students_list = new ArrayList(); try { Scanner fileReader = new Scanner(new File(file_path)); while (fileReader.hasNextLine()) { String line = fileReader.nextLine(); String[] pieces = line.split(" "); String name = pieces[1] + ", " + pieces[0]; ArrayList testgrades = new ArrayList(); for (int i = 2; i  

image text in transcribed

image text in transcribed

Will surely give thumbs up!

CS321 - SPRING 2023 - ASSIGNMENT \#5 20 POINTS Due: See Canvas for Date HOMEWORK GOAL This is an individual homework grade. You will modify your Student class to be able to sort them. Your program should use both the Comparable and Comparator interface approaches as discussed in Chapter 4. You may use my solution or your own from assignment 4 to solve this problem. PROGRAM REQUIREMENTS Adding to program 4, you will still read in an ArrayList of student objects from an input file. I will post a solution to that assignment very soon, so you may check your work against it. Sort your student list in two ways. The default sort using the Comparable implementation should sort the Student objects by name (lastname then use firstname if there is a tie). The alternate sort should sort the students by average. You should create a Comparator implementation that works to do the comparison by average instead of by name. Note: your Main program should use the built in Java Collection sort() in both cases. You do not have to write the sort logic from scratch. Your main program should test the sorts by displaying both versions of the sorted list to the screen. Below is a sample execution. The sample data file is given below. Enter the filename with your student data: c: \ temp \student.txt File opened successfully There were 4 students found in this file. Sorted By Name: \begin{tabular}{rrr} Student Name & No. of Grades & Average \\ \hline Abbas, Jana : & 6 & 90.83 \\ Allen, Beth : & 3 & 100.00 \\ Davis, Joe : & 4 & 66.75 \\ Fitzpatrick, Mika : & 1 & 78.00 \end{tabular} Sorted By Average: \begin{tabular}{rrr} Student Name & No. of Grades & Average \\ \hline Allen, Beth : & 3 & 100.00 \\ Abbas, Jana : & 6 & 90.83 \\ Fitzpatrick, Mika : & 1 & 78.00 \\ Davis, Joe : & 4 & 66.75 \end{tabular} Sample input file for the above test run Beth Allen 100100100 Joe Davis 50507592 Mika Fitzpatrick 78 Jana Abbas 909291869294

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions

Question

Graph each function. f(x) = |x| - 3

Answered: 1 week ago