Has to be in Java, Asked and received answer in C++. Must ask again Program will
ID: 3532680 • Letter: H
Question
Has to be in Java, Asked and received answer in C++. Must ask again Program will use array of student objects to store and report gradebook info for users number of students. Ask how many students, Lastname, First name, score on each of 3 tests, Then a menu on following, Display gradebook, Display student averages, reports highest average, lists students not passing, class average on each test, and end program. Teacher is supplying the "student.class portion of the program and the methods available are in the student.class program. we are to write the student.java using Student(), and Student(String last_name, String first_name), as Constructors. Then followed by methods available String firstName(), String lastName(), int testScore(int index), double testAverage(), int maxTestScore(), boolean isPasssing(), void setTestScore(int index, int score, Last sets students score on specified test(based on index), sets to value of score.
I need response in java code, not C++.
Explanation / Answer
public class Student {
private String lastName;
private String firstName;
private int studentID;
private int units;
private int gradePoints;
public Student(String lname, String fname, int id, int uts, int gpts) {
this.lastName = lname;
this.firstName = fname;
this.studentID = id;
this.units = uts;
this.gradePoints = gpts;
}
public double gpa() {
return (double) gradePoints / (double) units;
}
public void addGrade(int u, char grade) {
if (grade < 'A' || grade > 'F' || grade == 'E') {
System.out.println("ERROR: Grade parameter(" + grade + ") is not of right type.");
return;
}
if (u <= 0) {
System.out.println("ERROR: U parameter(" + u + ") is not valid.");
}
this.units += u;
if (grade != 'F') {
int points = 4 - (grade - 'A');
//Not really sure if this is right, kinda iffy on
//calculating gpa
this.gradePoints += points * u;
}
}
public String toString() {
return getLastName() + ", " + getFirstName() + "(" + getStudentID() +
") Units: " + getUnits() + " Grade Points: " + getGradePoints() +
" GPA: " + gpa();
} /*Returns a string that prints the student data in following format:
Austen, Ann (1000 ) Units: 55 Grade Points: 56 GPA: 1.01 */
/*getters */
public String getLastName() {
return lastName;
}
public String getFirstName() {
return firstName;
}
public int getStudentID() {
return studentID;
}
public int getUnits() {
return units;
}
public int getGradePoints() {
return gradePoints;
}
public static void main(String[] args) {
Student steve = new Student("Jeffries", "Steve", 1000, 4, 4);
System.out.println("Running tests on " + steve.getFirstName() + " " +
steve.getLastName());
System.out.println("His student id is " + steve.getStudentID());
System.out.println("Current GPA: " + steve.gpa());
steve.addGrade(4, 'B');
System.out.println("Added (4, 'B'), now GPA is: " + steve.gpa());
steve.addGrade(0, 'C');
System.out.println("Added invalid amount, GPA is still: " + steve.gpa());
steve.addGrade(3, 'Z');
System.out.println("Added invalid grade, GPA is still: " + steve.gpa());
System.out.println("Current units taken: " + steve.getUnits());
System.out.println("Current grade points: " + steve.getGradePoints());
steve.addGrade(1, 'C');
System.out.println("Added grade (1, 'C')");
System.out.println("Current units taken: " + steve.getUnits());
System.out.println("Current grade points: " + steve.getGradePoints());
System.out.println("Finished with student: " + steve);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.