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 4
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 1- Deposit and withdraw valid amounts of money
//add code below this line
Atm myAtm = new Atm(1000);
myAtm.deposit(50);
System.out.println(myAtm.getMoney());
myAtm.withdraw(925);
System.out.println(myAtm.getMoney());
//add code above this line
This code should produce the following output:
1050.0
125.0
Try it
Scenario 2- Deposit amount is not positive
//add code below this line
Atm myAtm = new Atm(1000);
myAtm.deposit(-50);
System.out.println(myAtm.getMoney());
//add coExercise 4
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 1- Deposit and withdraw valid amounts of money
//add code below this line Atm myAtm = new Atm(1000); myAtm.deposit(50); System.out.println(myAtm.getMoney()); myAtm.withdraw(925); System.out.println(myAtm.getMoney()); //add code above this line
This code should produce the following output:
1050.0125.0
Try it
Scenario 2- Deposit amount is not positive
//add code below this line Atm myAtm = new Atm(1000); myAtm.deposit(-50); System.out.println(myAtm.getMoney()); //add code above this line
This code should produce the following output:
You cannot deposit a negative amount of money. 1000.0
Try it
Scenario 3- Withdrawal amount is too large
//add code below this line Atm myAtm = new Atm(1000); myAtm.withdraw(5000); System.out.println(myAtm.getMoney()); //add code above this line
This code should produce the following output:
You do not have enough funds to withdraw that amount. 1000.0
Try it
Scenario 4- Withdrawal amount is not positive
//add code below this line Atm myAtm = new Atm(1000); myAtm.withdraw(-50); System.out.println(myAtm.getMoney()); //add code above this line
This code should produce the following output:
You cannot withdraw a negative amount of money. 1000.0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!