Assignment #1
Due: Tues, May 27
Objective
Practice with Java input/output and basic coding, including some simple
arithmetic calculations.
Task
Create a program (Filename: Sales.java) that will
calculate the taxes and totals for a set of home purchases.
- The user is purchasing some items for a new home -- these will
include a TV, a washer/dryer set, a refrigerator, and a microwave.
- As you can see in the sample execution, you should ask the user for
the price of each of these items, in order. All of these prices will be
of type double
- After reading in the prices of the 4 items, ask the user also for
the local sales tax rate (as this may vary in different localities).
This will be entered as a percentage (also a double)
- After collecting all of the prices and tax rate, your program should
compute the subtotal, tax amount, and grand total for all of the
purchased items, then produce the output demonstrated in the sample
execution. Also note that:
- The user-entered prices should be displayed in default format
(i.e. you do not need to add any special formatting for these)
- The output of the sales tax rate should be displayed to 1 decimal
place
- The subtotal, tax, and total monetary amounts should be displayed
to 2 decimal places.
- See notes page on "Console I/O" for controlling decimal precision of
outputs
- Write your program so that the output looks EXACTLY like
the sample execution shown below (this means same wording, spacing,
and formatting of numbers)
- Note: The underlining in the sample execution is used to illustrate
what the user is typing in -- obviously the underlining will not
appear on the screen.
- You may assume that user input will be correct (i.e. numeric entries
and valid amounts)
General Requirements
- Use the Scanner class for keyboard input
- When you write source code, it should be readable and
well-documented.
See the link Style Guidelines
for further instructions on this topic
Sample run 1: (user input underlined)
Welcome to Sales!!
What was the price of the TV? 895.99
and what was the price of the washer/dryer? 724.50
and what was the price of the refrigerator? 1299.98
and what was the price of the microwave? 300
What is the local sales tax rate? 7.53
Prices:
TV = $ 895.99
Washer/Dryer = $ 724.5
Refrigerator = $ 1299.98
Microwave = $ 300.0
Your subtotal is $ 3220.47
And at a tax rate of 7.5 percent, this will add $ 242.50 in sales tax
for a grand total of $ 3462.97
Goodbye!!
Sample run 2: (user input underlined)
Welcome to Sales!!
What was the price of the TV? 1599.23
and what was the price of the washer/dryer? 942.79
and what was the price of the refrigerator? 1433.96
and what was the price of the microwave? 250.20
What is the local sales tax rate? 6.85
Prices:
TV = $ 1599.23
Washer/Dryer = $ 942.79
Refrigerator = $ 1433.96
Microwave = $ 250.2
Your subtotal is $ 4226.18
And at a tax rate of 6.9 percent, this will add $ 289.49 in sales tax
for a grand total of $ 4515.67
Goodbye!!
Compiling and testing
Compilation instructions for various environments are on the course web
site, under the heading "Compilers and Compiling Help". These include
instructions for building projects in both NetBeans and Eclipse, as well
as compiling from the command line on your CS account or from the DOS
prompt. If you use the CS account, I'd recommend using
linprog.cs.fsu.edu.
Make sure to test your program with a variety of different
inputs. The Sample Runs above are just that -- examples, only.
Never hard-code your programs to work for only one or two test cases.
Your program should work and calculate the correct results for any set
of valid inputs.
Submitting:
On the Blackboard web page link for this course, there is now a menu
item (below CGS 3416 Course Content) called "Assignments". Go here for
assignment submission links.
General Advice - always keep an untouched copy of your
finished homework files on your computer science account, or e-mail a
copy of your finished files (before the due date) to your own FSU e-mail
account. This way, these files will have a time-stamp which will show
when they were last worked on (a timestamp from the CS servers, or a
time stamp on the FSU e-mail) and will serve as a backup in case you
ever have problems with submitting files through the web site. My
advice is to do this for ALL programs.
For HW #1, submit only the following file:
Sales.java