Assignment #2 - Chapter 3 Exercises

Due: Wednesday, May 28

From chapter 3, do programming exercises 3.2, 3.4, 3.5, 3.7 (starting on page 125), noting the added instructions below.
Filenames should be

To do these exercises, you will need the MyInput class that was used in lecture. and in HW 1. Paste this class into each of your own program files.

Extra Instructions

  1. For 3.2, after sorting, print out the results in the format shown below (sample output). Note that it is not enough to just print the items in the sorted order. Your program must store them in order, and then print the variables in the order: num1, num2, num3
  2. Combine 3.4 and 3.5 into one program, so that your program reads in a sequence of integers, stopping when the user types 0, and then reports on both how many positive and negative numbers there are (3.4) as well as the sum and average (3.5). (see sample output)
  3. For 3.7, print the patterns separately, but all in one program, not in separate programs

Sample Outputs

Sample user input is underlined.

Sample output for 3.2

  Programming Exercise 3.2 'Three number sorting'
  input integer 1 : 3
  input integer 2 : 2
  input integer 3 : 1
  Sorted : 1 <= 2 <= 3

Sample output for 3.4, 3.5

  Programming Exercise 3.4, 3.5 
  Input integer (0 to stop) 2
  Input integer (0 to stop) 4
  Input integer (0 to stop) -1
  Input integer (0 to stop) -5
  Input integer (0 to stop) 8
  Input integer (0 to stop) 0
  # of positives = 3
  # of negatives = 2
  Total = 8                 // corrected a typo here
  Average = 1.6

Compiling

Remember that the compile command is "javac", at the unix command prompt. Compile your code on program.cs.fsu.edu, and then run your programs with the "java" command.

Submitting:

Submit programs through the submission web page.