CS 0401 Intermediate Programming
Topics: Review of expressions, conditions, loops and I/O
Online: Saturday, September 6, 2014
Due: All source (.java) files and a completed Assignment Information Sheet zipped into a single file and submitted via the submission site by 11:59PM on Tuesday, September 23, 2014.
Late Due Date: 11:59PM on Thursday, September 25, 2014.
You are the owner of a small service station called Gas Gas and Gas. The only things you sell at Gas Gas and Gas are gasoline, propane fuel and burritos (you'd rather do fewer things and do them well). Your prices are as follows:
$3.75/gallon (regular); $4.00/gallon (plus). Gasoline is reduced by .10 per gallon for each $50 (rounded down) recorded on a customer's GasVantage card.
$20.00 for each 20 lb tank with an exchange. $35.00 for a tank without an exchange.
GasVantage card customers receive a 10% discount on propane.
$1.00/each for the first 5 (i.e. 1-5)
$0.90/each for the next 5 (i.e. 6-10)
$0.80/each for all additional burritos
For GasVantage customers, the chart above still applies, but the prices are $0.90, $0.80 and $0.70, respectively
If a patron's bill is $50.00 or more (after other discounts), you give him/her a 10% discount. This discount is given whether the patron has a GasVantage card or not. Finally, since you operate your store in Allegheny County, you need to add 7% tax to obtain the overall total (after the discount, if applicable).
Your assignment is to write a Java program that will simulate transactions between you and some of your customers. The program should:
1) Ask if there is another customer to be waited on. If so, continue; if not, quit the program.
2) Ask if the customer is a GasVantage customer or not. If the customer is a GasVantage customer, do the following:
a) Ask how much is recorded on his/her GasVantage card
b) Show him/her all of the applicable discounts for your products
3) Show the current customer a detailed menu including all products and prices and ask the customer (user) how many of each of the items (if any) he/she wants. Read in the amounts entered by the user (remember, the user does not have to buy every item or even any of the items -- your program should handle these special cases nicely). There are many different ways to do this but your approach should be reasonable and user-friendly.
4) Tabulate the subtotal (after GasVantage discounts but before 10% discount and tax) and show the itemized bill (with prices for each item) on the display. Note that you must sub-itemize the propane and the burritos so that the customer sees how much each one cost. See the example output in a1out.txt.
5) Tabulate the final total (counting 10% discount and tax) and show it on the display. Note that tax should be calculated after any discounts.
6) Show after the total the user's overall GasVantage savings for the purchase (do not show if user is not a GasVantage member)
7) Ask the customer for some money, input the amount, and give the customer his/her change (by showing it on the display). Do not allow the customer to underpay (i.e. do not accept an amount less than the total).
8) Go back to 1) and do it all again
For some example runs, see file a1out.txt
- Clearly there are a few places in your program where loops are required. We discussed several different looping constructs in lecture – choose one that is appropriate for the task at hand (more than one correct answer is possible).
- Be careful about handling special cases with regard to input. If the value the user enters is invalid your program should handle it in some reasonable way. However, you can assume that the type of the data the user enters will be valid (i.e. if you are expecting a number the user will not enter a non-numeric string). Some special cases are demonstrated in the example run shown in a1out.txt.
- Use the Scanner class for your input. We will see later how we can get input into our programs in other ways as well.
- Format your code nicely (indenting, etc) and be sure to use comments to explain your code where appropriate. Minimally you should have your name, course, section and a brief explanation at the beginning of your program.
- Your output should also be nicely formatted (make the user wants to run your program). In particular, your money values should be output in a well-formatted way. See the text and course handouts for ways to format money / decimal values in Java. Also see file a1out.txt for some example output.
- Be sure to electronically fill out and follow the directions on your Assignment Information Sheet, and to submit all materials following the correct submission guidelines. Note that the TA should be able to compile and run your program directly from your submission directory after unzipping your files. If there are any problems with your submission you will lose some points.
- If you are interested in doing some extra credit, you can enhance your program in many ways. Here are some examples:
- Allow the customer to buy gasoline by the gallon (ex. "fill it up with regular") or by the dollar amount (ex. "give me $10 of the plus"). In either case, you should display the gallons purchased and their cost.
- Allow the user the option of paying by credit card. This may involve inputting the card number (or some other simulated activity) and checking it against a list of invalid credit cards in a file. Only a valid credit card may be used.
- Instead of asking if a customer has a GasVantage card, ask the customer's name. Keep a file of all GasVantage card users and look up the customer in the file. Then automatically say if the customer is a GasVantage customer or not. You can also keep the balance on file so you do not have to ask the user how much is recorded on the card.
- Add some graphical output to your program using JOptionPane. You should NOT use this for input, however, since a Scanner class is required.
- If you have any other good ideas check with me to see if they qualify for extra credit. Be sure to mention any extra credit that you do on your Assignment Information Sheet.
- Be sure to look at the a1out.txt file for ideas about the look and feel of your program. Your program DOES NOT have to look exactly like the sample run, but it should have the same functionality and should be well-formatted. For details on formatting numbers that represent money values, see ex6.java.
 For example, if the user does not buy an item, the item should not even appear in the receipt. If a user does not buy any items, a receipt should not even be shown.