CSCI 1103 Lab02: Simple Input
- Due: 11:59pm Friday 9/22/2017
- Approximately 0.83% of total grade
- Submit to Canvas
- You may work with one partner on this lab but both partners must submit files and be physically present for Check-offs
- Lab exercises are open resource/open collaboration. You may freely discuss lab topics with other members of the class.
CODE DISTRIBUTION: lab02-code.zip
- Download the code distribution every lab
- See further setup instructions below
CHANGELOG: Empty
Table of Contents
1 Rationale
Completing this lab will teach some basic input/output skills. In
particular, basic methods to retrieve integers and doubles from the
user via the TextIO
class will be needed apprising students to the
basics of getting dynamic behavior from their programs.
Associated Reading
- Eck Chapter 2
- Chapter 2 discusses basic input using the
TextIO
class. Make sure to understand the use of theTextIO.getInt()
andTextIO.getDouble()
methods.
2 Download Lab Code and Setup
As in Lab01, download the code pack linked at the top of the page. Unzip this which will create a folder and create your files in that folder.
File | State | Notes |
---|---|---|
PARTNERS.txt | Edit | Fill in your name and the name of your partner in this text file |
TextIO.java | Provided | Allows easy input calls like TextIO.getInt() |
BurgersTests.java | Testing | Tests for problem 1 |
GratuityTests.java | Testing | Tests for problem 2 |
junit-1103.jar | Testing | For testing, don't try to edit this one |
Burgers.java | Create | Create this file for Problem 1 |
Gratuity.java | Create | Create this file for Problem 2 |
3 Problem 1: Burgers (TESTED)
Create a file named Burgers.java
which will print a welcome message
and prompt the user to enter some simple information. The overall
usage of the program will look like the following.
> javac Burgers.java > java Burgers Welcome to Good Burger, Home of the Good Burger May I take your order? ---------------------- Burgers: $2.55 Fries: $0.99 Tax: 7.2% ---------------------- Number of burgers: 4 Number of fries: 6 Total: $16.14 Tax: $1.1620800000000002 Grand Total: $17.30208
A few notes to save you trouble.
- The lines with a 4 and 6 above are input, stuff the user should type.
- Print the prices with fixed strings as in
System.out.println("Burgers: $2.55");
While this is generally a bad practice, printing numbers with a specific number of decimal places takes a bit of effort and will be covered later.
- Make sure to use the
TextIO.getInt()
method to retrieve integers from the user to calculate their order. - Don't worry about the messy output numbers at the end like
Tax: $1.1620800000000002
Printing with a specific number of decimal places will be covered soon but if you are curious about it now, ask your TA about the
System.out.printf( ... )
method.
4 Problem 2: Gratuity (TESTED)
Create a file named Gratuity.java
which will prompt the user for a
bill, the amount of gratuity (tip) they would like to leave, and the
number of people involved in the meal/outing. The program will then
print the overall total bill and the amount each person should
pay. Below are sample runs.
> java Gratuity Total bill (ex: 34.56): 100 Tip percentage (ex: 15.5): 5 Number of people (ex: 4): 1 Total with tip: $105.0 Each person pays: $105.0 > java Gratuity Total bill (ex: 34.56): 46.54 Tip percentage (ex: 15.5): 13.9 Number of people (ex: 4): 3 Total with tip: $53.00906 Each person pays: $17.669686666666667
Some notes
- You'll need to use the
TextIO.getDouble()
method here as some of the numbers are floating point values. - For the number of people, either an integer or a floating point number should work. Choose what you feel is appropriate.
- The tip is entered as a number but should be converted to a
fraction by dividing by 100.
- 7.5% tip should become 0.075
- 23.99% tip should become 0.2399
5 Getting Credit for this Lab
5.1 Demonstrate your code to Lab Staff (40%)
You should feel free at any time to get help from lab staff as you get stuck on the exercises.
By the end of the lab, make sure to demonstrate your code to a staff member. This will ensure that you receive full credit on the lab. Staff might ask you to
- Change what is printed
- Compile and run on the command line
- Run tests in DrJava or on the command line
- Show how to zip the folder with your programs in it
Be ready to do any or all of these.
5.2 Zip and Submit (60%)
Ensure that file PARTNERS.txt
has your name and the name of your
partner in it. This fill is located with the other Java files for the
lab and can be edited with DrJava.
Once your are confident your code is working, you are ready to submit. Ensure your folder has all of the required files. Create a zip archive of your lab folder and submit it to blackboard.
On Canvas:
- Click on the Assignments section
- Click on the appropriate link for this lab
- Scroll down to "Attach a File"
- Click "Browse My Computer"
- Select you Zip file and press OK