// Basic class diagram code
import java.util.Date;
import java.util.Scanner;
public class Main {
static Controller ctlr = new Controller();
static AuthManager auth = new AuthManager();
static Scanner sc = new Scanner(System.in);
public static void showMenu() {
boolean exit = false;
while (!exit) {
System.out.println(
"\n\n****** Select operation *****"
+ "\n\t1) Save card details"
+ "\n\t2) Add money to wallet"
+ "\n\t3) Make payment"
+ "\n\t4) Recharge mobile"
+ "\n\t5) Logout");
int ch = Integer.parseInt(sc.nextLine());
switch (ch) {
case 1:
break;
case 2:
System.out.println("Please enter amount");
double amt = Double.parseDouble(sc.nextLine());
ctlr.addMoneyToWallet("123", amt);
break;
case 3:
System.out.println("Please enter receiver mobile no.");
String mobNo = sc.nextLine();
System.out.println("Please enter amount");
amt = Double.parseDouble(sc.nextLine());
ctlr.transfer("8975464185", mobNo, amt);
break;
case 4:
System.out.println("Please enter mobile no. to recharge");
mobNo = sc.nextLine();
ctlr.recharge(mobNo);
break;
case 5:
exit = true;
break;
default:
System.out.println("\nPlease select valid operation");
break;
}
}
}
public static void main(String[] args) {
boolean exit = false;
while (exit != true) {
System.out.println(
"\n\n ***** You are not logged in ******"
+ "\n\t1) Login using OTP"
+ "\n\t2) Login using password"
+ "\n\t3) Register"
+ "\n\t4) Exit");
int ch = Integer.parseInt(sc.nextLine());
switch (ch) {
case 1:
System.out.println("\nEnter mobile no.: ");
long mobileNo = Long.parseLong(sc.nextLine());
auth.loginUsingOTP(mobileNo);
showMenu();
break;
case 2:
System.out.println("\nEnter username: ");
String username = sc.nextLine();
System.out.println("\nEnter password: ");
String password = sc.nextLine();
auth.loginUsingPassword(username, password);
showMenu();
break;
case 3:
System.out.println("\nEnter username: ");
username = sc.nextLine();
System.out.println("\nEnter password: ");
password = sc.nextLine();
System.out.println("\nEnter email: ");
String email = sc.nextLine();
auth.register(username, password, email);
showMenu();
break;
case 4:
exit = true;
System.out.println("Exiting....");
break;
default:
System.out.println("\nPlease select valid choice");
break;
}
}
}
}
class Controller {
private String[] planIDs;
/**
*
* @param from
* @param to
* @param amount
*/
public boolean transfer(String from, String to, double amount) {
BankAccount bankAccount = new BankAccount();
Bank bank = new Bank();
bank.transfer(from, bankAccount, amount);
System.out.println("Money transferred successfully");
return true;
}
/**
*
* @param userID
* @param docID
*/
public boolean verify(String userID, String docID) {
// TODO - implement Controller.verify
throw new UnsupportedOperationException();
}
/**
*
* @param userID
* @param amount
*/
public boolean addMoneyToWallet(String userID, double amount) {
Scanner sc = new Scanner(System.in);
System.out.println("\nPlease enter card no : ");
String cardNo = sc.nextLine();
System.out.println("\nPlease enter validity : ");
String validity = sc.nextLine();
System.out.println("\nPlease enter cvv : ");
String cvv = sc.nextLine();
System.out.println("INR " + amount + " added to your wallet");
return true;
}
/**
*
* @param userID
* @param amount
*/
public boolean saveCardDetails() {
Scanner sc = new Scanner(System.in);
System.out.println("\nPlease enter card no : ");
String cardNo = sc.nextLine();
System.out.println("\nPlease enter validity : ");
String validity = sc.nextLine();
System.out.println("\nPlease enter cvv : ");
String cvv = sc.nextLine();
System.out.println("Card details saved successfully");
return true;
}
public boolean recharge(String mobNo) {
String plan1 = " INR 399 - 2 GB/day";
String plan2 = " INR 199 - 1 GB/day";
Scanner sc = new Scanner(System.in);
System.out.println("\nPlease select plan\n1) " + plan1 + "\n2) " + plan2);
int c = Integer.parseInt(sc.nextLine().trim());
if (c == 1) {
System.out.println("Mobile number " + mobNo + " recharged succesfully with plan " + plan1);
} else {
System.out.println("Mobile number " + mobNo + " recharged succesfully with plan " + plan2);
}
return true;
}
}
class Customer extends User {
private String customerID;
private String[] cardIDs;
class Card {
private String cardNo;
private String issuerBankID;
private Date validity;
public boolean pay() {
return true;
}
class Bank {
private String ifscCode;
private String address;
private String bankID;
/**
*
* @param fromAccountNo
* @param toBankAccount
*/
public void transfer(String fromAccountNo, BankAccount toBankAccount, double amount) {
System.out.println("Amount transferred successfully");
class BankAccount {
private String accountNo;
private String bankID;
private String holderName;
private double balance;
class Document {
private String docID;
private String name;
private int size;
public String read() {
// TODO - implement Document.read
throw new UnsupportedOperationException();
}
/**
*
* @param s
*/
public void write(String s) {
// TODO - implement Document.write
throw new UnsupportedOperationException();
}
class Merchant extends User {
private int merchantID;
private int planID;
private String[] docIDs;
private BankAccount bankAccount;
/**
*
* @param planID
*/
public void buyPlan(String planID) {
// TODO - implement Merchant.buyPlan
throw new UnsupportedOperationException();
}
class Plan {
private String planID;
private int validity;
private Date startDate;
private double cost;
private double dailyQuota;
private double transactionChargesPercent;
class User {
private int userID;
private String username;
private String password;
private String emailID;
private String[] transactionIDs;
private double walletBalance;
private long mobileNo;
public int getUserID() {
return userID;
}
public void setUserID(int userID) {
this.userID = userID;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmailID() {
return emailID;
}
public void setEmailID(String emailID) {
this.emailID = emailID;
}
public String[] getTransactionIDs() {
return transactionIDs;
}
public void setTransactionIDs(String[] transactionIDs) {
this.transactionIDs = transactionIDs;
}
public double getWalletBalance() {
return walletBalance;
}
public void setWalletBalance(double walletBalance) {
this.walletBalance = walletBalance;
}
public long getMobileNo() {
return mobileNo;
}
public void setMobileNo(long mobileNo) {
this.mobileNo = mobileNo;
}
class AuthManager {
static Scanner sc = new Scanner(System.in);
String loggedInUserID;
public void generateOTP() {
System.out.println("OTP generated successfully");
}
public boolean verifyOTP() {
System.out.println("OTP verified successfully");
return true;
}
/**
*
* @param username
* @param password
* @param emailID
*/
public void register(String username, String password, String emailID) {
System.out.println("User registered successfully");
}
/**
*
* @param mobileNo
*/
public boolean loginUsingOTP(long mobileNo) {
generateOTP();
System.out.println("\nEnter OTP: ");
int enteredOTP = Integer.parseInt(sc.nextLine());
if (verifyOTP()) {
System.out.println("\nLogin successful");
return true;
}
System.out.println("\nLogin failed");
return false;
}
/**
*
* @param username
* @param password
*/
public boolean loginUsingPassword(String username, String password) {
System.out.println("User logged in successfully using password");
return true;
}
/*
PS C:\Users\Iraj\Desktop> javac .\State_Design_Pattern_Main.java
PS C:\Users\Iraj\Desktop> java State_Design_Pattern_Main
***** You are not logged in ******
1) Login using OTP
2) Login using password
3) Register
4) Exit
1
Enter mobile no.:
9476294502
OTP generated successfully
Enter OTP:
1234
OTP verified successfully
Login successful
****** Select operation *****
1) Save card details
2) Add money to wallet
3) Make payment
4) Recharge mobile
5) Logout
2
Please enter amount
5000
Please enter card no :
1234 5678 1234
Please enter validity :
01/22
Please enter cvv :
372
INR 5000.0 added to your wallet
****** Select operation *****
1) Save card details
2) Add money to wallet
3) Make payment
4) Recharge mobile
5) Logout
4
Please enter mobile no. to recharge
7290275891
Please select plan
1) INR 399 - 2 GB/day
2) INR 199 - 1 GB/day
1
Mobile number 7290275891 recharged succesfully with plan INR 399 - 2 GB/day
****** Select operation *****
1) Save card details
2) Add money to wallet
3) Make payment
4) Recharge mobile
5) Logout
5
***** You are not logged in ******
1) Login using OTP
2) Login using password
3) Register
4) Exit
4
Exiting....
PS C:\Users\Iraj\Desktop>
*/