Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created July 8, 2019 01:22
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/d7eb352ad0b02f56360b6b0d498c56b1 to your computer and use it in GitHub Desktop.
Save codecademydev/d7eb352ad0b02f56360b6b0d498c56b1 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" + "!" + "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