Java Intro 5 – Shopping Cart
(Final 10% for Second Language 1)
In class, we created a shopping example that uses the Switch statement. Start with this file and save but create a new copy by going through the following process:
- File… Save As Assign5_Shopping.java.
- This will cause an error. You need to change the CLASS line in your code to read: public class Assign5_Shopping { Note that it will be case sensitive. It must match exactly what you typed for the file name.
Need a copy of the start file? You can find it by clicking here. Be sure to run the file before continuing to be sure it works.
The First 80% - add the following to the start file
- At the beginning of the program, ask the Shopper for his/her name and then welcome the shopper by name before continuing. Use your store’s name in this welcome. Welcome to Safeway Nick.
- Adapt the shopping cart to include 8 items that you can find at an actual online store and use realistic prices. Be sure to complete a DEEP TEST at this stage. Deep testing means that you have tried to purchase almost every product and have not run into any errors.
- Add GST tax to the total before listing the final total. The GST is currently 5%.
- Use the shoppers name when giving the final total such as “Thank you for shopping Cindy Jones, your total comes to $145.”
- Add extra, empty println statements where appropriate to make the output more readable.
- Place comments to end your Switch statement, while loop and main method. In other words, make sure all your ending braces are commented. For example: // end while loop
- Opening and closing braces { } should always line up.
- Everything inside a new brace should be indented further
The Last 20% - Part 2: A tough challenge
Update the stock of each item by subtracting what is ordered. If an order is for more than what you have in stock, you must cancel that part of the order and warn the user that there are only X left.
How?
- You will need to create a variable for EACH item that tracks how many you have in stock. (eg. shoesInStock = 10) For testing purposes, set all these variables to 8 to begin with. /1
- You will need to add an if…else statement inside each case statement that checks if the order size is greater than the amount in stock.
- If the order is greater than the amount in stock, give a warning and ask them to place that part of the order again. /1
- Else (in other words, the order size is ok) you subtract the order size from the amount in stock and keep going. /1