Skip to content

Instantly share code, notes, and snippets.

@Aroueterra
Created May 27, 2021 23:29
Show Gist options
  • Save Aroueterra/b0f891f546f2f9544b85d98c0a411aff to your computer and use it in GitHub Desktop.
Save Aroueterra/b0f891f546f2f9544b85d98c0a411aff to your computer and use it in GitHub Desktop.
//add class definitions below this line
class Atm {
private double money;
public double getMoney(){
return money;
}
public void deposit(double s){
Double v = Double.valueOf(s);
if(v>=0){
money += v;
}else{
System.out.println("You cannot deposit a negative amount of money.");
}
}
public Atm(double s){
Double v = Double.valueOf(s);
money = v;
}
public void withdraw(double s){
Double v = Double.valueOf(s);
if(v>=0){
if((money-v)>=0){
money -= v;
}else{
System.out.println("You do not have enough funds to withdraw that amount.");
}
}else{
System.out.println("You cannot withdraw a negative amount of money.");
}
}
}
//add class definitions above this line
public class CodingExercise4 {
public static void main(String[] args) {
//add code below this line
Atm myAtm = new Atm(1000.0);
myAtm.deposit(50.0);
System.out.println(myAtm.getMoney());
myAtm.withdraw(925.0);
System.out.println(myAtm.getMoney());
//add code above this line
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment