My assignment is this:
Create a Java program that satisfies the following requirements:
- Create a single Java source file named MaxScore.java
- Create a single class named MaxScore
- The MaxScore class has two methods:
- main
- maxScore
The maxScore method takes seven integer arguments When called, the maxScore method returns the largest of the seven input arguments
The main method performs the following steps seven times:
- Write to STDOUT: Enter a score:
- Read from STDIN an integer value and store it in a new variable
- The main method calls maxScore with the seven integers obtained from STDIN
- The main method writes to STDOUT the maximum score in the following format: Maximum score is:
My main problem is that the symbol is not defined. I have tried this a bunch of times with no luck. I'm sure it's a fairly easy to fix problem but I could really appreciate some help. Here is my code:
import java.util.Scanner;
public class MaxScore1{
public static void main(String[] args){
//establishes the main method first
int z = a,b,c,d,e,f,g;
z = maxScore(a,b,c,d,e,f,g);
Scanner foo = new Scanner( System.in );
//repeating the code 7 times in order to get 7 integers that are the scores
System.out.print("Enter a score: ");
a = foo.nextInt();
System.out.print("Enter a score: ");
b = foo.nextInt();
System.out.print("Enter a score: ");
c = foo.nextInt();
System.out.print("Enter a score: ");
d = foo.nextInt();
System.out.print("Enter a score: ");
e = foo.nextInt();
System.out.print("Enter a score: ");
f = foo.nextInt();
System.out.print("Enter a score: ");
g = foo.nextInt();
System.out.println("Maximum value returned by maxScore is " + z + ".");
}
public static int maxScore(int a,int b,int c,int d,int e,int f,int g){
//calling all the integers obtained earlier
int x;
//establishing a base for the currentscore
x = 0;
//establishing the variable
if (a > x){
//a set of if statements to return the maximum value
x = a;
}
if (b > x){
x = b;
}
if (c > x){
x = c;
}
if (d > x){
x = d;
}
if (e > x){
x = e;
}
if (f > x){
x = f;
}
if (g > x){
x = g;
}
return x; //returning the maximum value obtained.
}
}
My errors are:
MaxScore1.java:6: error: cannot find symbol
int z = a,b,c,d,e,f,g;
^
symbol: variable a
location: class MaxScore1
MaxScore1.java:8: error: cannot find symbol
z = maxScore(a,b,c,d,e,f,g);
^
symbol: variable a
location: class MaxScore1
MaxScore1.java:13: error: cannot find symbol
a = foo.nextInt();
^
symbol: variable a
location: class MaxScore1
3 errors