Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need help adding Displays to a program

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Need help adding Displays to a program

    The main part of the program is to calculate average test scores, which I have done here:

    import java.util.Scanner; // Needed for the Scanner class

    /**
    This program demonstrates a user controlled loop.
    */

    public class TestAverage
    {
    public static void main(String[] args)
    {
    int score1, score2, score3; // Three test scores
    double average; // Average test score
    char repeat; // To hold 'y' or 'n'
    String input; // To hold input

    System.out.println("This program calculates the " +
    "average of three test scores.");

    // Create a Scanner object for keyboard input.
    Scanner keyboard = new Scanner(System.in);

    // Get as many sets of test scores as the user would like.
    do
    {
    // Get the first test score from the set.
    System.out.print("Enter score #1: ");
    score1 = keyboard.nextInt();

    // Get the second test score from the set.
    System.out.print("Enter score #2: ");
    score2 = keyboard.nextInt();

    // Get the third test score from the set.
    System.out.print("Enter score #3: ");
    score3 = keyboard.nextInt();

    // Consume the remaining newline.
    keyboard.nextLine();

    // Calculate and print the average test score.
    average = (score1 + score2 + score3) / 3.0;
    System.out.println("The average is " + average);
    System.out.println(); // Prints a blank line

    // Does you want to average another set?
    System.out.println("Do you want to average " +
    "more test scores?");
    System.out.print("Enter Y for yes or N for no: ");
    input = keyboard.nextLine(); // Read a line.
    repeat = input.charAt(0); // Get the first char.

    } while (repeat == 'Y' || repeat == 'y');
    }
    }




    However, I am lost on the requirement to use a bool type variable to "check for proper states."
    First, I need a H (for Help) option to invoke a function named "help()" which will display a help screen that says "How To Interact WIth This Program?"..the help screen is supposed to remain up until the user strikes any key.
    Second I need an "S" (for SetParams) option that will prompt for the number of students and quizzes (no more than 50 students & no more than 5 quizzes)
    Third, i need an F (for FillArray) option to be invoked after the S option. To enter a student ID made of 5 digits for each student incrementing by 1..Once completed, to display "Data Entry Completed."
    Lastly I need a D (for DisplayResults) to be invoked after the F option. Where the student ID scores and averages will be displayed.


    Even if you cant help with all of this, any small contribution that I can use as a guide is greatly appreciated! Thank you in advance


  2. #2
    Member
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    54
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: Need help adding Displays to a program

    What have you tried to code each of the 4 additional features of a help option, setParams option, FillArray option and DisplayResults option? I'll give a very rough outline of the logic and you may have to add smaller steps. Also, there are different types of JOptionPane, so you'll have to figure out which one is appropriate for you to use.

    Help option:
    1) Create a JOptionPane or JDialog
    2) Use a KeyListener/KeyAdapter and register it accordingly (you don't need to have both a KeyListener and KeyAdapter, only one).

    setParams option:
    1) Create a JOptionPane that gets the user input or read directly from the console (depends on the instructions you were given)
    2) Check to make sure the input does not exceed 50 students and 5 quizzes, otherwise ask again for input

    FillArray option:
    1) Create a JOptionPane that gets the user input or read directly from the console (depends on the instructions you were given)
    2) Check to make sure the student ID is made up of exactly 5 digits. You can either check to see whether each ID increments by 1 (which I wouldn't do) or increment by 1 five times based on the entered ID.
    3) Since the name is "FillArray", fill whatever the array is.

    DisplayResults option:
    1) Override a toString() : String method or create a similar one for your data types.
    2) Display either in a JOptionPane that shows output dialog, JDialog or display to the console.

  3. The Following User Says Thank You to SunshineInABag For This Useful Post:

    Lacie1013 (April 24th, 2013)

Similar Threads

  1. File Text displays jumbled in JList
    By gammaman in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: April 27th, 2012, 01:59 PM
  2. This java program is adding up in a negative way....
    By seaofFire in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 23rd, 2012, 04:58 PM
  3. Adding sound to program.
    By Archibold9 in forum What's Wrong With My Code?
    Replies: 32
    Last Post: December 21st, 2011, 02:28 PM
  4. How do you write a Java program that displays your initials?
    By kala99 in forum Java Theory & Questions
    Replies: 3
    Last Post: November 30th, 2011, 02:12 PM
  5. use multiple gui displays
    By jonwymore in forum AWT / Java Swing
    Replies: 1
    Last Post: November 19th, 2010, 10:11 AM