-
-
Save codecademydev/d7eb352ad0b02f56360b6b0d498c56b1 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SavingsAccount { | |
int balance; | |
public SavingsAccount(int initialBalance){ | |
balance = initialBalance; | |
} | |
public void checkBalance(){ | |
System.out.println("Hello" + "!" + "Your balance is " + balance); | |
} | |
public void deposit(int amountToDeposit){ | |
balance= amountToDeposit + balance; | |
System.out.println("You just deposited " + amountToDeposit); | |
} | |
public int withdraw(int amountToWithdraw){ | |
balance= balace - amountToWithdraw; | |
System.out.println("You just withdrew " + amountToWithdraw); | |
return amountToWithdraw; | |
} | |
public static void main(String[] args){ | |
SavingsAccount savings = new SavingsAccount(2000); | |
//Check balance: | |
System.out.println("Hello!"); | |
System.out.println("Your balance is "+savings.balance); | |
//Withdrawing: | |
int afterWithdraw = savings.balance - 300; | |
savings.balance = afterWithdraw; | |
System.out.println("You just withdrew "+300); | |
//Check balance: | |
System.out.println("Hello!"); | |
System.out.println("Your balance is "+savings.balance); | |
//Deposit: | |
int afterDeposit = savings.balance + 600; | |
savings.balance = afterDeposit; | |
System.out.println("You just deposited "+600); | |
//Check balance: | |
System.out.println("Hello!"); | |
System.out.println("Your balance is "+savings.balance); | |
//Deposit: | |
int afterDeposit2 = savings.balance + 600; | |
savings.balance = afterDeposit2; | |
System.out.println("You just deposited "+600); | |
//Check balance: | |
System.out.println("Hello!"); | |
System.out.println("Your balance is "+savings.balance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment