Question

In: Computer Science

I have an ATM Machine program. I'm not sure where to place the:   public void io() {...

I have an ATM Machine program. I'm not sure where to place the:   public void io() { section so the program gives the following output:

Welcome to ATM

Press Enter to begin;

Enter amount to begin:

Enter amount to withdraw: 230

Cash dispensed as follows:

$100 Bills: 2

$20 Bills: 1

$10 Bills: 1

The progam consists of

Main.java

class Main {

public static void main(String[] args) {

ATM atm = new ATM();

atm.init();

atm.run();

System.out.println();

System.out.println("ATM Version 0.1.0");

System.out.println("Copyright (C) 2020 " /*+ CHASE_BANK*/);

System.out.println("Code by Quang Pham");

}

}


/* public void io() {

lcd.print("Welcome to ATM\n");

lcd.print("Press ENTER to begin: ");

cardReader.readCard();

//Get amount to withdraw

lcd.print("Enter amount to withdraw: ");

int amount = keypad.getAmount();

//TODO: Verify amount

//Withdraw the amount

int result = dispenser.getCash(amount);

if (result == -1) {

lcd.print("Cash dispense error%n");

}

else {

lcd.print("Cash dispense as follows:\n");

lcd.print(dispenser.num100s() + "\n");

lcd.print(dispenser.num20s() + "\n");

lcd.print(dispenser.num10s() + "\n");

}

}

}*/

System.out.println();

System.out.println("ATM Version 0.1.0");

System.out.println("Copyright (C) 2020 " /*+ CHASE_BANK*/);

System.out.println("Code by Quang Pham");

}

}

ATM.java

class ATM {

private LCD lcd;

private CardReader cardReader;

private Keypad keypad;

private CashDispenser cashDispenser;

public void init() {

System.out.println("ATM.init()");

lcd = new LCD();

lcd.init();

cardReader = new CardReader();

cardReader.init();

keypad = new Keypad();

keypad.init();

cashDispenser = new CashDispenser();

cashDispenser.init();

}

public void run() {

System.out.println("ATM.run()");

}

}

CardReader.java

class CardReader {

public void init() {

System.out.println("CardReader.init()");

}

}

CashDispenser.java

class CashDispenser {

private int num100s;

private int num20s;

private int num10s;

public void init() {

System.out.println("CashDispenser.init()");

}

public int getCash(int amount) {

num100s = amount / 100; //get number of $100 bills

amount = amount % 100; //get remaining amount

num20s = amount / 20; //get number of $20 bills

amount = amount % 20; //get remaining amoung

num10s = amount /10; //get number of $10 bills

amount = amount % 10; //none should be remaining

if (amount != 0) return -1;//error

return 0; //success

}

public String num100s() {

return "$100 Bills: " + num100s;

}

public String num20s() {

return "$20 Bills: " + num20s;

}

public String num10s() {

return "$10 Bills: " + num10s;

}

}

Keypad.java

import java.util.Scanner;

class Keypad {

public void init() {

System.out.println("Keypad.init()");

}

public int getAmount() {

Scanner scanner = new Scanner(System.in);

return scanner.nextInt();

}

}

LCD.java:

class LCD {

public void init() {

System.out.println("LCD.init()");

}

public void print(String s) {

System.out.print(s);

}

}

User.java

class User {

private LCD lcd;

private CardReader cardReader;

private Keypad keypad;

private CashDispenser dispenser;

public User(LCD lcd, CardReader cardReader, Keypad keypad, CashDispenser dispenser) {

this.lcd = lcd;

this.cardReader = cardReader;

this.keypad = keypad;

this.dispenser = dispenser;

}

public void io() {

System.out.println("User.io()");

try {

Thread.sleep(5000);

}

catch (InterruptedException e) {

System.out.println(e);

}

}

}

The program is at:  https://repl.it/@quangnvpham1/ATM-Machine#Main.java .

Any help with this problem is greatly appreciated. Yours truly, Quang Pham

Solutions

Expert Solution

Your code in ATM.java was modified to :

class ATM {

  private LCD lcd;
  private CardReader cardReader;
  private Keypad keypad;
  private CashDispenser cashDispenser;

    public void init() {
      System.out.println("ATM.init()");
      lcd = new LCD();
      lcd.init();

      cardReader = new CardReader();
      cardReader.init();

      keypad = new Keypad();
      keypad.init();

      cashDispenser = new CashDispenser();
      cashDispenser.init();
      lcd.print("Welcome to ATM\n");
    lcd.print("Press ENTER to begin: ");

    //cardReader.readCard();

    //Get amount to withdraw
    lcd.print("Enter amount to withdraw: ");
    int amount = keypad.getAmount();

    //TODO: Verify amount

    //Withdraw the amount
    int result = cashDispenser.getCash(amount);
    if (result == -1) {
    lcd.print("Cash dispense error%n");
   }
    else {
    lcd.print("Cash dispense as follows:\n");
    lcd.print(cashDispenser.num100s() + "\n");
    lcd.print(cashDispenser.num20s() + "\n");
    lcd.print(cashDispenser.num10s() + "\n");
     }
    }

    
    public void run() {
      System.out.println("ATM.run()");
    }
}

I saw that the main function was calling the atm.init() function in the ATM class so I pasted the io() function code in init() function of the ATM class. Wherever you had used dispenser object, I changed those to cashDispenser and commented the cardreader.readcard() call as no such function exists.

The output can be seen:


Related Solutions

So I have a rather long question for Stats and I'm not really even sure where...
So I have a rather long question for Stats and I'm not really even sure where to begin let alone finish it. I am supposed to answer this using PhStat in Excel so if anyone can help me solve this and also explain how they did that would be awesome! Any help is appreciated :) Scenarios of the Problems: A researcher wishes to estimate the mean yearly tuition of the population of private universities throughout the United States. A random...
So I have a rather long question for Stats and I'm not really even sure where...
So I have a rather long question for Stats and I'm not really even sure where to begin let alone finish it. I am supposed to answer this using PhStat in Excel so if anyone can help me solve this and also explain how they did that would be awesome! Any help is appreciated :) Scenarios of the Problems: A researcher wishes to estimate the mean yearly tuition of the population of private universities throughout the United States. A random...
Hi! I have a homework question I'm not sure if I'm doing it correctly. Below is...
Hi! I have a homework question I'm not sure if I'm doing it correctly. Below is the information from the question and my answer in bold. Glass Company makes glass orders based on the customer specifications, so the company uses job costing to track costs. The company uses direct labor hours as the cost driver for manufacturing overhead application. Manufacturing overhead costs for the year:        $787,500 Usage of direct labor hours for the year:               225,000 Beginning Work-in-process, March 1 (Job 57)      $80,000 Beginning...
I have a lab assignment that I'm not sure how to do. The experiment is a...
I have a lab assignment that I'm not sure how to do. The experiment is a cart moving 60cm distance and there is a fan on top of it making it have a mass of .56kg. Every trial there is 100g added to the cart. For this part, the time is kept the same. 1. If the force provided by the fan was the same for each run and we have chosen the same time interval, how does the impulse...
I have a question that has 3 parts to it and I'm not sure about the...
I have a question that has 3 parts to it and I'm not sure about the answers. Could someone please give me the answers and maybe explain a little as well? Would be greatly appreciated! Question 1: Part A) Suppose Home has 500 units of capital and 250 units of labor and Foreign has 1000 units of capital and 3000 units of labor. Which of the following statements is true? a) Home is more capital abundant than Foreign b) Foreign...
I'm getting this error: Exception in thread "main" java.lang.NoSuchMethodError: main I tried using public static void...
I'm getting this error: Exception in thread "main" java.lang.NoSuchMethodError: main I tried using public static void main(String[] args){ but that negates all of the methods that I try to write. I'm just trying to make it so that I can enter values. Thanks. Code below: import java.util.Scanner; public class DataSet2 { private double value; private double sum; private int count; public void add(double value){    System.out.println("Enter values, enter -1 to finish");    Scanner scan = new Scanner(System.in);    value =...
This is for an accounting assignment and I'm not sure where I'm going wrong. I'll copy...
This is for an accounting assignment and I'm not sure where I'm going wrong. I'll copy and paste what I have and the directions as best as possible. PLEEEASE HELP: June 22: Received a bill for $1,190 from Computer Parts and Repair Co. for repairs to the computer equipment. It's telling me my rep and maintenance expense is wrong. I entered: Repairs & Maint. Expense 1190 Accounts payable 1190 It's for Byte of Accouting. What else would this transaction be...
(PLEASE SHOW STEPS TO SOLUTIONS. I'M GETTING STUCK IN MY PROCESS AND NOT SURE WHERE I'M...
(PLEASE SHOW STEPS TO SOLUTIONS. I'M GETTING STUCK IN MY PROCESS AND NOT SURE WHERE I'M GOING WRONG AND WHAT TO DO NEXT.) Skycell, a major European cell phone manufacturer, is making production plans for the coming year. Skycell has worked with its customers (the service providers) to come up with forecasts of monthly requirements (in thousands of phones) as shown in the table below (e.g., demand in Jan. is 1,000,000 units.) Manufacturing is primarily an assembly operation, and capacity...
what i have: import java.util.Scanner; public class examples1 { public static void main(String[] args) { Square...
what i have: import java.util.Scanner; public class examples1 { public static void main(String[] args) { Square shade = new Square(getside()); System.out.println("Your chooses are:"); System.out.println("\nCircle"); System.out.println("Triangle"); System.out.println("Rectangle"); System.out.println("Square"); boolean moreShapes = true; boolean userChoice = true; while(moreShapes) { Scanner shapes = new Scanner (System.in); System.out.println("\nWhat shape do you want:"); String yourShape = shapes.nextLine(); if (userChoice = shade != null) { shade.getSide(); } System.out.println("\nWhat are two size paramters of the shape you choose:"); String yourParameter = shapes.nextLine(); System.out.println("\nYour shape is: " +...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT