Write a program that reads a file line by line, and reads each line’s tokens to...

80.2K

Verified Solution

Question

Programming

Write a program that reads a file line by line, and reads eachline’s tokens to create a Student object that getsinserted into an ArrayList that holdsStudent objects.  Each line from thefile to read will contain two strings for first and last name, andthree floats for three test grades.  After reading thefile and filling the ArrayList withStudent objects, sort theArrayList and output the contents of theArrayList so that the students with the highestaverage are listed on top.

The Student class should have instance data forfirst and lastname, and a floatarray to hold three testgrades.  Create getters andsetters for first and last name.  Createone getter andone setter for insertingtests into thearray.  Don’t forget toverify that the quiz grades are within arange that makes sense before you insert them into thearray.  Also, verify that you do not go outside theindex range of the array when insertingquizzes.  Create a method to calculateand return test average. Also, override thetoString method and the equalsmethod to something that make sense. Also,implement the Comparableinterface on the Student class so that when youcompare Student objects by comparing thestudent's test average. If the average is the same whencomparing, then compare the last names. If the last names are thesame, then compare the first names.

Here is the file that the program should read:

Text File:

Frank Hanford 78.5 65.9 98.2John Blake 93.1 85.9 89.1Alex Sanders 87.1 56.9 67.2Jane Hope 72.1 85.1 77.9Donald Davidson 85.1 72.1 77.9Alan Davidson 77.9 72.1 85.1Perkins Jenkins 87.5 75.9 90.1Barbara Thompson 90.1 89.9 99.7Michael Jones 78.1 69.9 81.2

Answer & Explanation Solved by verified expert
4.4 Ratings (728 Votes)
Given below is the code for the question Please do rate the answer if it helped Thank you If you are using eclipse as your IDE make sure you dont put the input file inside the src folder Just put it directly under the project folder otherwise you will get file not found error Studentjava public class Student implements Comparable private String fname private String lname private float grades public Student fname lname grades new float3 public StudentString fname String lname thisfname fname thislname lname grades new float3 public String getFname return fname public void setFnameString fname thisfname fname public String getLname return lname public void setLnameString lname thislname lname public void    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students