Programming Assignment 03
Due: Week of Sep. 12 in lab
-
Problem: Write a java program to help teach multiplication to children.
Generate two random numbers
a
andb
between 0 and 10. Prompt the user for the answer toa*b
. Report whether their answer is correct. Name the file and programch1sec3prob00.java
. Worth 20pts. Use standard input to get the integers from the user. Assume the user provides valid input.
Examples:-
Input: $ java ch1sec3prob00
Output: (user will enter the value after the question...) What is 5*6? 10
That is incorrect. The correct answer is 30. -
Input: $ java ch1sec3prob00
Output: (user will enter the value after the question...) What is 6*6? 36
That is correct.
-
-
Problem 1.3.5 on page 77 of your book. Name the file and program
ch1sec3prob05.java
. Worth 20pts. Output good error messages for incorrect input values and not providing the correct amount of inputs to the program; output a single value otherwise. You do not need to handleNumberFormatExceptions
.
Examples:-
Input: $ java ch1sec3prob05 30 10
Output: 21.24829325564962
-
Input: $ java ch1sec3prob05 30
Output: Error you did not give only temperature and wind speed.
-
Input: $ java ch1sec3prob05 60 2
Output: Error input was invalid. Temperature should be between -50 and 50. Windspeed should be between 3 and 120.
-
-
Problem 1.3.28 on page 81 of your book. Name the file and program
ch1sec3prob28.java
. Worth 40pts. Input from the command line and Output a single number. Hint: This code requires a loop.
Examples:-
Input: $ java ch1sec3prob28 48 18
Output: 6
-
Input: $ java ch1sec3prob28 18 48
Output: 6
-
-
Problem 1.3.30 on page 81 of your book. Name the file and program
ch1sec3prob30.java. Worth 20pts. Output a list of numbers each on their own line
as described. Do not use
Math.pow
, it is not appropriate for integers, asdouble
s represent a different range of values inaccurately. Hint: Stop your loop 1 iteration early to avoid "integer overflow".
Examples:-
Input: $ java ch1sec3prob30 42
Output: 1
42
1764
74088
3111696
130691232
5489031744
230539333248
9682651996416
406671383849472
17080198121677824
717368321110468608
-
-
Bonus. Write a bank account tracker that starts
with $0 in the bank account. Prompt the user to alter their account
(positive numbers will be deposits and negative numbers are
withdrawals/charges). If they enter 0, quit the program. Worth 20pts.
Display all money values nicely. Your program must handle incorrect input as
well. Name your file and program
ch1sec3bonus.java
. Use standard input to get the alterations from the user.
Examples:-
Input: $ java ch1sec3bonus
Output: (user will enter the value after the questions...) Your account has $0.00.
Enter a positive value for a deposit and a negative value for a withdrawal: 23
Your account has $23.00.
Enter a positive value for a deposit and a negative value for a withdrawal: -5
Your account has $18.00.
Enter a positive value for a deposit and a negative value for a withdrawal: -5h
Error please enter a valid deposit/withdrawal: 0
-
Grading
Each assignment is graded out of 100% based on a combination of the criteria listed in the assignment description and programming style (e.g., good comments and naming) -- following instructions is extremely important in computer science, train yourself to think like the computer; programming style is important to be able to communicate your solutions to another programmer; both of which you are graded upon.
Specific instructions. Failure to do these steps will result in a loss of points.
- Name each file and program as listed in the instructions.
- Name all variables descriptively.
- Indent all programs appropriately.
- Use comments to help explain the steps and logic of your program.
- The top of your program should have a comment block where the first line
is your name, second line is your section, and third line is a description
of your java program.
//Name: Jory Denny
//Section: 00
//This program debates Batman vs Superman!
Turn in instructions. Each programming assignment is to be turned in before your lab section. You will turn in a soft copy of the assignment (.java or .zip for multiple java files) through blackboard. You will also turn in a hard copy of the assignment in your lab section with a signed coverpage (each program should start a new page of the hard copy).
If there are any discrepencies in grades please see the instructor during his office hours or by appointment (do not discuss with the lab assistants or graders).