Question
Student.java class coding below: //Beginning of class named Student public class Student { private String studentName; private int idNumber; private int sumGrades; private int numGrades;
Student.java class coding below:
//Beginning of class named Student public class Student {
private String studentName; private int idNumber; private int sumGrades; private int numGrades;
//Which will add the grade to SumGrades and will also add 1 to numGrades public void addGrade(int newGrade) { sumGrades += newGrade; numGrades++; } //Which calculates the student's average public double getAverage() { return numGrades / (double) 3; } public Student(String _studentName, int _idNumber) { studentName = _studentName; idNumber = _idNumber; sumGrades = 0; numGrades = 0; } // Set up String to String method public String toString() { return studentName + " " + idNumber + " " + getAverage(); } }
Report3 class coding below:
import java.util.Scanner;
public class Report3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); //Student 1 information System.out.print("Student1: "); System.out.print("\tName: "); String name = sc.nextLine(); System.out.printf("\tID: "); int idNumber = sc.nextInt(); System.out.printf("\tGrade1: "); int grade1 = sc.nextInt(); System.out.printf("\tGrade2: "); int grade2 = sc.nextInt(); System.out.printf("\tGrade3: "); int grade3 = sc.nextInt(); //Student 2 information System.out.printf("Student2: "); System.out.print(" \tName: "); String name2 = sc.nextLine(); System.out.printf("\tID: "); int idNumber2 = sc.nextInt(); System.out.printf("\tGrade1: "); int grade4 = sc.nextInt(); System.out.printf("\tGrade2: "); int grade5 = sc.nextInt(); System.out.printf("\tGrade3: "); int grade6 = sc.nextInt(); //Student 3 information System.out.printf("Student3: "); System.out.print(" \tName: "); String name3 = sc.nextLine(); System.out.printf("\tID: "); int idNumber3 = sc.nextInt(); System.out.printf("\tGrade1: "); int grade7 = sc.nextInt(); System.out.printf("\tGrade2: "); int grade8 = sc.nextInt(); System.out.printf("\tGrade3: "); int grade9 = sc.nextInt(); }
}
Lab 05: Implementing Classes & Data Types Exercise 1 - Implementing a class and tester (10 points) The exercise must be completed during the lab period Write a simple class grade report program. This will work for a class of exactly three students (quite a limitation) Write a class to represent the student's record. This class (named Student) should have a constructor to which we will pass the student's name (String) and id number (int). It will have attributes for these two values, plus two other attributes which we could call sumGrades and numGrades, both ints and both initialized to zero Besides the constructor, write a method which will add the grade to sumGrades and will also add 1 to numGrades Also, write a method public void addGrade (int newGrade) public double getAverage () beware of which calculates the student's average (this is the sum of the grades divided by the number of grades integer division here) Finally, write a toString method in this class public String tostring () which will return a string formatted as follows ic grade ame That's 10 characters for the name (exactly, no overflow), left justified, then a space, then 5 characters for the id, right justified, then a space, then 7 characters for the grade (right justified) with 2 spaces to the right of the decimal point. Use String. format in this method. Now, write another class named (the Tester) Report3. The main program is here and will follow the following nput output script: Student1: Name: Fred Smith ID: 12345 Gradel: 80 Grade2: 70 Grade3: 80 Student2: Name Martha Stewart ID: 54321 Gradel: 90 Grade2: 60 Grade3: 75 Student3: Page 1 of 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started