Overview
In this assignment you will write programs that get input data from the user (rather than having values declared as literals, as in the previous labs).
- Create, compile, and run short java programs
- Get user input using the Scanner class and System.in
LEGEND: Keyboard Screen
Task 0 Preliminaries
- You should have read Chapter chapter 2 sections 2.6 - 2.9 and section 2.13 - 2.14 before completing this lab.
- Create a folder titled lab21_lastname inside of k:\cosc181\labs\
- Open Eclipse and work within your project Chapter2. Create all of the Java classes for this lab inside of this project.
For all tasks in this lab, and for every lab in the future, make sure you do the following:
- Include jpeg screenshots of successful run(s)
- Include a standard header comment (you can use this java header template)
Task 1 Gaddis209b
- This task will be similar to Gaddis209a from Lab 2.0, but instead of assigning values for miles and gallons as literals within the program, we'll get the values from the user.
- You can reuse the code from Gaddis209a, but you don't want to overwrite it. Instead, you should work with a copy. Right-click on Gaddis209a.java and select Copy; then choose Edit | Paste ( or hit ctrl-v ). Eclipse will prompt you for a name, and you can enter Gaddis209b.
- Following the examples in 2.13, use a Scanner to get values for miles and gallons from the user. The value of milesPerGallon should of course still be calculated.
- Output should include all three values, formatted in an organized layout.
- Do several trial runs, entering different values for miles and gallons. Take a screenshot of each run to include with the lab.
Task 2 TestAverage
- As our programs start doing more interesting things, we'll actually name them by their functionality (rather than "GaddisXYZ"). Create a new Java main class named TestAverage.
- Complete task 10 from page 107 of the textbook.
- The formatting of input and output should be designed intentionally in a way that you feel is appropriate, organized, and attractive.
Below is an example -- yours need not look exactly like this. Design it the way that *you* like.
Welcome to the TestAverage calculator.
Please enter your score for exam 1: 78
Please enter your score for exam 2: 86
Please enter your score for exam 3: 92
With scores of 78, 86, and 92, your exam average is 85.3.
Thank you for using the TestAverage calculator!
Please send donations to starvingstudent@yahoo.com
Task 3 StringManipulator
- Practice manipulating strings by completing programming challenge 12 on page 107 of the text.
- Name your Java class StringManipulator.
Task 4 BillCalculator
This task is a modified version of programming challenge 13 on page 107 of the text.
- Create a Java main class named BillCalculator that asks the user for a total meal price and the number of people at the table, and then calculates and displays the following:
- the price entered (this isn't calculated, but should still be displayed in the output)
- the tax, calculated as 6.75% of the total price. Store this percentage (6.75) in a constant (read section 2.8)
- the tip, calculated at 15% of the bill plus sales tax. Save the tip percentage in a constant.
- the total bill, calculated as price + tax + tip.
- the amount each person should pay, calculated as total bill divided by number of people.
- Formatted output should include the original values input along with the values calculated.
Task 5 ZanyLibs
Based on task 16 in the textbook.
- Write a program that generates a "MadLibs" style story (but without violating Trademark law :-). The program should begin by displaying an introductory screen, and then ask the user for a variety of words, one at a time. The program finishes by displaying a story using the words that were entered.
- Use a Java main class named ZanyLibs
- Some ideas: you could ask the user for names, places, professions, kinds of animal, furniture, emotions, etc. You may also want to ask for specific forms of words, e.g., past-tense verb, verb with -ing, plural noun, adjective, etc.
- If you are not familiar with MadLibs (or even if you are), you might want to check out examples at:
Challenge Problems
