You are required to implement the Make Order Request use case for the on-line shopping system using an object-orient langauge (C++, C#, or Java). The requirements of Make Order Request are specified by means of the use case model and use case description. You can make your reasonable assumptions for the implementation of this use case if necessary.
Make Order Request use case description
Use case name: Make Order Request Summary: Customer enters an order request to purchase catalog items. The customer’s credit card is checked for validity and sufficient credit to pay for the requested catalog items.
Actor: Customer, Bank
Precondition: Customer has selected one or more catalog items
Main sequence: 1. Customer provides order request and customer account Id to pay for purchase. 2. System retrieves customer account information, including the customer’s credit card details. 3. System requests to a bank checking the customer’s credit card for the purchase amount and, if approved, creates a credit card purchase authorization number. 4. System creates a delivery order containing order details, customer Id, and credit card authorization number. 5. System confirms approval of purchase and displays order information to customer.
Make Order Request use case description :
Alternative sequences:
Step 2: If customer does not have an account, the system prompts the customer to provide information in order to create a new account. The customer can either enter the account information or cancel the order.
Step 3: If authorization of the customer’s credit card is denied (e.g., invalid credit card or insufficient funds in the customer’s credit card account), the system prompts the customer to enter a different credit card number. The customer can either enter a different credit card number or cancel the order.
Postcondition: Customer has purchased items.
Expert Answer
Solution=================================
import java.util.ArrayList;
import java.util.Scanner;
class Bank{
//Dummy Cards and balances
private String cards[]={
“1234567890”,”2345678901″,”135792469″
};
double balances[]={300,100,50.50};
private static int authNumCounter=707707;
//A card is authorized if it exists, and has sufficient balance
boolean isCardAuthorized(String cardNo, double amount){
for(int i=0;i<cards.length;i++){
if(cards[i].equals(cardNo)){
if(balances[i]>=amount){
return true;
}
}
}
return false;
}
public String getAuthNum(String creditcard,double amount) {
if(!isCardAuthorized(creditcard,amount)){
return String.valueOf(authNumCounter++);
}
return null;
}
}
class Customer{
ArrayList<Order>orderHistory;
Order currentOrder;
static int customerIdCounter=1001;
int customerId;
public Customer(String order){
orderHistory=new ArrayList<>();
currentOrder=new Order(order);
customerId=customerIdCounter;
customerIdCounter++;
}
public Order getCurrentOrder(){
return currentOrder;
}
}
//The main controller
class SystemController{
//Delivery order
class DeliveryOrder{
Order order;
int CustomerId;
String creditCardAuthNumber;
public DeliveryOrder(Order order, int customerId, String creditCardAuthNumber) {
this.order = order;
CustomerId = customerId;
this.creditCardAuthNumber = creditCardAuthNumber;
}
}
//List of all customers who have an account and delivery orders
ArrayList<Customer> registeredCustomers;
ArrayList<DeliveryOrder> deliveryOrders;
Bank bank;
public SystemController(){
registeredCustomers=new ArrayList<>();
deliveryOrders=new ArrayList<>();
bank = new Bank();
}
//Check if customer already have an account
boolean isCustomerRegistered(Customer cust){
for(Customer c:registeredCustomers){
if(c==cust) return true;
}
return false;
}
//Main logic
public void placeOrder(Customer cust, String creditcard)
{
Scanner in = new Scanner(System.in);
//If customer has no account prompt him to make one,or cancel order
if(!isCustomerRegistered(cust)){
System.out.println(“New User? Register(R) to continue..n Or Cancel(C) order: “);
String choice=in.nextLine().trim();
System.out.println(choice);
if(choice.equals(“R”)){
registerCustomer(cust);
System.out.println(“You are now registerd with us!! nPlease Wait…”);
}else{
System.out.println(“Your order has been cancelled”);
return;
}
}
//Prompt The right card number, until the Customer either cancels order or provides
//The correct card info
while(!bank.isCardAuthorized(creditcard, cust.getCurrentOrder().getTotalAmount())){
System.out.println(“Please enter the correct card, or Cancel(C) the order: “);
String input = in.nextLine().trim();
if(input.equals(“C”)) return;
creditcard=input;
}
in.close();
Order currentOrder=cust.getCurrentOrder();
String authNum=bank.getAuthNum(creditcard,currentOrder.getTotalAmount());
//Creating a Delivery Order, and storing it for record
DeliveryOrder o = new DeliveryOrder(cust.getCurrentOrder(),cust.customerId,authNum);
deliveryOrders.add(o);
//Displaying Order Summary
System.out.println(“Purchase Approved! Order Summary:”);
currentOrder.displayOrder();
System.out.println(“Total Amount: “+currentOrder.getTotalAmount());
}
public void registerCustomer(Customer cust){
registeredCustomers.add(cust);
}
}
class Order{
//Some fictional order items, and their associated prices
static final String items[] = {“A”,”B”,”C”,”D”};
static final double price[] ={10,15,11.50,170};
//Quantity chosen per item
int qty[]={0,0,0,0};
double totalCost;
//For simplicity order comes
//In the format of 4A-0B-3C-0D
public Order(String orders){
String[] data=orders.split(“-“);
for(int i=0;i<items.length;i++){
qty[i]=Character.getNumericValue(data[i].charAt(0));
}
//Calculating total Cost
totalCost=0;
for(int i=0;i<qty.length;i++){
totalCost+=(qty[i]*price[i]);
}
}
public double getTotalAmount(){
return totalCost;
}
public void displayOrder(){
System.out.println(“Item Quantity PricePerUnit”);
for(int i=0;i<qty.length;i++){
if(qty[i]!=0){
System.out.println(items[i]+” “+qty[i]+” “+price[i]);
}
}
}
}
public class PurchaseController {
public static void main(String[] args) {
SystemController sc = new SystemController();
Customer cust = new Customer(“1A-9B-2C-0D”);
sc.placeOrder(cust, “00000000”);
}
}
Output===============