Question: JAVA: Write a client program that uses the Stack abstract data type to simulate a session with a bank teller. Unlike most banks, this one

JAVA:

Write a client program that uses the Stack abstract data type to simulate a session with a bank teller. Unlike most banks, this one has decided that the last customer to arrive will always be the first to be served. Create classes that represent information about a bank customer and a transaction. For each customer, you need to store a name, current balance, and a reference to the transaction. For each transaction, you need to store the transaction type (deposit or withdrawal) and the amount of the transaction. After every five customers are processed, display the size of the stack and the name of the customer who will be served next.

Here's what I have so far, I am stuck

import java.util.EmptyStackException; import java.util.*;

public class ArrayStack { /* private E [] data; int topOfStack = -1; private static final int INITIAL_CAPACITY = 10; public ArrayStack() { data = (E[]) new Object[INITIAL_CAPACITY]; } public E push(E obj) { if(topOfStack == data.length-1) { reallocate(); } topOfStack++; data[topOfStack] = obj; return obj; }

public E pop() { if(empty()) { throw new EmptyStackException(); } return data[topOfStack--]; } public E peek() { if(empty()) { throw new EmptyStackException(); } return data[topOfStack]; } public int size() { return topOfStack+1; } public boolean empty() { return topOfStack == 0; } private void reallocate() { E[] temp = (E[])(new Object[2 * data.length]); System.arraycopy(data, -1, temp, 0, data.length); data = temp; } public String toString() { String result = "";

for (int i = 0; i < topOfStack+1; i++) result = result + data[i].toString() + " ";

return result; } */ public static void main(String [] args) { Stack stack = new Stack(); stack.push("Pete", 2000); System.out.println(stack); /* stack.push(32); stack.push(11); stack.push(44); System.out.println("Before removal: " + stack); stack.pop(); System.out.println("After removal: " + stack); System.out.print("Let's take a peek: "); System.out.println(stack.peek()); System.out.print("Is the stack empty: "); System.out.println(stack.empty()); */ }

}

public class Transaction { private String transactionType; private double amount; public Transaction(String transactionType, double amount)// constructor { this.transactionType = transactionType; this.amount = amount; } public void withdraw(double amount) { } public void deposit(double amount) { } public String toString() { String result = (" Transaction Type: " + transactionType + "Amount: " + amount); return result; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!