Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created July 1, 2020 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/f7138ac8a7aeb56675b121e15edf3ad9 to your computer and use it in GitHub Desktop.
Save codecademydev/f7138ac8a7aeb56675b121e15edf3ad9 to your computer and use it in GitHub Desktop.
Codecademy export
public class SavingsAccount {
int balance;
public SavingsAccount(int initialBalance){
balance = initialBalance;
}
public void checkBalance() {
System.out.println("Hello!");
System.out.println("Your balance is " + balance);
}
public void deposit(int amountToDeposit) {
balance = balance + amountToDeposit;
System.out.println("You just deposited " + amountToDeposit);
System.out.println(balance);
}
public int withdraw(int amountToWithdraw) {
balance = balance - amountToWithdraw;
System.out.println("You just withdrew " + amountToWithdraw);
System.out.println(balance);
return amountToWithdraw;
}
public static void main(String[] args){
SavingsAccount savings = new SavingsAccount(2000);
savings.checkBalance();
savings.deposit(150);
savings.withdraw(300);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment