Java Exercise

homework
java

#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

I am to compute the average using an expression to average the three to double (with decimal values) instead of an int, but I’m not sure where to start and where to place the expression?

<In what way does your code behave incorrectly? Include ALL error messages.>

There are also a few errors, but I’m not able to figure out what’s wrong with them.

``` import javax.swing.JOptionPane; public class TestAvg { public static void main(String[] args) { splash(); // Display a splash page; String input; // Temporary variable to hold String input from JOptionPane.showInputDialog method. int test1; // Hold the score for test 1. int test2; // Hold the score for test 2. int test3; // Hold the score for test 3. double average; // Holds the average calculated for the three tests.
  // Input the first test score
  input = JOptionPane.showInputDialog("What is the first test score? ");
  // Convert the input String to an int value and store it in the variable test1.
  test1 = Integer.parseInt(input);

  // Input the second test score
  input = JOptionPane.showInputDialog("What is the second test score? ");
  // Convert the input String to an int value and store it in the variable test2.
  test2 = Integer.parseInt(input);

  // Input the third test score
  input = JOptionPane.showInputDialog("What is the third test score? ");
  // Convert the input String to an int value and store it in the variable test3.
  test3 = Integer.parseInt(input);
  
  
  // ************************************************************************************************
  // Calculated the average of the three test scores and store the result in the average variable.
  // ************************************************************************************************
  
  
  // Display the three test scores and the average using String.format
  JOptionPane.showMessageDialog(null, "Test Information:\n"+
                                      "*********************\n"+
                                      String.format("Test 1: %3d\n",test1)+
                                      String.format("Test 2: %3d\n",test2)+
                                      String.format("Test 3: %3d\n",test3)+
                                      String.format("Average: %6.2f\n",average));      

}

// Introductory splash page
public static void splash() {
JOptionPane.showMessageDialog(null, “Test Average\n”+
"*********************\n"+
“This program will\n”+
“calculate the average\n”+
“of three test scores.”,
“Test Average”, JOptionPane.PLAIN_MESSAGE);
}
}

<do not remove the three backticks above>

#3

I am to compute the average using an expression to average the three to double (with decimal values) instead of an int, but I’m not sure where to start and where to place the expression?

<In what way does your code behave incorrectly? Include ALL error messages.>

There are also a few errors, but I’m not able to figure out what’s wrong with them.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.