Assignment #3

Due: Tues, June 10

Objective

This assignment will involve practice with loops.

Task

Write the following programs, each in a separate file. Filenames should be: (Make sure to use these exact filenames).

Exercise 1

Filename: Numbers.java

Write a program that will allow the user to enter a set of integers (as many as they want), then prints out a summary of information, as follows:

Sample Runs

(user input is underlined, to distinguish it from output)

Sample Run 1

  Input integer (0 to stop): 12
  Input integer (0 to stop): 4
  Input integer (0 to stop): -1
  Input integer (0 to stop): -5
  Input integer (0 to stop): 18
  Input integer (0 to stop): 0

  # of positives = 3
  # of negatives = 2
  Sum = 28
  Average = 5.60

Sample Run 2

  Input integer (0 to stop): 4
  Input integer (0 to stop): 8
  Input integer (0 to stop): 24
  Input integer (0 to stop): 94
  Input integer (0 to stop): -1
  Input integer (0 to stop): 43
  Input integer (0 to stop): 13
  Input integer (0 to stop): 0

  # of positives = 6
  # of negatives = 1
  Sum = 185
  Average = 26.43

Exercise 2

Filename: GuessingGame.java

Write a program that plays a Hi-Lo guessing game with the user. It should work as follows:

Sample Runs

(user input is underlined, to distinguish it from output)

Sample Run 1

Enter a guess (1-100): 50
  You guessed too low

Enter a guess (1-100): 70
  You guessed too low

Enter a guess (1-100): 80
  You guessed too low

Enter a guess (1-100): 90
  You guessed too low

Enter a guess (1-100): 97
  You guessed too high

Enter a guess (1-100): 94
  You guessed too low

Enter a guess (1-100): 95
  You guessed too low

Enter a guess (1-100): 96
  Correct!  You guessed the number in 8 guesses.

Sample Run 2

Enter a guess (1-100): 50
  You guessed too low

Enter a guess (1-100): 80
  You guessed too high

Enter a guess (1-100): 60
  You guessed too high

Enter a guess (1-100): 55
  You guessed too high

Enter a guess (1-100): 53
  You guessed too low

Enter a guess (1-100): 54
  Correct!  You guessed the number in 6 guesses.

Requirements for both programs


Submitting:

Submit the files through the Assignment 3 Blackboard link. Make sure you attach BOTH files before you click Submit:
  Numbers.java
  GuessingGame.java