Question
In this alternative project we will essentially duplicate Lab5, with one exception. In the Lab5 project the Student class contained a method called inputGrades, which
In this alternative project we will essentially duplicate Lab5, with one exception. In the Lab5 project the Student class contained a method called inputGrades, which prompted for and read in the students test grades.
For this project, the Student class will NOT have grade input functionality, i.e. you will create a Student class that does not have an inputGrades method.
What does that mean..how will you then get input from the user. This means that you will have to modify the Grades class to get the input on the client side, since the server will not be providing the input grades functionality.
Your test run should look exactly the same as your test run for Lab5
____________________________________________________________________________________________
/* Student class */
import java.util.Scanner; public class Student { private String name; private double test1, test2;
public Student(String studentName) { this.name = studentName; } public void inputGrades()
{ Scanner sc = new Scanner(System.in); System.out.println("Enter " + name + "'s score for test 1: "); test1 = sc.nextDouble();
System.out.println("Enter " + name + "'s score for test 2: "); test2 = sc.nextDouble(); } public double getAverage() { return (test1+test2)/2.0; } public void printName() { System.out.println(name); } public String toString() { return "Name: " + name + " Test 1: " + test1 + " Test 2: " + test2; } }
/* Grades Class. Output at bottom*/
public class Grades { public static void main(String[] args) { Student student1 = new Student("Mary"); Student student2 = new Student("Mike");
student1.inputGrades(); System.out.println("Average of Mary: " + student1.getAverage());
System.out.println(); student2.inputGrades();
System.out.println("Average of Mike: " + student2.getAverage()); System.out.println();
System.out.println("Student 1: " + student1); System.out.println("Student 2: " + student2);
} } /* Enter Mary's score for test 1: 80 Enter Mary's score for test 2: 100 Average of Mary: 90.0
Enter Mike's score for test 1: 90 Enter Mike's score for test 2: 85 Average of Mike: 87.5
Student 1: Name: Mary Test 1: 80.0 Test 2: 100.0 Student 2: Name: Mike Test 1: 90.0 Test 2: 85.0 */
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