Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

0201844524, 978-0201844528

More Books

Students also viewed these Databases questions