#Why is my determineGrade method not working? Would prefer if we can hop on a call to solve the issue
1 messages · Page 1 of 1 (latest)
@bitter quail 'A' is not the same as "A"
also determine grade returns an int
'A' can be magically converted into an int
but its 65
you actually do it here
since thats the ascii code for A
and in your else branch you don't return an int at all
can any one of you hop on a call?
prefer text
static String determineGrade(int A, int B, int C, int D, int E)
{
if (A >= 90) {
return "A";
} else {
return "unknown";
}
}
try that
so instead of an int, returning a String
and then you have to return from every branch the function might take
it is still giving me an error
import java.util.Scanner;
//Created my Main class
public class TestAverageGrade
{
//Created my first method for the user to store test scores in variables
static int calcAverage(int A, int B, int C, int D, int E)
{
//The value is going to return all five of the test scores divded by 5.
return (A + B + C + D + E) / 5;
}
static String determineGrade(int A, int B, int C, int D, int E)
{
if (A >= 90) {
return "A";
} else {
return "oh well.";
}
}
public static void main(String[] args)
{
Scanner intInput = new Scanner(System.in);
int i = 1;
String scoreInput = "What is the score of test %d \n";
System.out.printf(scoreInput, (i++));
int A = intInput.nextInt();
System.out.println(determineGrade);
}
}
when I call the method it gives me a error
please always provide the error
do I have to list all the integers?
is taht way
that*
TestAverageGrade.java:30: error: cannot find symbol
System.out.println(determineGrade);
^
symbol: variable determineGrade
location: class TestAverageGrade
1 error
hold up I think I got it
also why does it take 5 arguments?
my professor wants it to take arguments
rather than just having a running total
which would have been easier
import java.util.Scanner;
//Created my Main class
public class TestAverageGrade
{
//Created my first method for the user to store test scores in variables
static int calcAverage(int A, int B, int C, int D, int E)
{
//The value is going to return all five of the test scores divded by 5.
return (A + B + C + D + E) / 5;
}
static String determineGrade(int A, int B, int C, int D, int E)
{
if (A >= 90) {
return "A";
} else {
return "oh well.";
}
}
public static void main(String[] args)
{
Scanner intInput = new Scanner(System.in);
int i = 1;
String scoreInput = "What is the score of test %d \n";
System.out.printf(scoreInput, (i++));
int A = intInput.nextInt();
System.out.println(determineGrade(A, B, C, D, E));
}
}
very confused by what you are putting in A, B, C, D, and E
where do you get the variables in the form of letters at the entry point
so A is the grade on the first test?
A is a varibale that the first test score it going to be stored inside it
so that my determineGrade method converts it from a int to a string
maybe call them firstScore, secondScore, etc.
still something to fix, but more directionally right
but where do you get it? You don't define a variable "B", likewise C, D etc.
yea I didn't define them yet
well that's actually the problem
it is?
but I was giving it a value based on the user input
I just removed it until I was done with my second input
Scanner intInput = new Scanner(System.in);
int i = 1;
String scoreInput = "What is the score of test %d \n";
System.out.printf(scoreInput, (i++));
int A = intInput.nextInt();
System.out.printf(scoreInput, (i++));
int B = intInput.nextInt();
System.out.printf(scoreInput, (i++));
int C = intInput.nextInt();
System.out.printf(scoreInput, (i++));
int D = intInput.nextInt();
System.out.printf(scoreInput, (i++));
int E = intInput.nextInt();
System.out.println(calcAverage(A, B, C, D, E));
}
see
this is going to go in my main method
what error does ide display?
let me try something and I will let you know
I am going to mess with something really quick
The method should return a character (char), not an integer.
static char determineGrade(int average) {
if (average >= 90) {
return 'A';
} else {
return 'F';
}
}
figured it out