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

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...
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
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
2. Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a...
2. Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student gradebook using a two-dimensional array. It should allow the user to enter the number of students and the number of assignments they wish to enter grades for. This input should be used in defining the two-dimensional array for your program. For example, if I say I want to enter grades for 4 students and 5 assignments, your program should define a 4 X...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
Java 176 Lottery Program in Word. Using ArrayLists to Simulate a Lottery Program Simulate a Lottery...
Java 176 Lottery Program in Word. Using ArrayLists to Simulate a Lottery Program Simulate a Lottery Drawing by choosing 7 numbers at random from a pool containing 30 numbers Each time a number is selected, it is recorded and removed from the pool The pool values are 00 to 29 inclusive Your program must output each selected number from the drawing using a two-digit format. For Example, the number 2 would be represented by 02 on the “Picked” line. The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT