r/codehs • u/petite-mushroom • Aug 27 '23
1.5.8 Test Score Calculator
Hello! Can someone please tell me what is wrong about this code?
import java.util.Scanner;
public class Scores
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Please enter the first test name: ");
String testOneName = input.nextLine();
System.out.print("Please enter the first test score: ");
double testOneScore = input.nextDouble();
input.nextLine();
System.out.print("Please enter the second test name: ");
String testTwoName = input.nextLine();
System.out.print("Please enter the second test score: ");
double testTwoScore = input.nextDouble();
input.nextLine();
System.out.print("Please enter the third test name: ");
String testThreeName = input.nextLine();
System.out.print("Please enter the third test score: ");
double testThreeScore = input.nextDouble();
input.nextLine();
double average = (testOneScore+testTwoScore+testThreeScore)/3;
System.out.print("Your average score is: ");
System.out.print(average);
}
}
2
u/5oco Aug 27 '23
Is there an error message? Does it print incorrect data? Do you know how to post screenshots?
2
u/RNG_DiNo Sep 21 '23
Fixed: codehs's detector needs the average to return to the next line.
Scanner input = new Scanner(System.in);
System.out.print("Please enter the first test name: ");
String testOneName = input.nextLine();
System.out.println("Please enter the first test score: ");
double testOneScore = input.nextDouble();
input.nextLine();
System.out.print("Please enter the second test name: ");
String testTwoName = input.nextLine();
System.out.println("Please enter the second test score: ");
double testTwoScore = input.nextDouble();
input.nextLine();
System.out.print("Please enter the third test name: ");
String testThreeName = input.nextLine();
System.out.println("Please enter the third test score: ");
double testThreeScore = input.nextDouble();
input.nextLine();
double average = (testOneScore + testTwoScore + testThreeScore) / 3;
System.out.println("Your average score is: " + average);
1
u/PuzzleheadedHealth25 Sep 10 '23
yea, i am struggling with this one too.
1
u/Psychological_Fly282 Sep 17 '23
Try changing print to println that might work