CS 0401 Intermediate Programming

Assignment 1

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

 

Online: Friday, September 6, 2013

Due: All source (.java) and .class files submitted to the appropriate directory of the submission site by 11:59PM on Tuesday, September 24, 2013.

Late Due Date: 11:59PM on Thursday, September 26, 2013.

 

You are the owner of a small Internet store called Buy Stuff (or Buy it Not).  The only things you sell at Buy Stuff (or Buy it Not) are Yoda Action Figures, Star Wars Movie blue rays (at this point you only have the first movie, which, of course is Episode IV), and Death Star Lego Sets (you'd rather do fewer things and do them well).  Your prices are as follows:

 

Yoda Figures

$10.00 each

Star Wars Movie Blue Rays

$15.00 each

Death Star Lego Sets

$350.00 each

 

As an incentive to Star Wars aficionados to use the store, if a patron correctly answers a Star Wars trivia question, you give him/her a 10% discount on his/her bill (right now you have only two questions – see extra credit options for more possibilities).

 

You can ship orders via Regular Shipping (3-4 business days, $5.00 per $50.00 ordered), Express Shipping (overnight, $10.00 per $50.00 ordered) or Super Saver Shipping (7-10 business days, free).  The rates for shipping are rounded up, so that an order of $10.00 and an order of $50.00 shipped via Regular Shipping would both have a $5.00 shipping fee, but an order of $51.00 shipped via Regular Shipping would have a $10.00 shipping fee.

 

Your assignment is to write a Java program that will simulate transactions between you and some of your customers in a friendly, well-formatted way.  The program should:

 

1)    Ask if there is another customer to be waited on.  If so, continue; if not, quit the program [note: this is not the real way an Internet store would work, but we don't know GUIs yet and we are not really selling these things anyway, so we will do it as specified].

2)    Show the user a menu of the items for sale, and allow the user to update the totals for any of the items as many times as he/she wishes, until he/she wants to check out.  In other words, a user could choose to buy 3 Yoda Figures, then change his/her order to 2, then change it to 4, etc.  Clearly, a loop must be used to implement this.  This exchange should be well-formatted.  See a1out.txt for an example of how this will proceed.

3)    Once the user elects to check out, ask him/her one of the trivia questions (make up your own – do not use mine).  Pick your question randomly from the two choices (to do this see Math.random() and think a bit).  If the user gets the answer correct, note that he/she is entitled to a 10% discount.  See a1out.txt for an example.

4)    Ask the user what his/her shipping option is, clearly stating the possibilities.  See a1out.txt for an example.

5)    Tabulate the subtotal and show the itemized bill (with quantities and prices for each item) on the display.  See a1out.txt for an example.

6)    Show the discount (if applicable) and shipping fees, followed by the final total, all formatted nicely.  See a1out.txt for an example.

7)    Ask for the customer's credit card number and read it in.

8)    Go back to 1) and do it all again.

 

For some example runs, see file a1out.txt

Important Notes and Requirements:

-      Clearly there are a few places in your program where loops, if statements and possibly switch statements 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 runs 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 want 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 run your program directly from your submission directory without compiling it – if your program has to be recompiled you will lose points!   

-      If you are interested in doing some extra credit, you can enhance your program in many ways.  Note that some of these options are beyond what we have covered so far in lecture (which is why they are extra credit).  Also note that the maximum amount of extra credit is 10 overall assignment points.  Here are some examples, with the possible points for each:

>      Allow for more than one type of movie and/or action figure and/or Lego set in your store.  You must keep track of each item, so this will require additional variables and logic in your code (up to 5 pts).

>      Allow for more than two possible trivia question (so the user cannot memorize the answers).  The best way to do this is to have many questions (and answers) stored in a file and to select one randomly when the program is run (up to 10 pts).

>      Check the user's credit card to make sure it is not bad / stolen.  This should involve checking the number input by the user against a list of invalid credit cards in a file.  Only a valid credit card may be used (up to 10 pts).

>      Add some graphical output to your program using JOptionPane.  You should NOT use this for input, however, since a Scanner class is required (up to 5 pts).

-      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.  It should also have the same information in both the input and output.  For details on formatting numbers that represent money values, see ex6.java and ex6b.java.