StudentData.java - courseGrade(testScores/alternate...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * By Cole Hudson * Date: 4/26/2015 * Purpose: Use assertions and exceptions to keep track of students * * PMR in README.txt */ public class StudentData { //instance variables private String firstName; private String lastName; private double[] testScores; private char grade; //getters public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public double[] getTestScores() { return testScores; } //setters public void setFirstName(String firstName) { this.firstName = firstName; } public void setLastName(String lastName) { this.lastName = lastName; } public void setTestScores(double[] testScores) { this.testScores = testScores; } //constructor StudentData(String firstName, String lastName, double[] testScores) { this.firstName = firstName; if(firstName.length() == 0) { throw new IllegalArgumentException("Name must be longer than 0"); } this.lastName = lastName; if(lastName.length() == 0) { throw new IllegalArgumentException("Name must be longer than 0"); } this.testScores = testScores;
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: courseGrade(testScores); } //alternate StudentData() { } //methods //toString public String toString() { String returnString = String.format("%-10s %-10s ", firstName, lastName); for(double score : testScores) { returnString += String.format("%-7.2f", score); } returnString += " " + courseGrade(testScores); return returnString; } //course grade public char courseGrade(double list) { if(list.length == 0) { throw new IllegalArgumentException("Grade list can not be empty"); } double average = 0.0; for(double score : list) { average += score; } average /= list.length; //course grades based off of my school if(average >= 93) { grade = 'A'; return 'A'; } else if(average >= 86) { grade = 'B'; return 'B'; } else if(average >= 79) { grade = 'C'; return 'C'; } else if(average >= 72) { grade = 'D'; return 'D'; } else if(average >= 65) { grade = 'E'; return 'E'; } grade = 'F'; return 'F'; } }...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern