Skip to content

Instantly share code, notes, and snippets.

@minor
Created May 5, 2020 03:40
Show Gist options
  • Save minor/d67db39f7930f23395048cda063f355b to your computer and use it in GitHub Desktop.
Save minor/d67db39f7930f23395048cda063f355b to your computer and use it in GitHub Desktop.
Account.java
package com.saurishsrivastava;
public class Account {
private long number = 0;
private double balance = 0.0;
private java.util.Date dateCreated;
public Account() {
this.number = 0;
this.balance = 0.0;
dateCreated = new java.util.Date();
}
public Account(long number, double balance) {
this.number = number;
this.balance = balance;
}
public long getNumber() {
return this.number;
}
public double getBalance() {
return this.balance;
}
public void setBalance(double newBalance) {
balance = newBalance;
}
public String getDateCreated() {
return this.dateCreated.toString();
}
public void deposit(double amount) {
if (amount > 0)
this.balance += amount;
}
public void withdraw(double amount) {
if ((amount > 0) && (amount < this.balance))
this.balance -= amount;
}
public void toString(long number, double balance) {
System.out.println("Account number " + number + " has a balance of $" + balance + ".");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment