CS 0401 Intermediate Programming

Assignment 1

Topics: Review of expressions, conditions, loops and I/O

 

Online: Wednesday, May 20, 2020

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 Friday, June 5, 2020.

Late Due Date: 11:59PM on Monday, June 8, 2020.

 

Submission note:  Your .zip file should contain only .java files and your Assignment Information Sheet.  There should be no project files or project subdirectories in the .zip file.  Also, your TA must be able to compile your program from the command line using the javac command.  Test your files to make sure this will work (especially if you use an IDE such as NetBeans for development).  If the TA cannot compile your program you will receive minimal credit!

 

 

After passing your OWLs and NEWTs (with a grade of "Outstanding" in "Defence Against the Dark Arts") but discovering that there are currently no openings for Aurors, you decide to bide your time by opening a small Honeydukes franchise (really just a food cart) in Diagon Alley, called "A Little Honey".  Since your cart is small you have a very limited menu, consisting only of Acid Pops, Pumpkin Pasties, and Bertie Bott's Every Flavour Beans.  However, since these are all popular items you hope to earn enough Galleons to get by while you wait for an Auror position to become available.

 

Your prices are as follows:

 

Acid Pops

Single: 12 Knuts

Bag of 5: 2 Sickles (= 58 Knuts)

Pumpkin Pasties

4 Sickles (= 116 Knuts) each

Every Flavour Beans

Small Bag: 50 Knuts

Large Bag: 70 Knuts

 

For your best customers (in your "Honeys Dukes" club) you have a secret password that enables them to get discounts on your products.  Customers who know the password (they get two tries to guess it) get the following discounted prices:

 

Acid Pops

Single: 11 Knuts

Bag of 5: 50 Knuts

Pumpkin Pasties

100 Knuts each

Every Flavour Beans

Small Bag: No discount

Large Bag: 2 Sickles (= 58 Knuts)

Overall

10% off over and above any other discounts if the overall order (after other discounts) is 10 Sickles or more, rounded to the nearest Knut

 

To accommodate the occasional muggle (or first year who may have grown up in a muggle household) who may drop by, you also post the following currency sign on your cart:

 

Note 1: We prefer exact change (but will make change if necessary)!

 

Note 2: No more than 50 galleons are kept in the cart (funds are transported to Gringotts on a daily basis)

 

Note 3: Recall our currency options:

            29 Knuts == 1 Sickle

            17 Sickles == 1 Galleon == 493 Knuts

 

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 the customer for the secret password to see if he/ she is in the "Honeys Dukes" club (pick any password that you would like – don't worry about encryption).  If the customer knows the password, show him/her the discounted prices; otherwise show the customer the regular price list.

3)     Allow the customer to order items from the menu.  This process should be iterative, with the customer possibly changing his / her order until finalizing it prior to checking out.  This includes possibly changing something that has previously been ordered (ex. "putting something back"). During the ordering process, the customer should have an option to see the price list (in case he/she forgets the prices), and to see the current itemized subtotal (to keep track of how much he/she has already spent on each item).  For simplicity (to allow the line to move more quickly), purchases will be restricted in the following ways:

a)     Purchase of Acid Pops will always be made by number of pops.  If a customer wishes to buy a bag, he / she should specify 5 pops and your program should automatically detect that as a bag of 5.  Furthermore, for any number of pops, K, you should automatically count as many whole bags as you can before charging by the pop.  For example, if a customer asks for 13 Acid Pops, this should be 2 bags plus 3 single pops.

b)     Discount passwords will be sent to customers either via owl or perhaps floo powder transmissions.  In any case, customers will not be given the password during store transactions – they must already know the password when they are waited on.

Before an order for a specific item is updated, the previous order for that item should be shown to the user.  The idea here is that the customer is changing his / her order so you should show the previous order before updating it to the new one. For an idea of how a customer transaction might proceed, see my sample output in a1out.txt.

4)     Tabulate the subtotal and then the total (don't forget the 10% overall discount if it applies) and show the itemized bill (with unit and subtotal prices for each item) on the display.  Only show items on the bill that have actually been purchased. See the example output in a1out.txt.

5)     Ask the customer for some money, input the amount, and give the customer his/her change (by showing it on the display).  The payment should be an iterative process – the customer enters an amount in Knuts, Sickles or Galleons (only one currency at a time) and the amount is added to the total.  The loop should continue until the total value entered equals or exceeds the total bill.   If change is given, you will always give the minimum number of coins back (so you give larger currency before smaller currency).  For example, if a customer's total bill is 600 Knuts and he/she pays with 2 Galleons (= 986 Knuts), then the change should be 13 Sickles and 9 Knuts (which add up to 386 Knuts).  See how this process works in the example output in a1out.txt.

6)     Go back to 1) and do it all again (i.e. you should repeat this process for an arbitrary number of customers)

 

For some example runs, see file a1out.txt

 

Important Notes:

       Clearly there are a few places in your program where loops are required.  We discussed (or will discuss) several different looping constructs in lecture – choose one that is appropriate for the task at hand (more than one correct answer is possible).

       You will also need to do some math to calculate totals and discounts and to convert currency.  Think carefully about how you can do these things in relatively simple ways.

       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 that will be put online. Make sure you can handle all of these situations properly.

       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 itemized bill must be presented in a nice, readable way, with the individual subtotals lined up beneath each other.  There are several ways to format output in Java.  See your text and online documentation for some help with this.  One suggestion is to use printf() – this is demonstrated in your text.  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.  If you do very good extra work you can earn up to 10% total extra credit on this assignment.  Here are some examples:

®   Show after the total the user's overall savings for being in the Honeys Dukes club (i.e. for knowing the password).  In other words, for a customer who knows the password you should calculate and show the bill both with and without the discounts, and the difference is the amount the Honeys Dukes member saved.  For full extra credit you should itemize the savings (i.e. show how much was saved for each item).

®   Keep track of customers individually and track them as they make transactions in the store.  Note that to do this you will need one or more files and you will have to require customers to log into the site.  Note: This option will be a lot of work and most definitely much more work than the 10% extra credit that you can earn from it.  You have been warned!

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.