Page 1 of 1

Stage 1 - A ticket to book In this stage, you will implement a basic online shopping cart. You are required to create on

Posted: Fri May 20, 2022 10:30 am
by answerhappygod
Stage 1 A Ticket To Book In This Stage You Will Implement A Basic Online Shopping Cart You Are Required To Create On 1
Stage 1 A Ticket To Book In This Stage You Will Implement A Basic Online Shopping Cart You Are Required To Create On 1 (175.1 KiB) Viewed 42 times
Stage 1 – A ticket to book
In this stage, you will implement a basic online shopping cart.
You are required to create one class: Ticket.
Build the Ticket class with the following specifications:
Instance variables
o Stringname
o intprice
o intquantity
No-argument constructor Ticket()
o InitializenametoString“UNKNOWN” o Initializepriceto-1
o Initializequantityto0
Constructor Ticket(String name, int price, int quantity)
o Initializeinstancevariablenametonameifthelatterisnotnull
o Initializeinstancevariablepricetopriceifthelatteris>=0
o
Initializeinstancevariablequantitytoquantityifthelatteris>=1

o
Ifanyoftheparameterpassedinisinvalid,throwIllegalArgumentException.
Public mutators & accessors
o setName(Stringname)&getName()
o setPrice(intprice)&getPrice()
o setQuantity(intquantity)&getQuantity()
o Settersshouldconsiderthevalidityoftheparameterpassedin
Public method getTotalPrice() which returns the total cost of
the item to purchase. The total price is computed using the
formula: price * quantity
Override the toString() method which returns the following
String: o “name quantity X $price = $totalCost”
The CartManager class contains the main() method. Complete the
stage1(Ticket ticket) method, which prompts the user for one ticket
and sets the attributes of Ticket passed into stage1(). Print the
information of the item. Example outputs are as follows. Given the
same user input, your program is expected to produce the same
output as follows. Only minor format differences (e.g., extra line
break) are allowed.
********** Stage 1 ********** Enter the name of the ticket: The
Matrix Reloaded
Enter the ticket price:
15
3
Stage 2 – A basic shopping cart
You must complete Stage 1 before attempting Stage 2. If Stage 1
has not been completed Stage 2 will not be assessed.
In this stage, you will create a basic shopping cart. The
shopping cart is supposed to (1) store a customer’s information;
(2) allow a customer to add items; and (3) compute the total cost
of the items within the shopping cart.
Implement the class ShoppingCart. Specifically, the ShoppingCart
class should contain:
Private fields
o StringcustomerName
o Stringdate
o Ticket[]inCartTickets
o staticfinalintCAPACITYofvalue5(provided) o intcount
No-argument constructor ShoppingCart()
o InitializecustomerNametoString“UNKNOWN”
o InitializedatetoString“1May2022”
o InitializecartTicketstoanemptyarrayofsizeCAPACITY o
Initializecountto0
Constructor ShoppingCart(String name, String date)
o Initializeinstancevariablenametoname
o Initializeinstancevariabledatetodate
o InitializeinCartTicketstoanemptyarrayofsizeCAPACITY o
Initializecountto0
Public accessor getName() which returns the customer name of the
shopping cart
Public mutator setName(String name) which sets the customer
name
Public accessor getDate() which returns the sign up date of the
customer
Public mutator setDate(String date) which sets the current date
of shopping cart
Public member method add(Ticket ticket), which adds the ticket
parameter to inCartTickets array. The method determines whether the
ticket passed in is not null and is different to any ticket in
inCartTickets. If yes, it adds ticket to the shopping cart and
returns true. Otherwise, it prints a message “Ticket invalid or
already added.” and returns false. Note, all tickets should have
different names ignoring cases. “Star wars”, “star wars” and “Star
Wars” are considered the same. If the shopping cart is full, the
ticket then cannot be added. It prints “SHOPPING CART IS FULL” and
returns false.
Public member method getCount() which returns quantity of all
tickets in cart. Note that the quantity of all tickets must be
computed as the total quantity of all different tickets in the
cart. E.g. if there are 1 sale of 3 tickets and 1 sale of 1 ticket,
the method will return 4, not 2.
Public member method getCost() which returns the total cost of
the tickets in cart.
Public member method printTotal() which outputs (1) the customer
and the date; (2) number of total sales in the shopping cart; (3)
the information of each sale in the shopping cart; and (4) the
total cost of the shopping cart. If the cart is empty, outputs (1)
the customer and the
The Matrix Reloaded 3 X $15 = $45
date; and (2) the message “SHOPPING CART IS EMPTY.”. Please
refer to the example outputs when implementing this method.
Complete stage2(ShoppingCart cart) method in CartManager. Ask
user to enter name and date. Sets the customerName and date of cart
passed in. Print the information of the shopping cart created by
calling printTotal() (note, it is the first-time calling
printTotal() ).
Prompt the user for two ticket sales, create two objects of the
Ticket class, and add these two objects into the shopping cart
created. Hint: Before prompting for the second item, you may need
to call scanner.nextLine(); to allow the user to input a new string
(depends on your program). Print info of the shopping cart by
calling printTotal() (calling printTotal() for the second
time).
Example outputs are as follows. Given the same user input, your
program is expected to produce the same output . Only minor format
differences (e..g., extra line break) are allowed.
Example output after printTotal() is called for the first
time:
Stage 3 – Updating the shopping cart
You must complete Stage 2 before attempting Stage 3. If Stage 2
has not been completed Stage 3 will not be assessed.
In this stage, you will need to allow user to update the items
already added to the shopping cart. You need to extend the
ShoppingCart class by adding:
• Public method removeTicket(String ticketName)
o It removes a ticket from the shopping cart if its name matches
with the parameter
ticketName. After removing, output this message “Ticket
ticketName removed from
the cart”. It returns true in this case.
o
IfnoiteminthecartmatcheswithticketName,printthismessage“Ticketnotfound.
Cart remains unchanged.” It returns false in this case.
• Public method updateTicket(String ticketName)
o Modifiesaticket’squantityandreturnstrueifsuccessful.
o If an item with a matched name of the parameter ticketName can be
found in cart,
prompt the user to enter the new quantity with the message
“Please enter the new
quantity:”. Update the ticket quantity according to the user
input.
o If the ticket cannot be found (by ticketName), print the message:
“Ticket not found.
Cart remains unchanged.” and return false.
• Public method checkout()
o Generate a summary of the shopping cart by calling printTotal().
Allow customer to
check-out.
o Removesallitemsfromtheshoppingcartandreturnstrue.
o If the shopping cart is empty, do not generate a summary.
Instead, output the
message “SHOPPING CART IS EMPTY.” and returns false.
Implement stage3() method in CartManager. Note that in main(),
stage3() will work on the cart object that has been updated by
Stage 2. Ask user for the ticket to be removed. Perform the removal
by calling removeTicket(String ticketName), and print the summary
of the cart by calling the printTotal(). Next, ask for the ticket
name to be modified, then call updateTicket(String ticketName).
Print the information of the shopping cart by calling the
printTotal() method. Finally, prompt the user to check- out and
call the checkout() method.
Example outputs are as follows. Given the same user input, your
program is expected to produce the same output as follows. Only
minor format differences (e..g., extra line break) are allowed.
Stage 4 – VIP Shopping Cart
You must complete Stage 3 before attempting Stage 4. If Stage 3
has not been completed Stage 4 will not be assessed.
In this stage, you will extend the program to create a shopping
cart for VIP customer. VIP customers have a few privileges:
(1) If the total price of purchased ticket is greater or equal
to $100, then the last ticket is free for one. Using the last
example from Stage 3, Andrew Smith ordered 4 tickets for Top Gun
but only needs to pay for 3, e.g. $75.
(2) Collect points after check-out. The number of points
collected is equal to the cost that a customer actually pays at
check-out. If a VIP pays $75 at check-out, then 75 points will be
rewarded.
(3) A VIP customer can use the points to pay at check-out.
Specifically, every 20 points can be used equivalently as $1. When
a VIP proceeds to check-out, your program should prompt the user
for number of points he/she wishes to use. When using points to
pay, a customer can only use multiples of 20 points, e.g., 20, 40,
100 points etc. If the customer enters a number that is not
multiples of 50, the nearest lower multiple of 20 will be used,
e.g. 80 for 95, 40 for 49. If the customer enters a number greater
than the total points available, print the message: “Not enough
points. Please re-enter or enter -1 to quit point redeeming.”. If a
valid number is entered, deduct the points from balance and
continue the checkout. If -1 is entered, the program will proceed
with the normal checkout.
To achieve the above requirements, you will need to implement a
new class VIPCart that is a subclass of the ShoppingCart class.
Additional private fields, new methods or overridden methods may be
added. You then need to implement stage4() method. In this method,
prompt the user to create a VIP shopping cart. Add one item to the
shopping cart, and then call checkout().
Example outputs are as follows. Given the same user input, your
program is expected to produce the same output as follows. Only
minor format differences (e..g., an extra line break) are
allowed.
Example, a VIP ordered 3 tickets of “The Matrix Reloaded” and
redeemed 100 points at checkout.
Stage 1 - A ticket to book In this stage, you will implement a basic online shopping cart. You are required to create one class: Ticket. Build the Ticket class with the following specifications: • Instance variables o String name o int price o int quantity . O • No-argument constructor Ticket() Initialize name to String "UNKNOWN" o Initialize price to -1 Initialize quantity to 0 O . Constructor Ticket(String name, int price, int quantity) Initialize instance variable name to name if the latter is not null Initialize instance variable price to price if the latter is >= 0 Initialize instance variable quantity to quantity if the latter is >= 1 If any of the parameter passed in is invalid, throw IllegalArgumentException. оооо • Public mutators & accessors o setName(String name) & getName() o setPrice(int price) & getPrice() o setQuantity(int quantity) & getQuantity() Setters should consider the validity of the parameter passed in O Public method getTotalPrice() which returns the total cost of the item to purchase. The total price is computed using the formula: price * quantity . Override the toString() method which returns the following String: o "name quantity X $price = $totalCost" The CartManager class contains the main() method. Complete the stage1(Ticket ticket) method, which prompts the user for one ticket and sets the attributes of Ticket passed into stage10). Print the information of the item. This method should handle 'gracefully' any exception thrown from ticket. Example outputs are as follows. Given the same user input, your program is expected to produce the same output as follows. Only minor format differences (e.g., extra line break) are allowed. ********** Stage 1 ********** 1 Enter the name of the ticket: The Matrix Reloaded Enter the ticket price: 15 Enter the quantity: 3 The Matrix Reloaded 3 x $15 = $45

date; and (2) the message "SHOPPING CART IS EMPTY.". Please refer to the example outputs when implementing this method. Complete stage2(Shopping Cart cart) method in CartManager. Ask user to enter name and date. Sets the customerName and date of cart passed in. Print the information of the shopping cart created by calling printTotal() (note, it is the first-time calling printTotal()). Prompt the user for two ticket sales, create two objects of the Ticket class, and add these two objects into the shopping cart created. Hint: Before prompting for the second item, you may need to call scanner.nextLine(); to allow the user to input a new string (depends on your program). Print info of the shopping cart by calling printTotal() (calling printTotal() for the second time). Example outputs are as follows. Given the same user input, your program is expected to produce the same output. Only minor format differences (e..g., extra line break) are allowed. Example output after print Total() is called for the first time: ********** Stage 2 ********** Enter the name of the customer: Andrew Smith User Prompt in stage2() Enter the current date: 1 May 2022 Andrew Smith - 1 May 2022 SHOPPING CART IS EMPTY Example output of the first printTotal() call Example outputs after printTotal() is called for the second time: Enter the name of the ticket: The Matrix Reloaded Enter the ticket price: 15 Enter the quantity: 3 Enter the name of the ticket: Top Gun Enter the ticket price: 25 Enter the quantity: 2 Andrew Smith - 1 May 2022 Number of tickets: 5 The Matrix Reloaded 3 X $15 = $45 Example output of the second printTotal() call Top Gun 2 X $25 = $50 Total cost: $95

Stage 2 - A basic shopping cart You must complete Stage 1 before attempting Stage 2. If Stage 1 has not been completed Stage 2 will not be assessed. In this stage, you will create a basic shopping cart. The shopping cart is supposed to (1) store a customer's information; (2) allow a customer to add items; and (3) compute the total cost of the items within the shopping cart. Implement the class Shopping Cart. Specifically, the Shopping Cart class should contain: • Private fields o String customer Name o String date o Ticket[] inCartTickets static final int CAPACITY of value 5 (provided) o int count O 0 No-argument constructor Shopping Cart() Initialize customerName to String "UNKNOWN" Initialize date to String "1 May 2022" Initialize cartTickets to an empty array of size CAPACITY o Initialize count to O оооо Constructor ShoppingCart(String name, String date) o Initialize instance variable customerName to name o Initialize instance variable date to date Initialize inCart Tickets to an empty array of size CAPACITY o Initialize count to O O Public accessor getCustomerName() which returns the customer name of the shopping cart Public mutator setCustomerName(String name) which sets the customer name Public accessor getDate() which returns the sign up date of the customer Public mutator setDate(String date) which sets the current date of shopping cart . Public member method add(Ticket ticket), which adds the ticket parameter to in CartTickets array. The method determines whether the ticket passed in is not null and is different to any ticket in inCart Tickets. If yes, it adds ticket to the shopping cart and returns true. Otherwise, it prints a message “Ticket invalid or already added." and returns false. Note, all tickets should have different names ignoring cases. "Star wars", "star wars” and “Star Wars" are considered the same. If the shopping cart is full, the ticket then cannot be added. It prints "SHOPPING CART IS FULL" and returns false. . Public member method getTotalCount() which returns quantity of all tickets in cart. Note that the quantity of all tickets must be computed as the total quantity of all different tickets in the cart. E.g. if there are 1 sale of 3 tickets and 1 sale of 1 ticket, the method will return 4, not 2. Public member method getCost() which returns the total cost of the tickets in cart. Public member method printTotal() which outputs (1) the customer and the date; (2) number of total sales in the shopping cart; (3) the information of each sale in the shopping cart; and (4) the total cost of the shopping cart. If the cart is empty, outputs (1) the customer and the

Another example: ********** Stage 3 ********** Do you want to remove a ticket from the cart? Y/N Y Enter the name of the ticket: No such ticket! Topgun Ticket not found. Cart remains unchanged. Andrew Smith - 1 May 2022 Number of tickets: 5 The Matrix Reloaded 3 x $15 = $45 Top Gun 2 X $25 = $50 Total cost: $95 Example outputs of updateTicket() and printTotal(). Assume 2 tickets of “Top Gun” in the cart. Do you want to update a ticket from the cart? Y/N Y Enter the name of the ticket: Top gun Case insensitive. Please enter the new quantity: 4 Andrew Smith - 1 May 2022 Number of tickets: 7 The Matrix Reloaded 3 X $15 = $45 Top Gun 4 X $25 = $100 Total cost: $145 Example outputs after calling checkout() if not empty. Do you want to checkout? Y/N Y Andrew Smith - 1 May 2022 Number of tickets: 7 The Matrix Reloaded 3 x $15 = $45 Top Gun 4 X $25 = $100 Total cost: $145 Thank you for shopping

Stage 3 – Updating the shopping cart You must complete Stage 2 before attempting Stage 3. If Stage 2 has not been completed Stage 3 will not be assessed. In this stage, you will need to allow user to update the items already added to the shopping cart. You need to extend the Shopping Cart class by adding: . O Public method remove Ticket(String ticketName) It removes a ticket from the shopping cart if its name matches with the parameter ticketName. After removing, output this message “Ticket ticketName removed from the cart". It returns true in this case. If no item in the cart matches with ticketName, print this message "Ticket not found. Cart remains unchanged." It returns false in this case. O . O o Public method update Ticket(String ticketName) Modifies a ticket's quantity and returns true if successful. If an item with a matched name of the parameter ticketName can be found in cart, prompt the user to enter the new quantity with the message "Please enter the new quantity:". Update the ticket quantity according to the user input. If the ticket cannot be found (by ticketName), print the message: “Ticket not found. Cart remains unchanged." and return false. O . O Public method checkout() Generate a summary of the shopping cart by calling printTotal(). Allow customer to check-out. Removes all items from the shopping cart and returns true. o If the shopping cart is empty, do not generate a summary. Instead, output the message "SHOPPING CART IS EMPTY." and returns false. O Implement stage3() method in CartManager. Note that in main(), stage3() will work on the cart object that has been updated by Stage 2. Ask user for the ticket to be removed. Perform the removal by calling remove Ticket(String ticketName), and print the summary of the cart by calling the printTotal(). Next, ask for the ticket name to be modified, then call update Ticket(String ticketName). Print the information of the shopping cart by calling the printTotal() method. Finally, prompt the user to check- out and call the checkout() method. Example outputs are as follows. Given the same user input, your program is expected to produce the same output as follows. Only minor format differences (e..g., extra line break) are allowed. ********** Stage 3 ********** Do you want to remove a ticket from the cart? Y/N Y Enter the name of the ticket: Case insensitive top gun Top Gun removed from the shopping cart. Andrew Smith - 1 May 2022 Number of tickets: 3 The Matrix Reloaded 3 X $15 = $45 Total cost: $45

Andrew Smith - 1 May 2022 Number of tickets: 3 The Matrix Reloaded 3 x $15 = $45 Total cost: $45 Do you want to checkout? Y/N Y How many points to redeem? Enter -1 to checkout without using points. 118 Redeemed 100 points for $5 100 points redeemed, not 118 points! Total price paid: $40 40 VIP points added. Available 290 points. Thank you for shopping Andrew from the above example is now buying two sets of tickets. Assume he has 350 VIP points. Enter the name of the ticket: The Matrix Reloaded Enter the ticket price: 15 Enter the quantity: 3 Enter the name of the ticket: Top Gun Enter the ticket price: 25 Enter the quantity: 4 Andrew Smith - 1 May 2022 Number of tickets: 7 The Matrix Reloaded 3 x $15 = $45 Top Gun 4 X $25 = $75 (with VIP discount) The last ticket is free!! So only pay for 3. Total cost: $120 Do you want to checkout? Y/N Y How many points to redeem? Enter -1 to checkout without using points. -1

NO VIP points used Total price paid: $120 120 VIP points added. Available 470 points. Thank you for shopping 350 + 120

Stage 4 VIP Shopping Cart You must complete Stage 3 before attempting Stage 4. If Stage 3 has not been completed Stage 4 will not be assessed. In this stage, you will extend the program to create a shopping cart for VIP customer. VIP customers have a few privileges: (1) If the total price of purchased ticket is greater or equal to $100, then the last ticket is free for one. Using the last example from Stage 3, Andrew Smith ordered 4 tickets for Top Gun but only needs to pay for 3, e.g. $75. (2) Collect points after check-out. The number of points collected is equal to the cost that a customer actually pays at check-out. If a VIP pays $75 at check-out, then 75 points will be rewarded. (3) A VIP customer can use the points to pay at check-out. Specifically, every 20 points can be used equivalently as $1. When a VIP proceeds to check-out, your program should prompt the user for number of points he/she wishes to use. When using points to pay, a customer can only use multiples of 20 points, e.g., 20, 40, 100 points etc. If the customer enters a number that is not multiples of 20, the nearest lower multiple of 20 will be used, e.g. 80 for 95, 40 for 49. If the customer enters a number greater than the total points available, print the message: "Not enough points. Please re-enter or enter -1 to quit point redeeming.". If a valid number is entered, deduct the points from balance and continue the checkout. If-1 is entered, the program will proceed with the normal checkout. To achieve the above requirements, you will need to implement a new class VIPCart that is a subclass of the Shopping Cart class. Additional private fields, new methods or overridden methods may be added. You then need to implement stage4() method. In this method, prompt the user to create a VIP shopping cart. Add one item to the shopping cart, and then call checkout(). Example outputs are as follows. Given the same user input, your program is expected to produce the same output as follows. Only minor format differences (e..g., an extra line break) are allowed. Example, a VIP ordered 3 tickets of “The Matrix Reloaded” and redeemed 100 points at checkout. ********** Stage 4 ********** Enter the name of the VIP customer: Andrew is a VIP! Andrew Smith Enter the current date: 1 May 2022 Enter the VIP points available: 350 Enter the name of the ticket: The Matrix Reloaded Enter the ticket price: 15 Enter the quantity: 3