#Can someone help me with this methods question

1 messages · Page 1 of 1 (latest)

snow pierBOT
#

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

snow pierBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

sullen sluice
#

Hey! according to this question, you need to write 2 functions

#

the 1st one is to enter the scores made in last 3 games and return the average : sum / 3; I guess

#

the 2nd function is going to take the result of the 1st one, and distinguish whether the user is qualified

#

you can make a class and inside you declare the 2 functions with static keyword, and you declare main() method where your whole program is

compact python
#

your return is in the wrong spot

#

and u might lack a }

sullen sluice
#

the return must be place at the end of the function

#

hmm you need to use Scanner object to enter the scores

#

the answer is not an input

#

i think this code is fine

#

wdym by answer key ?

#

I see a scanner !

#

it does

#

static Scanner input = new Scanner(System.in);

scenic marsh
#

please do not follow in your teacher's footsteps of predeclaring variables

compact python
#

yeah, and he/she made faults aswell

scenic marsh
#

heres a slightly better solution: ```java
import java.util.Scanner;

public class Exercise1 {
public static void main(String[] args) {
double averagePoints = getAveragePoints();
if (isAllStar(averagePoints)){
System.out.println("He is an allstar!");
}
else {
System.out.println("He is NOT an allstar.");
}
}

public static double getAveragePoints(){
    Scanner input = new Scanner(System.in);
    System.out.print("Enter game 1 points: ");
    int gamePoints1 = input.nextInt();
    System.out.print("Enter game 2 points: ");
    int gamePoints2 = input.nextInt();
    System.out.print("Enter game 3 points: ");
    int gamePoints3 = input.nextInt();

    return (gamePoints1 + gamePoints2 + gamePoints3) / 3.0;
}

public static boolean isAllStar(double averagePoints){
    if (averagePoints >= 25){
        return true;
    }
    return false;
}

}```

#

thats a valid answer too

#

I forget some pseudo famous quote that says if ur doing something more than 2 times use a lop

compact python
#

dont repeat yourself ? :p

scenic marsh
#

yeah but something else

#
    public static double getAveragePoints(){
        Scanner input = new Scanner(System.in);
        int totalPoints = 0;
        for (int gameNumber = 1; gameNumber <= 3; ++gameNumber) {
            System.out.print("Enter game " + gameNumber + " points: ");
            totalPoints += input.nextInt();
        }
        return totalPoints / 3.0;
    }```
#

could also name gameNumber to i but wanted to be more explicit since it has a meaning

sullen sluice
#

its better to use nextDouble()

#

and close scanner after the for()

compact python
#

careful on that code style though, its stopping at 4 with display

scenic marsh
#

you should not use nextDouble in this context because basketball doesnt half non-integer points.
You should also never close the scanner.
If you intend to reuse the scanner, then make it static like the solution (or a class member when they get there)

scenic marsh
#

because basketball dont have non-integer points.

compact python
#

(use case problem, not code problem)

sullen sluice
scenic marsh
#

Even a code problem too because adding doubles could give .999999999 errors

#

If you close the scanner you can never reopen System.in

compact python
#

read the text on the bottom

#

not initialized

#

( aka it has no value )

scenic marsh
#

( aka dont predeclare variables like this instructor is doing )

sullen sluice