Last active
June 28, 2016 21:26
-
-
Save GlenTiki/87dc85e985d287dc5e688519a74029c7 to your computer and use it in GitHub Desktop.
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
package accounttest1; | |
// This defines a "type" of object which you can create, etc. | |
public class Account { | |
// this defines a "hidden" or "private" variable. | |
// this is a variable which is only able to be accessed from | |
// within the account class methods | |
// The "int" defines this variable as an "integer" which is a | |
// type of number, with no decimal points | |
private int balance; | |
// this is a constructor, there is no "type" defined after the "public" statement | |
// this essentially allows you to create an object of the "type" "Account" | |
public Account(int balance){ | |
this.balance = balance; | |
} | |
// this is a public method which can be used by code outside of this class. | |
// This returns nothing (hence the "void" type). | |
// It takes an int variable named debit | |
public void debit(int debit){ | |
// here we take the debit variable AWAY from this object balance variable | |
// and we set this objects balance to that result | |
this.balance = this.balance - debit; | |
} | |
// this is pretty similar to the debit class method. | |
// this takes an integer and adds to the balance | |
public void credit(int credit) { | |
this.balance = this.balance + credit; | |
} | |
// this is a method which returns something with the int type. | |
public int getBalance() { | |
return this.balance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment