Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java - Display score

josh2013
josh2013 


Console Welcome to the Student Scores Application. Enter number of students to enter: 4 Lowe, Doug: 82 “Your grade is below class average” Jordan, Michael: 92 Burns, Joe: 93 Jackson, Randy:95 Class Test Score Average: 90.5 Operation • This application accepts the last name, first name, and score for one or more students and stores the results in an array. Then, it prints the students and their scores in alphabetical order by last name. Specifications • The program should implement a class named Student that stores the last name, first name, and score for each student. This class should implement the IComparable interface so the students can be sorted by name. If two students have the same last name, the first name should be used to determine the final sort order. • The program should use an array to store the Student objects. Then, it should sort the array prior to printing the student list. • Validate the input so the user can enter only a positive integer for the number of students, the last or first name can’t be an empty string, and the score is an integer from 0 to 100. Enhancements • Add the ability to sort the list by score. This turns out to be a surprisingly complicated enhancement. The easiest solution is probably to create a second student class (perhaps called StudentScore) that implements the IComparable interface to sort by score rather than by name. • Read data about students from a text file. The data for each student will be last name, first name, and test score. • You do not know how many students there are. There will be fewer than 100. • Display the class average after displaying information for all individual students. • Display a message after each student whose grade is more than 10 points below the class average. • You may read the input file only once. Studentdata.txt Gator Ali 85 Vator Ella 75 Beam James 95 Class Lastin 55 Lowe Doug 82 Jordan Michael 92 Jackson Randy 95 Huck Alex 82 Weber Ryan 90 Henry John 79 Brown John 93 Oaks Jen 89 Package chapt11 and name application CH11PR112App. ReadStudentData.java package chapt11; import java.io.*; import java.util.*; public class ReadStudentData { /** * Sample application to read data from text file named Students.txt located * in the same directory folder as the application. */ public static void main(String[] args) throws Exception { Scanner aScanner = new Scanner(new FileReader( "src//chapt11//Studentdata.txt")); while (aScanner.hasNext()) { String studentLastName = aScanner.next(); String studentFirstName = aScanner.next(); double score = aScanner.nextDouble(); System.out.println(studentFirstName + " " + studentLastName + " " + score); } } } Attachments
Tags Clarifications

Answers

Java - Student Scores - Solution

dickersonka
dickersonka 



Attached is the solution including source and comments to the Java - Student Scores assignment. This solution sorts by name and reads from a text file, if you need any changes, let us know. Attachments
StudentScores.zip (2 K) Download
Preview
System.out.print(student.getLastName() + ", " + student.getFirstName() + ": " + student.getScore()); //check whether to display below average if(student.getScore() < warnScore){ System.out.print(" Your grade is below class average"); } System.out.println(); } } //format for average DecimalFormat df = new DecimalFormat("0.0");

Preview
return score; } public void setScore(double score) { this.score = score; } @Override public int compareTo(Object obj) { //cast object to compare Student s2 = (Student)obj; //compare last names int compare = getLastName().compareTo(s2.getLastName());

Preview
Vierling Percy 78 Nicol Lenora 20 Spearman Ronni 63 Guo Yee 43 Beresford Joie 29 Lamborn Vernell 100 Gaylor Malka 49 Manuelito Gus 79 Calnan Quincy 81 Laurich Audrea 49 Hanes Drema 24 Milera Melissa 63 Rachal Neda 28 Sailer Petronila 43 Bingman Yuk 47 Huebner Luvenia 46 Duhaime Nerissa

Screenshots
Purchase Answer