Homework 1
- Write a program named Numbers.java which does the following:
- Print the program name and your name using System.out.println().
- Ask the user to input two integers (from the console or a dialog
box; see ConsoleString.java and
DialogString.java).
- Convert the user's input into integers using Integer.parseInt(string).
- Calculate and print the sum, product, difference, quotient and
modulus of the numbers (using the +, -, *, /, and % operators).
- For the quotient and average, you will need a floating point variable.
The other variables should be integers.
- Calculate and print the minimum and maximum of the numbers (using
the ternary if-then-else operator).
- if a and b are integers, the minimum is
a < b ? a : b
.
- Calculate and print the average of the numbers (using half the
sum).
- if a and b are integers, the average is
(a + b) / 2
.
- Compile, run, test, debug and document the program.
- You might find it easiest to calculate and print just one statistic at a
time (e.g. start with the sum, compile and test, then do the same with
product).
- Send the source code to the
instructor as an attachment in a message with subject java hw1.