im fairly new to java and this is my first programming assignment, our objective is to implement 3 students grades in two different classes (Student, grades) and find the average.
Specifications: In the new implementation, the two classes, Student and Grades, we are to implement the following methods:
Student class:
public class Student - Defines a student with a full name and a complete set of grades:
public void setup() - Sets all attributes of the student (name and grades).
private void setName() - Sets the name of the student.
private void setGrades() - Sets all the grades for the student.
public void display() - Displays the complete information on the student.
public double overallGrade() - Returns the overall grade of the student.
Grades class:
public class Grades - Defines a complete set of grades received by a student.
public void setup() - Sets the complete set of grades
public void display() - Displays the complete set of grades
public double average() - Returns the average of the complete set of grades (i.e., it returns a number between 0.0 and 100.0).
Here is my program:
public class Program01 {
public static void main(String[] args)
{
Student bob, john, matt;
Grades grades;
grades = new Grades();
double bobgrade, johngrade, mattgrade;
bob = new Student();
john = new Student();
matt = new Student();
bob.setup();
john.setup();
matt.setup();
bob.display();
john.display();
matt.display();
bobgrade = bob.overallGrade();
johngrade = john.overallGrade();
mattgrade = matt.overallGrade();
grades.average(bobgrade, johngrade, mattgrade);
System.out.println("The overall grade for the class is: " + grades.theSectionAverage);
}
}
public class Student {
Grades grades;
String fullName, firstName, lastName, name;
int studentProgramGrade, studentExamGrade;
public void setup(){
setName();
setGrades();
}
public void setName()
{
System.out.print("Please, enter the student's name in the form of Doe, John or Smith, Jane:");
fullName = Keyboard.readString();
firstName = fullName.substring(fullName.indexOf(" ") + 1, fullName.length());
lastName = fullName.substring(0, fullName.indexOf(","));
name = firstName + " " + lastName;
}
public void setGrades()
{
studentExamGrade = grades.setupExam(name);
studentProgramGrade = grades.setupProgram(name);
}
public void display()
{
System.out.println(name + " " + grades.display());
}
public double overallGrade()
{
final double PROGRAM_WEIGHT = 0.40;
final double EXAM_WEIGHT = 1 - PROGRAM_WEIGHT;
double theOverallGrade;
theOverallGrade = studentProgramGrade * PROGRAM_WEIGHT + studentExamGrade * EXAM_WEIGHT;
return theOverallGrade;
}
}
public class Grades {
int programGrade, examGrade;
double theSectionAverage;
public int setupExam(String studentname)
{
System.out.print("Please, enter the exam grade for " + studentname + ":");
examGrade = Keyboard.readInt();
return examGrade;
}
public int setupProgram(String studentname)
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Please, enter the program grade for " + studentname + ":");
programGrade = Keyboard.readInt();
return programGrade;
}
public String display()
{
return programGrade + " " + examGrade;
}
public double average(double bobgrade, double johngrade, double mattgrade)
{
theSectionAverage = bobgrade + johngrade + mattgrade / 3;
return theSectionAverage;
}
}
when i run my program=, it gives me the following error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Keyboard cannot be resolved
at Student.setName(Student.java:16)
at Student.setup(Student.java:8)
at Program01.main(Program01.java:17)
any help would be greatly appreciated, like i said, im new to java.