Lab 4
Start Now

Overview

Two independent programs must be created. The programs provide experience with loop constructs in Java. One program asks the user to enter a positive integer and displays all of the prime numbers between 1 and the number entered. The other program presents the user with randomly generated addition problems and continues until the user answers incorrectly. The program then displays the number of correctly answered addition problems.

Prime Details

This program must ask the user to enter a positive integer and then display all of the prime numbers between 1 and the number entered.

  • The program must be created in a class named Prime that is in a package named the same as your MSOE username.
  • The program must use the console to communicate with the user.
  • A number, x is considered prime if the result of x divided by every integer between 2 and x/2 has a non-zero remainder.
  • The program should display "Invalid integer value entered" and exit if the user enters an invalid integer.
  • The program may crash if the user enters anything other than an integer value.

Sample user interaction:

Please enter a positive integer: 8

Prime numbers between 1 and 8:
2
3
5
7

Quiz Details

This program must repeatedly present the user with randomly generated addition problems until the user answers incorrectly. The program then displays the number of correctly answered addition problems.

  • The program must be created in a class named AdditionQuiz that is in a package named the same as your MSOE username.
  • The addends for the addition problem must be between zero and ten. E.g., 3 + 7
  • A random integer value between zero and ten may be obtained using the following code:
      java.util.Random generator = new java.util.Random();
      int randomValue = generator.nextInt(10);
    
  • The program must use pop-up windows to communicate with the user.
  • When the user enters an incorrect answer, the program must display the number of equations for which the user answer correctly.
  • The program may crash if the user cancels the input dialog window, enters a non-integer value or does not enter any characters.
    (Optional) Alternatively, the program may re-prompt the user to enter a number.
  • (Optional) The program may also display the average number of seconds required for the user to answer the questions. Hint: System.currentTimeMillis() returns the current time in milliseconds.

Lab Deliverables

See your professor's instructions for details on submission guidelines and due dates.
Dr. Dennis' class: See Blackboard
See Dr. Rebenistch for instructions
Dr. Taylor's class: See below
See Prof. Ung for instructions
Dr. Yoder's submission instructions
If you have any questions, consult your instructor.

Acknowledgement

This laboratory assignment was developed by Dr. Chris Taylor.

Tuesday, 16-Feb-2016 09:54:10 CST