So you think you can dance | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

So you think you can dance

Hi everyone! I have an issue with one of the coding here. The question is as below: You are an assistant on a TV show where celebrities are dancing and 4 judges evaluate their performance and give them a score between 1 and 10. The program you are given takes the scores as input. Complete the method to take them as parameters, then calculate and return the average score. This is my coding: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); double score1 = read.nextDouble(); double score2 = read.nextDouble(); double score3 = read.nextDouble(); double score4 = read.nextDouble(); double avgScore = getAverageScore(score1, score2, score3, score4); System.out.println(avgScore); } //create your method here public static double getAverageScore(double score1, double score2, double score3, double score4) { double[] numArray = {score1, score2, score3, score4}; double sum = 0.0; for (double num: numArray) { sum += num; } double avgScore = sum / numArray.length; System.out.format("The average is: %.2f", avgScore); } return; } I hope someone can help me and explain to me what i did wrong. Thanks.

10th Aug 2021, 3:42 AM
Nur Ameera Nabila Binti Abdul Rahim
Nur Ameera Nabila Binti Abdul Rahim - avatar
3 Answers
0
You have to return <avgScore> from getAverageScore() method. Also an array in getAverageScore() isn't necessary. You can sum it directly; double sum = score1 + score2 + score3 + score4; double avgScore = sum / 4; And return <avgScore> return avgScore;
10th Aug 2021, 3:55 AM
Ipang
0
return at the end of method is outside method and doesn't return double type. There are two output commands but better is one
10th Aug 2021, 1:02 PM
zemiak
0
Hey! I made the code a little easier for you, try this import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); double score1 = read.nextDouble(); double score2 = read.nextDouble(); double score3 = read.nextDouble(); double score4 = read.nextDouble(); AverageScore(score1,score2,score3,score4); } //create your method here public static void AverageScore(double score1, double score2, double score3, double score4) { double sum= score1+score2+score3+score4; double avgscore= sum/4; System.out.println("average of four judges is: "+avgscore); }
26th Jul 2022, 8:59 AM
madhu spurthi
madhu spurthi - avatar