CS 0401 Intermediate Programming

Assignment 1

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


Online: Friday, September 11, 2015

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 Monday, September 28, 2015.

Late Due Date: 11:59PM on Wednesday, September 30, 2015.


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!



You are the owner of a small shop called Pies, Pies and Πs. The only things you sell at Pies, Pies and Πs are pizza, cherry pies and gold Π charms.  This enables customers to eat dinner and dessert, while also commemorating the world's most famous transcendental number (you thought about alternative names but decided that Pies, Pies and E's just didn't have the same ring to it).  Your prices are as follows:


Pizza [one size]


Plain: $10.000

Pepperoni: $12.00

Cherry Pies

$2.00 per slice or $10.00 for a whole pie [a whole pie has 6 slices]

Π Charms

$50.00 each [they are 14k gold]


To promote repeat business you have a Pie Card that customers can obtain free of charge.  However, by registering customers give you "Big Brother" access to their private information, so not everyone may want to participate.  Lucky Pie Card participants get the following discounts:



Pepperoni pizza for the price of plain

Cherry Pies

$0.25 off per slice or $2.00 off for a whole pie

Π Charms

10% off each charm


10% off over and above any other discounts if the overall order (after other discounts) is $100.00 or more


Since you operate your shop in Allegheny County, you need to add 7% tax to obtain the overall total (after the discounts, 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 has a Pie Card or not.  If the customer has a Pie Card, show him/her all of the applicable discounts for your products.

3)    Show the current customer a detailed menu including all products and prices (based on whether or not he/she has a Pie Card) and allow the customer (user) to choose as many of each item that he or she wishes (could be none).  A customer should be able to change his / her order before finalizing it so be sure to allow this in some way.  For simplicity (you like to keep things VERY simple), purchases will be restricted in the following ways:

a)     No "odd" pizza orders, such as double-pepperoni or half-pepperoni, are allowed.

b)     Purchase of fruit pies will always be made by number of slices.  If a customer wishes to buy an entire pie, he / she should specify 6 slices and your program should automatically detect that as a whole pie.  Furthermore, for any number of slices, K, you should automatically count as many whole pies as you can before charging by the slice.  For example, if a customer asks for 22 slices of pie, this should be 3 whole pies plus 4 slices.

c)     Customers will not be able to get a new Pie Card during normal purchases.  They can only get a Pie Card online via a different program (so it is not your problem here!).  Note also that for this program you are not storing any information about Pie Card customers – you take them at their word that they have the card when they come into your store.

4)    Tabulate the subtotal (after Pie Card discounts but before tax) and show the itemized bill (with unit and subtotal prices for each item) on the display. See the example output in a1out.txt.

5)    Tabulate the final total counting tax and show it on the display.  Note that tax should be calculated after any discounts.

6)    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).

7)    Go back to 1) and do it all again


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 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 that will be put online.

-      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:

-      If adding an extra slice of pie would either be the same or a lower price for the customer, recommend that he or she add another slice.  Think about the situations for which this would occur (both regular and with the Pie Card).

-      Show after the total the user's overall Pie Card savings for the purchase (do not show if user is not a Pie Card holder).  In other words, for a Pie Card customer you should calculate the bill both with and without the Pie Card Discounts, and the difference is the amount the Pie Card holder saved.

-      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 Pie Card, ask the customer's name.  Keep a file of all Pie Card users and look up the customer in the file.  Then automatically say if the customer is Pie Card customer or not.

-      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.