Question

For Java For this assignment you will develop two classes called ATM and Customer that simulate...

For Java

For this assignment you will develop two classes called ATM and Customer that simulate an imaginary automated teller machine (ATM). In the assignment, you should also develop a UML class diagram for the ATM class and a jUnit test case.

In the program, we assume that an ATM initially keeps $100.00 cash for customer transactions. Additionally, we assume that there are a total of ten customers combined for the Union Bank and BOA banks. This is a list of customers with their names, PINs, balances, and banks they have.

  1. Alice, 1234, $5000.00, UnionBank

  2. Tom, 2000, $200.00, UnionBank

  3. Monica, 3000, $50.00, UnionBank

  4. Michael, 7777, $0.00, UnionBank

  5. John, 8000, $500.00, UnionBank

  6. Jane, 2222, $500.00, UnionBank  

  7. Robert, 2323, $200.00, BOA

  8. Owen, 4455, $50.00, BOA

  9. Chris, 8787, $10.00, BOA

  10. Rebecca, 8080, $555.55, BOA

Demo Program

The following program presents a demo program that uses the ATM and Customer classes.

public class ATMDemo

{

public static void main(String[] args)

{

ATM machine1 = new ATM("UnionBank ");

ATM machine2 = new ATM(200, "BOA", "Library");

Customer alice;

System.out.println("===== Welcome to Demo Program =====");

System.out.println(machine1);

System.out.println("");

System.out.println(machine2);

System.out.println("\n===== Equality Checking =====");

System.out.println(machine1.equals(machine2));

System.out.println("");

machine1.setATM(100, "BIT");

machine1.addFund(400);// In this method, we assume that an ATM machine

                // administrator adds $400 more cash to the machine.

System.out.println(machine1);

System.out.println("");

machine1.displayMenu()

machine1.withdrawal("Alice", 7777, 10.50); // In the method, we assume

// that the customer "Alice" wants $10.50 withdrawal with PIN 7777.

machine1.withdrawal("Robert", 2323, 10.50);

machine1.withdrawal("Alice", 1234, 10000);

machine1.withdrawal("Alice", 1234, 10);

machine1.withdrawal("Alice", 1234, 2000);

System.out.println("\n===== Machine Status =====");

machine1.status();

System.out.println("");

if (machine1.isCustomer("Alice")) {

alice = machine1.getCustomer("Alice");

System.out.println(alice);

System.out.println("");

}

machine1.deposit("Alice", 1234, 10); // In the method, we assume that

// "Alice" conducts the cash deposit $10

// to the machine with PIN 1234.

System.out.println("\n===== Machine Status =====");

machine1.status();

System.out.println("");

//The following method conducts a money transfer transaction from

// "Alice" to "Tom" about $10.00 dollars.

if (machine1.transfer("Alice", 1234, 10, "Tom", 2000)) {

System.out.println("Good transfer!!!\n");

}

if (!machine1.transfer("Chris", 8787, 10, "Tom", 2000)) {

System.out.println("Bad transfer!!!\n");

}

System.out.println("\n===== Machine Status =====");

machine1.status();

System.out.println("\n===== Thank you! ====="); } }

Sample Run of the Demo Program

The following presents a sample result of the demo program.

===== Welcome to Demo Program =====

Serial Number: 0

Bank Name: UnionBank

Location: UNKNOWN

Balance: 100.00

Serial Number: 200

Bank Name: BOA

Location: Library           

Balance: 100.00

===== Equality Checking =====

false

Serial Number: 100

Bank Name: UnionBank

Location: BIT

Balance: 500.00

===== ATM Transaction Menu =====

1. Withdrawal

2. Deposit

3. Transfer

Fail – withdrawal

Fail – withdrawal

Fail – withdrawal

Succeed – withdrawal

Fail – withdrawal

===== Machine Status =====

Serial Number: 100

Bank Name:  

Location: BIT

Balance: 490.00

5 Transactions so far:

Withdrawal: 5 (1 success, 4 fail)

Deposit: 0 (0 success, 0 fail)

Transfer: 0 (0 success, 0 fail)

Alice: Balance $4990.00

Succeed – deposit

===== Machine Status =====

Serial Number: 100

Bank Name: UnionBank

Location: BIT

Balance: 500.00

6 Transactions so far:

Withdrawal: 5 (1 success, 4 fail)

Deposit: 1 (1 success, 0 fail)

Transfer: 0 (0 success, 0 fail)

Succeed – transfer

Good transfer!!!

Fail – transfer

Bad transfer!!!


===== Machine Status =====

Serial Number: 100

Bank Name: UnionBank

Location: BIT

Balance: 500.00

8 Transactions so far:

Withdrawal: 5 (1 success, 4 fail)

Deposit: 1 (1 success, 0 fail)

Transfer: 2 (1 success, 1 fail)

===== Thank you! =====

Read the demo program and sample execution result very carefully to identify operations of the classes. And also, you should consider the failure cases of the transactions such as incorrect name, incorrect PIN, not enough fund, unmatched bank, etc.

UML Design

Based on the demo program and sample run, identify instance variables and methods for the ATM class and draw the class in a UML class diagram using the Visio program (Google Drawing, Draw.io, etc.). In the UML diagram, you should include all instance variables and methods that are necessary to run the demo program. But you don’t need to include constructors, accessors, and mutators because they are obvious. And also, you don’t need to draw the UML diagram for the Customer class because it’s very small.

Homework Answers

Answer #1

------Screenshot--------------------

---------------------------------------------------------

--------------------ATMDemo.java-----------------

---------------------------------------------------------

public class ATMDemo{

public static Customer[] getCustomerList(){

Customer[] customerList = new Customer[10];

int i = -1;

i++;customerList[i] = new Customer("Alice", 1234, 5000.00, "OUBank");

i++;customerList[i] = new Customer("Tom", 2000, 200.00, "OUBank");

i++;customerList[i] = new Customer("Monica", 3000, 50.00, "OUBank");

i++;customerList[i] = new Customer("Michael", 7777, 0.00, "OUBank");

i++;customerList[i] = new Customer("John", 8000, 500.00, "OUBank");

i++;customerList[i] = new Customer("Jane", 2222, 500.00, "OUBank");

i++;customerList[i] = new Customer("Robert", 2323, 200.00, "BOA");

i++;customerList[i] = new Customer("Owen", 4455, 50.00, "BOA");

i++;customerList[i] = new Customer("Chris", 8787, 10.00, "BOA");

i++;customerList[i] = new Customer("Rebecca", 8080, 555.55, "BOA");

return customerList;

}

public static void main(String[] args){

ATM machine1 = new ATM("OUBank");

ATM machine2 = new ATM(200, "BOA", "Library");

Customer alice;

System.out.println("===== Welcome to Demo Program =====");

System.out.println(machine1); System.out.println("");

System.out.println(machine2);

System.out.println("\n===== Equality Checking =====");

System.out.println(machine1.equals(machine2));

System.out.println("");

Customer[] customerList = getCustomerList();

machine1.setATM(100, "BIT");

machine1.addFund(400);// In this method, we assume that an ATM machine

// administrator adds $400 more cash to the machine.

System.out.println(machine1);

machine1.customerList = customerList;

System.out.println("");

machine1.displayMenu();

machine1.withdrawal("Alice", 7777, 10.50); // In the method, we assume

// that the customer "Alice" wants $10.50 withdrawal with PIN 7777.

machine1.withdrawal("Robert", 2323, 10.50);

machine1.withdrawal("Alice", 1234, 10000);

machine1.withdrawal("Alice", 1234, 10);

machine1.withdrawal("Alice", 1234, 2000);

System.out.println("\n===== Machine Status =====");

machine1.status();

System.out.println("");

if (machine1.isCustomer("Alice")) {

alice = machine1.getCustomer("Alice");

System.out.println(alice);

System.out.println("");

}

machine1.deposit("Alice", 1234, 10); // In the method, we assume that

// "Alice" conducts the cash deposit $10

// to the machine with PIN 1234.

System.out.println("\n===== Machine Status =====");

machine1.status();

System.out.println("");

//The following method conducts a money transfer transaction from

// "Alice" to "Tom" about $10.00 dollars.

if (machine1.transfer("Alice", 1234, 10, "Tom", 2000)) {

System.out.println("Good transfer!!!\n");

}

if (!machine1.transfer("Chris", 8787, 10, "Tom", 2000)) {

System.out.println("Bad transfer!!!\n");

}

System.out.println("\n===== Machine Status =====");

machine1.status();

System.out.println("\n===== Thank you! =====");

}

}

---------------------------------------------------------

--------------------ATM.java-----------------

---------------------------------------------------------

public class ATM{

private String bankName;

private String location = "UNKOWN";

private int serialNo = 0;

private double balance = 100.0;

public static Customer[] customerList;

public int[][] numTransactions = new int[3][2];

public ATM(String bankName){

for(int i=0;i<3;i++){

for(int j=0;j<2;j++){

numTransactions[i][j] = 0;

}

}

this.bankName = bankName;

}

public ATM(int serialNo, String bankName, String location){

for(int i=0;i<3;i++){

for(int j=0;j<2;j++){

numTransactions[i][j] = 0;

}

}

this.serialNo = serialNo;

this.bankName = bankName;

this.location = location;

}

public void setATM(int serialNo, String location){

this.serialNo = serialNo;

this.location = location;

}

public void addFund(double fund){

this.balance += fund;

}

public String getBankName(){return bankName;}

public String getLocation(){return location;}

public int getSerialNo(){return serialNo;}

public double getBalance(){return balance;}

public Boolean isEqual(ATM machine){

Boolean r1 = bankName.equals(machine.getBankName());

Boolean r2 = location.equals(machine.getLocation());

Boolean r3 = serialNo == machine.getSerialNo();

Boolean r4 = balance == machine.getBalance();

return r1 && r2 && r3 && r4;

}

public String toString(){

String s1 = "Serial Number: " + serialNo + "\n";

String s2 = "Bank Name: " + bankName + "\n";

String s3 = "Location: " + location + "\n";

String s4 = "Balance: " + balance;

return s1+s2+s3+s4;

}

public Boolean withdrawal(String name, int PIN, double amount){

if(balance>=amount){

for(Customer c:customerList){

if(c.name.equals(name)

&& c.PIN == PIN

&& c.balance>=amount

&& c.bankName.equals(bankName))

{

c.balance -= amount;

balance -= amount;

numTransactions[0][0] += 1;

System.out.println("Succeed – withdrawal");

return true;

}

}

}

numTransactions[0][1] += 1;

System.out.println("Fail – withdrawal");

return false;

}

public Boolean deposit(String name, int PIN, double amount){

for(Customer c:customerList){

if(c.name.equals(name)

&& c.PIN == PIN

&& c.bankName.equals(bankName))

{

c.balance += amount;

balance += amount;

numTransactions[1][0] += 1;

System.out.println("Succeed – deposit");

return true;

}

}

numTransactions[1][1] += 1;

System.out.println("Fail – deposit");

return false;

}

public Boolean transfer(String name1, int pin1, int amount, String name2, int pin2){

for(Customer c1:customerList){

if(c1.name.equals(name1)

&& c1.PIN == pin1

&& c1.balance >= amount

&& c1.bankName.equals(bankName))

{

for(Customer c2:customerList){

if(c2.name.equals(name2)

&& c2.PIN == pin2

&& c2.bankName.equals(bankName))

{

c1.balance -= amount;

c2.balance += amount;

numTransactions[2][0] += 1;

System.out.println("Succeed – transfer");

return true;

}

}

}

}

numTransactions[2][1] += 1;

System.out.println("Fail – transfer");

return false;

}

public void status(){

System.out.println(toString());

int totalTransactions = 0;

for(int i=0;i<3;i++){

for(int j=0;j<2;j++){

totalTransactions += numTransactions[i][j];

}

}

System.out.println(totalTransactions + " Transactions so far:");

int b = numTransactions[0][0],c = numTransactions[0][1];

int a = b+c;

System.out.println("Withdrawal: "+a+" ("+b+" success, "+c+" fail)");

b = numTransactions[1][0];c = numTransactions[1][1];

a = b+c;

System.out.println("Deposit: "+a+" ("+b+" success, "+c+" fail)");

b = numTransactions[2][0];c = numTransactions[2][1];

a = b+c;

System.out.println("Transfer: "+a+" ("+b+" success, "+c+" fail)");

}

public Boolean isCustomer(String name){

for(Customer c:customerList){

if(c.name.equals(name) && c.bankName.equals(bankName))

{

return true;

}

}

return false;

}

public Customer getCustomer(String name){

for(Customer c:customerList){

if(c.name.equals(name) && c.bankName.equals(bankName))

{

return c;

}

}

return null;

}

public void displayMenu(){

System.out.println("===== ATM Transaction Menu =====");

System.out.println("1. Withdrawal\n2. Deposit\n3. Transfer");

}

}

---------------------------------------------------------

--------------------Customer.java-----------------

---------------------------------------------------------

public class Customer{

public String name;

public int PIN;

public double balance= 0;

public String bankName;

public Customer(String name, int PIN, double balance, String bankName){

this.name = name;

this.PIN = PIN;

this.balance = balance;

this.bankName = bankName;

}

public String toString(){

return name + ": Balance $" + balance;

}

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT