#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)

red jacinthBOT
#

<@&987246399047479336> please have a look, thanks.

hazy shadow
#

@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

strong cliff
#

you actually do it here

hazy shadow
#

since thats the ascii code for A

#

and in your else branch you don't return an int at all

bitter quail
#

can any one of you hop on a call?

strong cliff
#

prefer text

hazy shadow
#
 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

bitter quail
#

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

strong cliff
#

please always provide the error

bitter quail
#

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

strong cliff
#

well you know how to use a method?

#

determineGrade(...)

bitter quail
#

hold up I think I got it

strong cliff
#

also why does it take 5 arguments?

bitter quail
#

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));
}
}

hazy shadow
bitter quail
#

they are test arguments

#

A is test 1, B is test 2, and etc

ashen hound
hazy shadow
bitter quail
#

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

hazy shadow
#

maybe call them firstScore, secondScore, etc.

#

still something to fix, but more directionally right

ashen hound
bitter quail
#

yea I didn't define them yet

ashen hound
#

well that's actually the problem

bitter quail
#

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

ashen hound
bitter quail
#

let me try something and I will let you know

#

I am going to mess with something really quick

ashen hound
#

The method should return a character (char), not an integer.

#
static char determineGrade(int average) {
        if (average >= 90) {
            return 'A';
        } else {
            return 'F';
        }
    }
bitter quail
#

figured it out