Solved-Assignment 1 -Solution

$35.00 $24.00

Submission note: Your .zip file should contain only .java files and your Assignment Information Sheet. There should be no .class files, no project files and no 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…

You’ll get a: . zip file solution

 

 
Categorys:

Description

5/5 – (2 votes)

Submission note: Your .zip file should contain only .java files and your Assignment Information Sheet. There should be no .class files, no project files and no 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 have long felt that there should be a Quidditch supply shop closer to Hogwarts (since, after all they have 4 teams to field there), so you have decided to open a small branch of Quality Quidditch Supplies in Hogsmeade. Your shop is very small so you stock only the most common, necessary items. For a full stock players will need to go to the main store in Diagon Alley.

Here are your items with prices:

House Pins 20 Knuts each, available in Gryffindor, Slytherin,
Hufflepuff and Ravenclaw

Quaffles 5 Sickles ( = 145 Knuts) each or
Box of 5 for 22 Sickles (= 638 Knuts)

Broomstick 2 Galleons (= 986 Knuts) each
Service Kits

For your best customers 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:

House Pins Purchase 10 or more pins and the price is reduced
to 18 Knuts each

Quaffles No discount on one but a box of 5 is now only 20
Sickles

Broomstick 31 Sickles (= 899 Knuts) each
Service Kits

1 of 3 10/2/19, 3:18 PM
https://web.archive.org/web/20180418141524/http://people.cs.pi…

MAR APR MAY ⍰
Go
23 captures 18 f
2017 2018 2019
26 Apr 2017 – 26 Mar 2019 ▾ About this capture

To accommodate the occasional muggle who may drop by, or to remind the absent-minded 3rd years of the currency, you also post the following sign prominently within your shop:

Note 1: We appreciate exact change!

Note 2: 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 (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. For simplicity (to allow the line to move more quickly), purchases will be restricted in the following ways:

a) Purchase of Quaffles will always be made by number of individual items. If a customer wishes to buy a box, he / she should specify 5 and your program should automatically detect that as a box of 5. Furthermore, for any number of Quaffles, K, you should automatically count as many boxes as you can before charging by the individual item. For example, if a customer asks for 12 Quaffles, this should be 2 boxes plus 2 single items.

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.

For an idea of how a customer transaction might proceed, see my sample output in a1out.txt.

4) Tabulate 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 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 720 Knuts and he/she pays with 2 Galleons (= 986 Knuts), then the change should be 9 Sickles and 5 Knuts. See how this process works in the example output in a1out.txt.

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

2 of 3 10/2/19, 3:18 PM
https://web.archive.org/web/20180418141524/http://people.cs.pi…

F MAR APR MAY ⍰
Go
I 23 captures 18 f
– 26 Apr 2017 – 26 Mar 2019 2017 2018 2019 ▾ About this capture
Clearly there are a few places in your program where loops are required. 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 runs 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. You should also explain any code / logic that is not obvious.

– 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. See file a1out.txt for some example output. There are several ways to format output in Java. See your text and online documentation for some help with this.

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

– Show after the total the user’s itemized overall savings for being in Dumbledore’s Army (i.e. for knowing the password). In other words, for a customer who knows the password you should calculate the bill both with and without the discounts, and the difference is the amount the Dumbledore’s Army member saved. Show this total but also the individual savings for each different item.

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

3 of 3 10/2/19, 3:18 PM