Question: Exercise 4 Create the Atm class. This class has the attribute money that gets its value as an argument from the constructor. money - double
Exercise
Create the Atm class. This class has the attribute money that gets its value as an argument from the constructor.
money double that represents the amount of money in the account
This attribute should have a getter method, but not a setter. The class should have two method, deposit and withdrawal. The deposit method should contain data validation to check if the amount of money deposited is positive. Print a message if the data validation fails. The withdrawal method should check the data to see if there is enough money to withdraw and that the amount is positive. Print a message to the user if data validation fails.
Expected Output
Verify that your program works for each of the following scenarios.
Scenario Deposit and withdraw valid amounts of money
add code below this line
Atm myAtm new Atm;
myAtm.deposit;
System.out.printlnmyAtmgetMoney;
myAtm.withdraw;
System.out.printlnmyAtmgetMoney;
add code above this line
This code should produce the following output:
Try it
Scenario Deposit amount is not positive
add code below this line
Atm myAtm new Atm;
myAtm.deposit;
System.out.printlnmyAtmgetMoney;
add coExercise
Create the Atm class. This class has the attribute money that gets its value as an argument from the constructor.
money double that represents the amount of money in the account
This attribute should have a getter method, but not a setter. The class should have two method, deposit and withdrawal. The deposit method should contain data validation to check if the amount of money deposited is positive. Print a message if the data validation fails. The withdrawal method should check the data to see if there is enough money to withdraw and that the amount is positive. Print a message to the user if data validation fails.
Expected Output
Verify that your program works for each of the following scenarios.
Scenario Deposit and withdraw valid amounts of money
add code below this line Atm myAtm new Atm; myAtm.deposit; System.out.printlnmyAtmgetMoney; myAtm.withdraw; System.out.printlnmyAtmgetMoney; add code above this line
This code should produce the following output:
Try it
Scenario Deposit amount is not positive
add code below this line Atm myAtm new Atm; myAtm.deposit; System.out.printlnmyAtmgetMoney; add code above this line
This code should produce the following output:
You cannot deposit a negative amount of money.
Try it
Scenario Withdrawal amount is too large
add code below this line Atm myAtm new Atm; myAtm.withdraw; System.out.printlnmyAtmgetMoney; add code above this line
This code should produce the following output:
You do not have enough funds to withdraw that amount.
Try it
Scenario Withdrawal amount is not positive
add code below this line Atm myAtm new Atm; myAtm.withdraw; System.out.printlnmyAtmgetMoney; add code above this line
This code should produce the following output:
You cannot withdraw a negative amount of money.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
