Object Oriented Programming 1 – JAVA PROG10082
Assignment 3 1
Assignment 3 Selections
Description
This lab is based on the material studied in week 4 and 7, including the exercises done in class.
This assignment is to be done individually; you are not allowed to work on this assignment with anyone.
See also the Academic Integrity Policy and the Assignment and Exam Policies
Question 1
An underground parking garage requires a program that allows clerks to calculate and display a bill for customer
parking charges. A customer is charged when they leave the garage, and the amount charged is based on a few
different factors. Some customers own a special membership card if they work in the building above the garage,
so they are charged a special hourly rate of only $2 per hour. Customers without the card are charged $3 per
hour, unless they park for more than 12 hours, in which case they are charged only $2.50 per hour. Partial hours
are rounded up to the next hour, so if a customer parks for 5.2 hours, the charge is calculated for 6 hours. HINT:
chargeable hours = Math.ceil(actual hours). The maximum charge allowed is $100, so if a customer’s total
charges are more than $100, they will be charged exactly $100.
To retrieve the input for the membership card, you have a few choices. For example, you could assign numeric
values for member and non-members and have the user enter an integer:
Membership Status (1 = member, 0 = non-member):
Then you simply need to check the user-entered value to see if the customer is a member or not.
You could also do this with Strings/characters, for example:
Is customer a member (Y/N)?
This would require a bit more advanced coding to grab a single character from the user and check that it’s ‘Y’ for
member. (Hint: check in-class exercise coding solutions)
Sample program interaction (prompts in black, user input in blue) with output at the end in green. These colours
are here for demonstration only; your program does not need to display in colour):
Enter time parked: 5.5
Membership Status (1 = member, 0 = non-member): 1
Hourly Rate: $ 2.00
Chargeable Hours: 6.00
Total Charges: $ 12.00
Note the formatting above: All values are formatted to 2 decimal places and numbers are aligned right-justified
at the decimal point. Your output must appear in the exact same format as shown above.
Object Oriented Programming 1 – JAVA PROG10082
Assignment 3 2
All literal numeric values in your program must be defined as constants. Be sure to use well-defined and
appropriate names for all of your constants and variables.
Here is an IPO chart to help you understand the program’s requirements:
Inputs: – number of hours parked
- whether or not the customer has a membership card
Processing: – determine hourly rate based on membership status and hours parked - chargeable hours = ceiling of actual hours parked
- total charges = hourly rate * chargeable hours
Outputs: – hourly rate - chargeable hours
- total charges
Don’t forget to include proper documentation describing your code statements!
Question 2
Write a program that plays a random number guessing game. Generate a random number between 1 and 100
(Math.random() * 100 + 1) and repeatedly ask the user to guess what the number is. Display messages to help
the user: if the number they guessed is lower than the correct number, or if the number they guessed is higher
than the correct number, say so. Eventually, the user will guess the correct number. Once this happens, ask the
user if they’d like to play the game again. If they say yes, do the whole game again. If they say no, display a
“Thanks for playing” message. Allow the user to give up at any time by ending a negative number for their guess
(display the actual number after the user gives up).
Numbers must all be integers. “Play again?” input must be character (char) type.
Sample program interaction (prompts in black, user input in blue) with output at the end in green. These colours
are here for demonstration only; your program does not need to display in colour):
I’m thinking of a number between 1 and 100. What is it?
Guess: 50 Too high. Guess: 25 Too high.
Guess: 15 Too low.
Guess: 20
Too low. Guess: 23
You got it!
Play again? (Y/N) Y
I’m thinking of a number between 1 and 100.
What is it?
Object Oriented Programming 1 – JAVA PROG10082
Assignment 3 3
Guess: 50 Too low.
Guess: 75
Too high. Guess: 65
Too high.
Guess: 55 Too low. Guess: 60
Too high. Guess: 57 Too low.
Guess: 58 Too low. Guess: 59
You got it!
Play again? (Y/N)
n
Thanks for playing!
• First, get one game running
• Next, get more than one game running
• At last, add more option, i.e. allow user to give up by input a negative number
Step 1: I’m thinking of a number between 1 and 100. What is it?
Guess: 50
Too high! Guess: 25 Too low!
Guess: 35 Too low! Guess: 40
Too high! Guess: 37 Too low!
Guess: 38 Too low!
Guess: 39
You got it!
Thanks for playing! Step 2: I’m thinking of a number between 1 and 100.
What is it? Guess: 50 Too high.
Guess: 25
Too high. Guess: 15
Too low.
Guess: 20 Too low.
Object Oriented Programming 1 – JAVA PROG10082
Assignment 3 4
Guess: 23 You got it!
Play again? (Y/N) y
I’m thinking of a number between 1 and 100. What is it? Guess: 50
Too low. Guess: 75 Too high.
Guess: 65 Too high. Guess: 55
Too low. Guess: 60
Too high.
Guess: 57 Too low.
Guess: 58
Too low. Guess: 59
You got it!
Play again? (Y/N)
n
Thanks for playing!
Step 3: I’m thinking of a number between 1 and 100. What is it?
Guess: 50
Too high. Guess: 25 Too low. Guess: 35 Too low. Guess: 45 Too high. Guess: 40 Too low.
Guess: -1 You gave up!
Your number was 42.
Submission
All submissions are expected to abide by the Submission Standards and all code is expected to abide by the
Coding Standards for this Course. Before the deadline specified on Slate.
You are to submit 3 files for each questions:
- Your Java source code for your program.
- A text or word processed document containing all of your source code.
- Screenshot a screenshot of your code & console display (.jpg file)
Object Oriented Programming 1 – JAVA PROG10082
Assignment 3 5 - Source Code File:
• Submit only the source code file (.java) for your program. DO NOT submit anything else or you will
lose marks. DO NOT submit .class files, DO NOT submit your editor’s backup files (e.g. .java~
or .bak), etc.
• DO NOT compress your files by using ZIP or RAR
• The name of your file should be YourfirstnameYourlastnameAssignment#Q#.java, For example,
JohnSmithAssignment1Q1.java. - Document of Source:
You must also copy and paste all of your source code into a plain text file (e.g. .TXT), or Word document
(e.g. .DOC/.DOCX). Submit this document in addition to your source code java file. This is used for SLATE’s
originality checker.
Submit your assignment to where you download this instruction in SLATE, that is
Slate/Assessment/Assignment/Assignment 3, click [add a file].
IMPORTANT: Failure to follow any of the instructions above will result in penalties or a grade of 0.
Evaluation
Your submission will be evaluated based on the following criteria:
• Efficient Code: Program uses variables where and only when necessary; program doesn’t define
variables that are never used, nor does it use too many variables for unnecessary tasks; program logic is
written concisely and is not cluttered with unnecessary tasks.
• Functionality: program functions according to specifications – input and output is done on the console
using the techniques discussed in class; variables are used to store user inputs until they are needed for
output.
• Programming Style: proper indentation and spacing, use of comments/documentation; all identifiers are
descriptive and valid; variables are defined with appropriate types and converted when required.
• Other: all instructions regarding submissions and program specifications have been followed;
submission was completed and submitted as requested in a timely fashion; techniques discussed in class
have been used.
Copyright:
This work is the intellectual property of Wendi Jollymore & Yan Cui. Any further copying and
distribution outside of class must be within the copyright law. Posting to commercial sites for profit is
prohibited.
© Wendi Jollymore & Yan Cui, et al