Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.