Skip to content

Instantly share code, notes, and snippets.

@tatey
Created August 13, 2008 04:13
Show Gist options
  • Save tatey/5193 to your computer and use it in GitHub Desktop.
Save tatey/5193 to your computer and use it in GitHub Desktop.
Solution to Lab 3 for 1005ICT
/**
* Write a description of class Account here.
*
* @author Tate Johnson
* @version 2008-08-07
*/
public class Account {
private static int nextId = 1;
private static double totalDeposits = 0;
private int id;
private String name;
private double balance;
public Account(String name) {
id = nextId;
nextId++;
this.name = name;
balance = 0;
}
public static double totalDeposits() {
return totalDeposits;
}
public double balance() {
return balance;
}
public void deposit(double dAmount) {
balance = balance + dAmount;
totalDeposits = totalDeposits + dAmount;
}
public boolean withdraw(double wAmount) {
if (wAmount <= balance) {
balance = balance - wAmount;
totalDeposits = totalDeposits - wAmount;
return true;
}
else {
return false;
}
}
public double calcInterest(double rate) {
double startingBalance = balance;
double totalInterest = 0;
for (int i = 0; i < 12; i++) {
totalInterest = totalInterest + (startingBalance * rate);
startingBalance = startingBalance + (startingBalance * rate);
}
return totalInterest;
}
public String toString() {
return new String(name + ", " + id + ", has $" + balance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment