CS 157 Spring 2003               Assignment 11 – Working inside a class, some GUI, and some previous topics 

100 points

 

Assigned: 04/09/2003

Due: 04/16/2003 (at the start of class – as will be the normal case)

 

Pre-Lab (Do Before Lab):  Bring an empty (or nearly empty) disk. Plan out sequence of statements needed for all code to be created – in PretzelStore class, and main. This is another step up in complexity. Plan ahead!!

 

Main Assignment:

Pretzel Palace has decided that they’d like you to help out with running their stores. I have provided most of a class definition for PretzelStore (on my WWW page), which will keep track of inventory, number of pretzels sold, price for pretzels, and profit margin, and enable selling pretzels. You need to provide: methods getCurrInv, getSold, and getTotalSales. The first two are inspectors, the latter one provides a simple calculation.  You will also write a main function that simulates customers coming to the store, “Write code for main that asks the user for the number of pretzels in initial inventory, the sales price for pretzels, the profit margin for pretzels, and the number of customers to process; then processes customers until all customers have been processed, and for each one, ask the customer for the number of pretzels, and sell them if you can. (If there are not enough pretzels for the customer’s order, they should be given a choice as to whether they want to accept a partial order. A customer who answers No cannot be served and is skipped. Either way, we then order a new batch of pretzels (to be available for the next customer after the current one) and we move on to the next customer.  After all customers have been processed, (and as many customers have been served as possible), report the number of customers actually served, the number of pretzels sold, the dollar amount of the pretzel sales, and the total profits for the day.”  The latter three can be obtained from the PretzelStore object, do not keep track of them in main while working with customers!!! If you do, you are avoiding part of the point of the assignment. Significant points would be taken off! 

Your interaction with the customer should be via dialog boxes, using static methods from RedmondMsgIn157 and RedmondMsgOut See the sample interaction below for a textual replay of what happened in one example.  RedmondMsgOut provides a display method which puts out a dialog box and then echos to normal output so it can still be seen later.

 

·        In using the readValidInt etc methods in RedmondMsgIn157, you automatically get validation (force the initial inventory to be 1-1000, the sales price to be 0.10-2.00, the profit margin to be 0.01-1.90, and the number of customers to be 1-100). 

·        Use doubles for anything that COULD be a non-whole number (e.g. profit margins ...)

·        The PretzelStore, RedmondMsgIn157, and RedmondMsgOut classes can be obtained from my WWW page under assignments.

·        Format the data so that monetary values have two decimal places!!!  

        DecimalFormat twoDecFormat = new DecimalFormat ("0.00");

                              Instead of what we have largely been using, which drops trailing zeros

·        You can put your main in a separate file as you have been doing when working with my classes (preferred) or at the bottom of the PretzelStore class.

·        Put your name, e-mail address, and date in comments near the top (e.g.  /* Your Name */).  Make should you put your name in PretzelStore too (e.g. /* modified by Your Name */ )

·        Also, comment any significant code to document it (each loop, each if, and each significant calculation should have a comment).  Make sure you clearly mark your changes to PretzelStore.

·        Indent code following standard conventions (indent to show that something is “inside” or “part of” the preceding code (e.g. inside if’s or loops, or statements continued on a new line). 

 

Compile the program and remove any errors. Ensure that the program runs correctly. It should run on any set of inputs (test it on more than the example below!!, I will!!).

               To avoid needless long waits, I recommend doing this on the c: drive, then upon completion, copying it to the a: drive, testing it there, creating an extra backup for yourself, then deleting it from the c: drive.

 

Hand in:


Sample Interaction:

Please enter Starting Inventory

10

Please enter Sales Price

0.25

Please enter Profit Margin

0.12

How many customers will we be processing?

5

How many pretzels would you like?

4

Ok, here you go - 4 pretzels

How many pretzels would you like?

5

Ok, here you go - 5 pretzels

How many pretzels would you like?

10

We don't have that many pretzels, would you like to buy 1

y

Ok, here you go - 1 pretzels

 New batch of pretzels successfully ordered

How many pretzels would you like?

10

Ok, here you go - 10 pretzels

How many pretzels would you like?

10

We don't have that many pretzels, would you like to buy 2

n

 New batch of pretzels successfully ordered

We served 4 customers a total of 20 pretzels - total sales of $5.00 and made a total profit of $2.40