CS 1083 - Fall 2019
- Project 3: Supermarket Transaction Using
Dynamic Window
(100 points)
The SupermarketDynamicWindow
Class
Objectives
This is one of three major programming projects this
semester.
You may NOT collaborate on this project.
While you may ask for assistance in debugging, this project should
be ENTIRELY your own work.
Other objectives include:
- Use of nested loops.
- Call and write methods with parameters and return values.
- Use the DrawingPanel, Graphics, Color classes, and mouse
events such as Click.
- Use while loops and if statements to validate input and
control code.
- Use arrays to store and process information.
Hand-in Requirements
All projects will be submitted electronically through
Blackboard. Zip up your entire lab directory to submit as
the
source. (Right click on the lab folder and follow the 7-Zip
>
Add to "abc123_project3.zip" or follow Send To >
Compressed
(zipped) Folder.) The lab folder should include the
following:
- SupermarketDynamicWindow.java
- DrawingPanel.java
Introduction
The goal of this project is to code the missing parts (methods) of
a program that allows the user to process a supermarket
transaction in a graphical way. This version will be
programmed as if the application was going to be deployed for a
tablet.
The most interesting part of this project is experiencing the
re-use of code. Calling methods with different parameters
allows the programmer (a.k.a. the student) write programs with
less lines of code while
also organize the funtionalities.
This project is similar to the project 2. For instance, the
method getValueList performs the same
functionality than getValidInput in Project 2.
Moreover, both methods are in charge of getting values from the
user. The difference now is that we need to get the
information in a graphical way. That said, the program
will not send anything to display in text mode rather than through
the DrawingPanels.
Just like for the project 2, in this exercise you act as if you
were part of
a software development team. In other words, when working
in that environment, you need to use/code each and every method
provided as method stubs. The reason for that is that if
you don't work with the methods provided the complete team project
will fail when tests will take place.
Note: Do not pay attention to the tittle of the DrawingPanels.
Specifically where it says "@fox05".
As a recommendation, try to start working with enough time in
advance given that this project may take a good amount of time to
accomplish it.
Details
The program will start with the method genTransaction,
which will perform the following tasks.
- Ask the user for a customer via a method call such as customer
= (int) getValueList(customerName, "Customer", true);.
- Repeatedly ask the user for actions via a method call such as
action = (int) getValueList(actions, "Action", true);.
According to the action returned from the call, it will
perform one of the following tasks.
- Add to cart.
- Check if the cart is full using the method isCartFull
and perform the following actions according to the
returned Boolean value.
- True: Do nothing.
- False:
- Let the user select an item to add to the cart
via a method call item = (int)
getValueList(itemDesc, "Item", true);
- Let the user input a quantity via a method
call quantity = getValueList(numbers,
"Quantity", false);. Note that here the
third parameter is set to false to indicate that
the returned quantity is expected to be a true
double value (with digits and a decimal
point "."). This would require the
getValueList method to assemble a String with
the digits and period to represent a valid
double value. The method isNumeric(temporalString)
should be used to validate such a string. If the
quantity is valid and after the user clicks the
OK button on the panel, the getValueList method
should use the Double.parseDouble(valueString)
method to convert the string representation of
the valid quantity into a double value and
return it. If the value returned is 0.0
the action "adding to the cart" should be
cancelled.
- Add the itemID and quantity information to the
cart by calling the method addToCart
- Calculate and revise the subtotal, discount,
tax, and grand total.
- Display the grand total in the panel by
calling the method showTotal.
- Remove from cart.
- Verify that the cart contains at least one item by
calling the method isCartEmpty and perform the
following tasks according to the returned Boolean value.
- True: Do nothing.
- False:
- Let the user select the item to delete.
For that, the program will:
- Create an array with the description of
the items in the cart by calling the method
getCartItemNames.
- Let the user select the item to delete via
a method call such as itemCart = (int)
getValueList(cart, "Cart", true);,
where the first parameter cart is the array
returned by getCartItemNames.
- Obtain the item "ID" by calling the method getItemAtCart.
- Remove the item from the cart by calling the
method remItem which will return the
quantity of that item in the cart.
- Calculate and update the subtotal, discount,
tax, and grand total.
- Display the grand total in the panel by
calling the method showTotal.
- Finish transaction.
- Let the user enter the dollar amount (to pay for the
items in the cart) via a method call such as cash =
getValueList(numbers, "Cash", false);.
- If the value returned is greater than or equal to
the grand total, calculate the change and show the
change by calling the method showMessage.
Otherwise, keep asking the user for another cash
value.
- Cancel transaction.
- Clear the cart by calling the method clearCart.
- Reset the subtotal, discount, tax, and grand total.
- Display grand total which should be 0.00 by calling
the method showTotal.
- Display the message "cart is empty" by calling the
method showMessage.
The Cart
In the previous project, all the arrays were static. In
other words, they did not change in size or values throughout all
the program execution. Nonetheless, in this project we
introduce the concept of a shopping cart. The cart
stores information in two arrays cartItem and cartQty.
These arrays have a capacity to hold MAX_ITEMS
items. However, the actual number of items can be less than
MAX_ITEMS and will be recorded in the variable cartSize.
Initial Zip File
You should start your project by
downloading abc123_project3.zip.
This
file contains DrawingPanel.java file and a template SupermarketDynamicWindow.java
file.
DrawingPanel.java
The DrawingPanel.java has been updated to include two
additional methods for getting mouse click positions.
Here are the methods you may use.
Method Name |
Description |
getGraphics( ) |
returns a Graphics object that the program can
draw on |
setBackground(color) |
sets the background color |
sleep(milliseconds) |
pause for a given number of milliseconds (1000
milliseconds equals one second) |
close( ) |
closes the window |
getClickX( ) |
returns the X position of the last mouse click |
getClickY( ) |
returns the Y position of the last mouse click |
See the provided getDecision() method in the SupermarketDynamicWindow
class for more details on how to use these methods. You should model your implementation
of your getValueList method after the sample code provided in the getDecision().
SupermarketDynamicWindow.java
The template version of SupermarketDynamicWindow.java
already implements the following pseudocode which you should not change:
In the main method:
- Asks to the user to confirm if a new transaction should be
started.
- If yes, it will call the genTransaction method.
In the genTransaction method:
- Asks to the user to confirm if a new transaction should be
started.
- If yes, it will call the genTransaction method.
You should start coding right after this, following the instructions
provided in the Details section.
You should study the code in SupermarketDynamicWindow.java
to gain an understanding of how the code implements the
aforementioned behavior. Pay attention to the description of what
is stored in each variable. For the getClickRowExample
and getClickColExample methods, determine the
correspondence between the return values and locations of the
mouse clicks. Figure out how the program knows which
rectangle is selected in a particular cell labeled by "Yes" and
"No".
You should then start coding the functionality described in the
section Details. Study the detailed
documentation of what is each method purpose (functionality) and
the details about parameters and their possible values, and what
will be returned by the method.
Change to receive an array of options
For this project, you need to code the missing parts in all the
code which intends to work with dynamic windows which will change
size and options possible toselect based on the array that will
be received as parameter.
The program should be modified to ensure that it implements the
behavior that will be seen
in the videos provided in the next link.
Rubric
Your program should compile without any errors. A program
with more than one or two compile errors will likely get a zero
for the whole assignment.
The following criteria will also be used to determine the grade
for this assignment:
- [10 points] If your submission includes the following:
- The program draws the string "Project 3 written by [...]".
with your specifics.
- Your submission was a Zip file named abc123_project3.zip
containing a folder named abc123_project3, which
contains the other files. Note that you should change abc123 to
your own.
- If your submission contains files named
SupermarketDynamicWindow.java and DrawingPanel.java.
- If your program contains a comment that describes what
the program does and contains a comment describing each method
and big portions of the program.
- If your program is indented properly.
- [20 Points] The genTransaction method was
implemented following the process described in the Details
section.
- [25 Points] The getValueList method was implemented
and called correctly.
- [15 Points] Correctly working to get the index of the
array received when returnInt parameter is true.
- [10 Points] Correctly working to get the double value
assembled by the sequence of numbers and "." selected by the user
when returnInt parameter is false.
- [5 Points] The method getClickRow was coded and
called correctly, using as example the method getClickCol.
- [15 Points] All the methods pertaining to the operations with
the cart were implemented
correctly.
- [3 Points] The method addToCart
- [3 Points] The method removeItemCart
- [1 Points] The method getCartItemNames
- [1 Points] The method getItemAtCart
- [1 Points] The method clearCart
- [1 Points] The method isCartFull and isCartEmpty
- [15 Points] Correct implementation of the graphical methods.
- [10 Points] The method drawOptions was
implemented with nested loops.
- [3 Points] The method showMessage.
- [2 Points] The method showTotal.
- [10 Points] The program shows the right output as presented in
the videos provided.