Question

In: Computer Science

I need to create a program that will simulate an ATM. The program has to be...

I need to create a program that will simulate an ATM. The program has to be written in JAVA that uses JOptionaPane to pop up the messages. It will need to simulate to get

** balance

**withdraw

**Deposit

**exit the atm

** need to have a method that shows a receipt of everything that was done during the transaction

Solutions

Expert Solution

If you have any problem with the code feel free to comment.

Program

import javax.swing.JFrame;
import javax.swing.JOptionPane;

class ATM {
   //instance variables
   private int balance, withdraw, deposit;
  
   //setters
   public void setBalance(int balance) {
       this.balance = balance;
   }

   public void setWithdraw(int withdraw) {
       this.withdraw = withdraw;
   }

   public void setDeposit(int deposit) {
       this.deposit = deposit;
   }
  
   public void performDeposit() {
       if(deposit>0) {//if value is less than zero balance remain unchanged
           balance += deposit;          
       }
   }
  
   public void performWithdraw() {
       if(withdraw<balance) {//if withdraw is greater than balance, balance remain unchanged
           balance -= withdraw;          
       }
   }
   //for showing reciept
   public void showReciept() {
       System.out.println("**********Reciept**********");
       System.out.println("Initial Balance: $"+balance);
       System.out.println("Withdraw Amount: $"+withdraw);
       performWithdraw();
       System.out.println("Balance after withdraw: $"+balance);
       System.out.println("Deposit Amount: $"+deposit);
       performDeposit();
       System.out.println("Balance after deposit: $"+balance);
   }
  
}

public class Test {
   public static void main(String[] args) {
       JFrame frame = new JFrame();
       ATM obj = new ATM();
       //getting user input using JOptionPane
       String balance = JOptionPane.showInputDialog(frame,"Enter Balance");
       String withdraw = JOptionPane.showInputDialog(frame,"Enter Withdraw");
       String deposit = JOptionPane.showInputDialog(frame,"Enter Deposit");
       //setting user input
       obj.setBalance(Integer.parseInt(balance));
       obj.setWithdraw(Integer.parseInt(withdraw));
       obj.setDeposit(Integer.parseInt(deposit));
       obj.showReciept();//showing reciept
       System.exit(0);
   }
}

Output


Related Solutions

You need to create a Java class library to support a program to simulate a Point-...
You need to create a Java class library to support a program to simulate a Point- of-Sale (POS) system. General Requirements: You should create your programs with good programming style and form using proper blank spaces, indentation and braces to make your code easy to read and understand; You should create identifiers with sensible names; You should make comments to describe your code segments where they are necessary for readers to understand what your code intends to achieve. Logical structures...
I need someone to create a program for me: Create a program that takes as input...
I need someone to create a program for me: Create a program that takes as input an employee's salary and a rating of the employee's performance and computes the raise for the employee. The performance rating here is being entered as a String — the three possible ratings are "Outstanding", "Acceptable", and " Needs Improvement ". An employee who is rated outstanding will receive a 10.2 % raise, one rated acceptable will receive a 7 % raise, and one rated...
Simulate an ATM machine. Create ten accounts in an array with id 0, 1, . ....
Simulate an ATM machine. Create ten accounts in an array with id 0, 1, . . . , 9, and initial balance $100. The system prompts the user to enter an id. If the id is entered incorrectly, ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run. You can enter a choice 1 for viewing the current balance, 2 for withdrawing money, 3 for depositing...
Create an application to simulate a bank ATM and you must combine graphical interfaces using Swing...
Create an application to simulate a bank ATM and you must combine graphical interfaces using Swing or AWT and relational databases. We will have a Bank Accounts database. Each account will have an account number, the name of the owner and the account balance. The program must allow the following options: a) Create an account: request the account information and save it in the database. b) Enter the ATM: it will allow you to request the account number and will...
Create a C++ program to simulate an art gallery: 4 classes: Gallery class Has three vectors...
Create a C++ program to simulate an art gallery: 4 classes: Gallery class Has three vectors of type Painting which represent three categories of paintings (abstract, impressionism, pointillism) Has a function that reads in paintings from a file and stores each painting in the correct vector Read in paintings from file (will have multiple paintings) Title of painting Artists first name Artists last name Address street number Address street name Address city Address state Address zip Artists website Category Number...
1.Create full program in Java that will simulate a Rock Paper Scissors Game You will create...
1.Create full program in Java that will simulate a Rock Paper Scissors Game You will create the code so that when the program is run the user will see in the console the following: We are going to play rock paper scissors. Please choose 1 for Rock 2 for Paper or 3 for scissors. The program will have your choice which is the integer-valued typed in by the user and compChoice which will be the randomly generated value of either...
hello, I need a python program for a drone to follow keyboard commands - Create a...
hello, I need a python program for a drone to follow keyboard commands - Create a simple single obstacle environment and program the drone to navigate through it - Create a more advanced obstacle environment (3+ obstacles) and program the drone to navigate through it
Program Requirements: This assignment requires you to create one program in Java to simulate a Point-of-Sale...
Program Requirements: This assignment requires you to create one program in Java to simulate a Point-of-Sale (POS) system. The solution must be in JAVA language. You create the main program called POSmain.java and two classes: ShoppingCart and CashRegister. Your POSmain program should take three file names from command line arguments. The first file contains a list of products and their prices; the second and third files are lists of items in two shopping carts of two customers. The POSmain program...
I need to simulate the interview speech and use the following skills to explain why I...
I need to simulate the interview speech and use the following skills to explain why I want to join the job of security. The speech is from 30 seconds to 1 minute, and the self-introduction part can be omitted. thank you for your help. Course: Professional Career Development and Management Experience:I am a veteran and served in the 101st Airborne Division of the United States for 3 years. Because I was at infantry company, I can use a lot of...
a) Create a program for the msp430FR6989 .You will use need to program it to be...
a) Create a program for the msp430FR6989 .You will use need to program it to be able to use a external pulse switch to start/stop the blinking of LED1, and a second pulse switch to control the blinking of LED2. b) Modify Program #1 (b) to blink the number of times on the data switches once the pulse switch is engaged
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT