I can compile the class and the program, but when I try to run Grades.java, it will not run. I don't understand the error message I am getting, and it is a little lengthy.
CODE
// ****************************************************************
CODE
// ****************************************************************
I am not sure how to add code tags... please let me know. But here are the programs:
//**********************************************************
// Student.java
//
// Define a student class that stores name, score on test 1, and
// score on test 2. Methods prompt for and read in grades,
// compute the average, and return a string containing student’s info.
//**********************************************************
import java.util.Scanner;
public class Student
{
//declare instance data
String name;
int test1;
int test2;
//-----------------------------------------------
//constructor
//-----------------------------------------------
public Student(String studentName)
{
//add body of constructor
name = studentName;
}
//-----------------------------------------------
//inputGrades: prompt for and read in student's grades for test1
//and test2
//Use name in prompts, e.g., "Enter's Joe's score for test1".
//-----------------------------------------------
public void inputGrades(Scanner scan)
{
//add body of inputGrades
System.out.println ("Enter " + name + "'s score for test 1");
test1 = scan.nextInt();
System.out.println ("Enter " + name + "'s score for test 2");
test2 = scan.nextInt();
}
//-----------------------------------------------
//getAverage: compute and return the student's test average
//-----------------------------------------------
//add header for getAverage
public double getAverage()
{
//add body of getAverage
double average = ((test1 + test2) / 2);
return average;
}
//-----------------------------------------------
//getName: print the student's name
//-----------------------------------------------
//add header for getName
public String getName()
{
//add body of getName
return name;
}
}
and:
//**********************************************************
// Grades.java
//
// Use Student class to get test grades for two students
// and compute averages
//
//**********************************************************
import java.util.Scanner;
public class Grades
{
public static void main(String[] args)
{
int test1, test2;
Scanner scan = new Scanner (System.in);
Student student1 = new Student("Mary");
//create student2, "Mike"
Student student2 = new Student("Mike");
//input grades for Mary
System.out.println("Enter test 1 score for Mary: ");
student1.inputGrades(scan);
//print average for Mary
System.out.println("Mary's average is: " + student1.getAverage());
System.out.println();
//input grades for Mike
student2.inputGrades(scan);
//print average for Mike
System.out.println("Mike's average is: " + student2.getAverage());
}
}