My errors:
Student.java:11: illegal start of expression
private String name; //Student name
^
Student.java:12: illegal start of expression
private int test1; //Score on test 1
^
Student.java:13: illegal start of expression
private int test2; //Score on test 2
^
Student.java:14: illegal start of expression
private int test3; //Score on test 3
^
Student.java:18: illegal start of expression
public Student(){
^
Student.java:18: ';' expected
public Student(){
^
Student.java:29: illegal start of expression
public void setName (String nm){
^
Student.java:29: illegal start of expression
public void setName (String nm){
^
Student.java:29: ';' expected
public void setName (String nm){
^
Student.java:29: ';' expected
public void setName (String nm){
^
Student.java:34: illegal start of expression
public String getName (){
^
Student.java:34: ';' expected
public String getName (){
^
Student.java:39: illegal start of expression
public void setScore (int i, int score){
^
Student.java:39: illegal start of expression
public void setScore (int i, int score){
^
Student.java:39: ';' expected
public void setScore (int i, int score){
^
Student.java:39: <identifier> expected
public void setScore (int i, int score){
^
Student.java:39: not a statement
public void setScore (int i, int score){
^
Student.java:39: ';' expected
public void setScore (int i, int score){
^
Student.java:46: illegal start of expression
public int getScore (int i){
^
Student.java:46: ';' expected
public int getScore (int i){
^
Student.java:46: ';' expected
public int getScore (int i){
^
Student.java:53: illegal start of expression
public int getAverage(){
^
Student.java:53: ';' expected
public int getAverage(){
^
Student.java:60: illegal start of expression
public int getHighScore(){
^
Student.java:60: ';' expected
public int getHighScore(){
^
Student.java:69: illegal start of expression
public String toString(){
^
Student.java:69: ';' expected
public String toString(){
^
Student.java:79: reached end of file while parsing
}
^
28 errors
/* Student.java
Manage a student's name and three test scores.
*/
public class Student
{
public static void main ( String [] args);
{
//Instance variables
//Each student object has a name and three test scores
private String name; //Student name
private int test1; //Score on test 1
private int test2; //Score on test 2
private int test3; //Score on test 3
//Constructor method
public Student(){
//Initialize a new student's name to the empty string and the test
//scores to zero.
name = "";
test1 = 0;
test2 = 0;
test3 = 0;
}
//Other methods
public void setName (String nm){
//Set a student's name
name = nm;
}
public String getName (){
//Get a student's name
return name;
}
public void setScore (int i, int score){
//Set test i to score
if (i == 1) test1 = score;
else if (i == 2) test2 = score;
else test3 = score;
}
public int getScore (int i){
//Retrieve score i
if (i == 1) return test1;
else if (i == 2) return test2;
else return test3;
}
public int getAverage(){
//Compute and return the average
int average;
average = (int) Math.round((test1 + test2 + test3) / 3.0);
return average;
}
public int getHighScore(){
//Determine and return the highest score
int highScore;
highScore = test1;
if (test2 > highScore) highScore = test2;
if (test3 > highScore) highScore = test3;
return highScore;
}
public String toString(){
//Construct and return a string representation of the student
String str;
str = "Name: " + name + "\n" + // "\n" denotes a newline
"Test 1: " + test1 + "\n" +
"Test 2: " + test2 + "\n" +
"Test 3: " + test3 + "\n" +
"Average: " + getAverage();
return str;
}
}

New Topic/Question
Reply




MultiQuote






|