Online-Academy

Look, Read, Understand, Apply

Menu

OOAD - Object Oriented Analysis and Design

Verifying Card and PIN at ATM

Go through the code, and try to make sequence diagram from it.

import java.util.*;
class Card{
	int cardno;
	int pin;
	public Card(int cardno,int pin){this.cardno=cardno;this.pin=pin;}
	public int getCard(){return cardno;}
	public int getPIN(){return pin;}
}
class Customer{
	int id;
	Scanner sc = new Scanner(System.in);
	String name;
	Card card; 
	public Customer(int id,String name, Card c){
		this.id = id;
		this.name = name;
		card = c;
	}
	public int getID(){return id;}
	public int getCard(){int id = sc.nextInt();return id;}
	public int getPIN(){int id = sc.nextInt();return id;}
}
class ATM{
	ArrayList<Card> cards = new ArrayList<Card>();
	int i;
	public ATM(){
		cards.add(new Card(1,1234));
		cards.add(new Card(2,1235));
		cards.add(new Card(3,1236));
		cards.add(new Card(4,1237));
	
	}
	public boolean verifyCard(int id){
		for(i=0;i<cards.size();i++){
			if(cards.get(i).getCard() == id){
				return true;
			}
		}
		return false;
	}
	public boolean verifyPIN(int pin ){
		for(i=0;i<cards.size();i++){
			if(cards.get(i).getPIN() == pin){
				return true;
			}
		}
		return false;
	}
}
class ATMController{
	ATMUI ui = new ATMUI();
	Customer cus = null;
	boolean flag = false; 
	ATM atm = new ATM();
	public void request_for_card(Customer c){
		cus = c; 
		ui.request_for_card();
	}
	public boolean validateCard(){
		int id = cus.getCard();
		flag = atm.verifyCard(id);
		return flag; 
	}
	public boolean validatePIN(){
		ui.request_for_pin();
		int pin = cus.getPIN();
		flag = atm.verifyPIN(pin);
		return flag; 
	}
	public void show_error_msg(){
		ui.show_error_msg();
	}
	public void show_menu(){
		ui.show_menu();
	}
}
class ATMUI{
	public void request_for_card(){
		System.out.println("Enter Card: ");
	}
	public void request_for_pin(){
		System.out.println("Enter PIN: ");
	}
	public void show_error_msg(){
		System.out.println("Wrong Card!!!");
	}
	public void show_menu(){
		System.out.println("1.Statement\n2.Withdraw");
	}
}

class check_card_pin{
	public static void main(String[] arrr){
		Card cd1 = new Card(11,1234);
		Card cd2 = new Card(21,1235);
		Customer c1 = new Customer(1, "Ramesh",cd1);
		Customer c2 = new Customer(2, "Mahesh",cd2);
		
		ATMController controller = new ATMController();
		controller.request_for_card(c1);
		boolean flag = controller.validateCard();
		if(flag == true){
			flag = controller.validatePIN();
			if(flag == true){
				controller.show_menu();
			}else controller.show_error_msg();
		}else controller.show_error_msg();
	}
}