Question: Assignment 2 : Implementing Scenarios A Shopping Cart Example This assignment is going to build on the work that we are doing in the lectures.
Assignment : Implementing Scenarios A Shopping Cart Example This assignment is going to build on the work that we are doing in the lectures. Your goal is to create and run two test scenarios to demonstrate the functionality of the shopping cart transaction classes. The first scenario is the scenario covered in the lecture sessions. The second scenario is a slight variation of the first: a The user adds three items. b Requests a display of the shopping cart items and total. c Removes one item. d Confirms the cart and makes an order. e The user submits a payment; however, the payment is not valid. f The user is sent a regret email notifying them that the order was unsuccessful. Each scenario should be contained in its own test method. See the lecture notes on this. Your starting point will be the Java code that will be supplied from the lecture notes. To complete this assignment, you are expected to proceed according to the development process that I demonstrated in last week's lecture. Your solution for each scenario is only allowed to use the following classes. These are the classes that were identified in the lecture. Customer ShoppingCart Item Order Address Payment Email TransactionTest ShoppingCart: It should be clear how to implement all the methods needed here. Some are 'getter' methods, others are addremove methods for addingremoving items from the ShoppingCart's ArrayList. The one method that might not be clear is the one called 'close When the close method is called, items cannot be added or removed from the ShoppingCart. If you try to call the ShoppingCart's addItem item method after the close method is called, it will print out an error : "Sorry the shopping cart is closed". Hint: you should use a boolean variable and conditional statements to implement this. If its value is false, you can addremove items; if its value is true, you cannot addremove items Item: You will already have the code for the Item class from Canvas but double check the variable types to ensure that they are suitable. Order: The role of the Order class is to take a ShoppingCart object and transfer its items one by one into itself. It should also take the information about the Customer. Once this is done, the ShoppingCart should be empty. ie its Arraylist should be empty. Order is an important class in this programme. Look over the lecture notes to see the list of methods that we provisionally assigned to it It will have relationships with several other objects such as ShoppingCart, Payment, Address and Email. Address: The role of the Address class is to hold the address fields of the Customer's address: eg street, city, zip, country. A customer may have two Address objects associated with them a billing address and a delivery address. You will need methods to set and get the information in each Address object. Payment: The Payment class holds the following pieces of information customer; credit card type; credit card number; date; address; credit card bank name As an object that is in charge of verifying its own information, the Payment class also has code
for validating the data submitted. For example, a new Payment object might be created as
follows:
Payment payment new Paymentcustomer address "NasterCard",
;
or since the Order object contains most of the information you need, you could have an
alternative constructor for Payment that takes an order object as an input parameter.
Payment payment new Paymentorder "NasterCard", ;
You will need to write some code to make sure that the Card type is either "MasterCard" or
"Visa". Clearly, "NasterCard" is not valid.
You should also check that the card number has the correct number of digits not like
above
You should also check if the date is in the future so that the card is not out of date.
If the input information is correct, then the Payment object should set a boolean field called
'valid'. This will allow you to define a method called isValid which returns the value of the
field. If it is true, it will run otherwise it will not run the body of the if statement.
You can then write the following in your test code
ifpaymentisValid
do something
else
do something print a message that the payment is not valid
TransactionTest:
As illustrated in the lectures, this is a test class. It should have two methods one for each
scenario. They are executed from the main method, which is contained by the TransactionTest
class.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
