Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created August 27, 2020 13:06
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/78516fec13ab280689ff6ad1339bba79 to your computer and use it in GitHub Desktop.
Save codecademydev/78516fec13ab280689ff6ad1339bba79 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 "+savings.balance);
}
public static void main(String[] args){
SavingsAccount savings = new SavingsAccount(2000);
System.out.println(checkBalance);
//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