Determine the different ways the system will be used. This includes main functions the system needs to perform and who will use it.
Functional Requirements
Based on the requirements and use cases, identify the main objects of the system and analyze how they interact and relate to each other...
For each class, define the attributes (data) it will hold and the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation.
API:
for payment:
API: product/payPrice/
Request:
{amount: “XX”, vendingMachineId: “XXXX”}
Response
Success: {transactionId: “XXX”, message: “Success”}
Failure: { message: “Failure”}
for getting product status check
API: product/:key
Request:
{id: key}
Response:
Success: {message: “Please take the item”}
Failure: {message: “The item selected is empty. Please select the correct item”}
maintainence alert
API: maintence/monthly
Request
Response
Success: {message: “Maintainace montly alert”}
User complaint
API: complaint/
Request: {message: “xxxxx”, transactionId: “xxxxxx”}
Response: {message: “Message successfully delivered. Someone will contact you shortly to resolve your queries regarding the transaction”}
Classes
abstract class PaymentType {
public abstract void pay(double amount,String Client);
}
class UPI extends PaymentType {
private UPIIntent upi;
public UPI(){}
@override
public void pay(double amount,String Client){
upi.payMoneyToClient(amount, client);
}
}
class CreditCard extends PaymentType {
private CreditIntent credit;
public CreditCard(){}
@override
public void pay(double amount,String Client){
credit.payMoneyToClient(amount, client);
}
}
class DebitCard extends PaymentType {
private DebitIntent debit;
public DebitCard(){}
@override
public void pay(double amount,String Client){
credit.payMoneyToClient(amount, client);
}
}
class PaymentFactory {
public PaymentFactory(){}
pubic void pay(String type, double amount, String client){
if(type == “UPI”){
UPI upi = new UPI();
upi.pay(amount, client);
} else if(type == “CREDIT”){
CreditCard creditCard = new CreditCard();
creditCard.pay(amount, client);
} else if(type == “DEBIT”){
DebitCard debitCard = new DebitCard();
debitCard.pay(amount, client);
} else {
throw new Error(”No intent found for payment”);
}
}
}
class Item {
String name;
double price;
int itemCount;
public Item (String name, double price, int itemCount) {
this.name = name;
this.price = price;
this.itemCount = itemCount;
}
}
class Items {
private static int size = 48;
private static int itemSize = 48;
Database db;
public void listItems () {
List<Item> items = db.inventoryItems();
return items;
}
public int removeItem(String item){
List<Item> items = db.inventoryItems();
String result = “No Item found”;
for(int i = 0; i < items.size; i++){
if(items.get(i).equals(item)){
if(items.get(i).itemCount - 1 > 0) {
items.set(i, new Item(item, items.get(i).price, items.get(i).itemCount - 1);
db.setInventory(item.get(i));
} else {
db.removeInventoryItem(item);
}
return items.get(i).price;
}
}
return -1;
}
public String addItem(String item, double price, int itemCount){
List<Item> items = db.inventoryItems();
if(items.size() == itemSize){
return “Space is full”;
}
String result = “Item added”;
for(int i = 0; i < items.size; i++){
if(items.get(i).equals(item)){
if(items.get(i).itemCount == size){
return “Space is full”;
}
items.set(i, new Item(item, price, items.get(i).itemCount + itemCount);
db.setInventory(item.get(i));
return result;
}
}
items.set(i, new Item(item, price, itemCount);
return result;
}
}
class Maintainance {
Mail mail;
Database db;
public void triggerMaintainanceAlert(){
long date = db.lastDate();
long currDate = new Date().now().toMillis();
if(currDate - date ≥ 30){
mail.sendMail(”Maintainance time”);
db.setLastDate(currDate);
}
}
}
Vending machine should implement
cart items
Cart item should have a fixed limit of item
Cart should remove Item;
payment class
Maintaince
add item
maintaince alert
notify message
class VendingMachine{
Items items;
PaymentFactory paymentFactory;
Maintainance maintaince;
Timer timer;
public void startTimer() {
timer.scheduledAtFixedRate(new TimeTask(){
@override
public void run(){
maintaince.triggerMaintainanceAlert();
}
}, 0, 1000 * 60 * 24 * 30)
}
public String buy(String item, String paymentType){
int price = Items.removeItem(item).price;
if(price ≠ -1){
paymentFactory.pay(price, paymentType):
return “Purchased”
}
return “Item not found”;
}
public String addItem(String item, double price, int itemCount){
return items.addItem(item, price, itemCount);
}
}
Explain design tradeoffs you considered. Check and explain whether your design adheres to SOLID principles. Explain how your design can handle changes in scale and whether it would be easy to extend with new functionalities. Identify areas for future improvement...