Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BankAccount
/** A bank account has a balance that can be changed by deposits and withdrawals. */ public class BankAccount : IComparable { //Overrides the toString method in Object class public string ToString() { return GetType().FullName + "[balance= " + balance + "]"; } //Implements the compareTo method in the Comparable interface public int CompareTo (object anObject) { BankAccount anAccount = (BankAccount) anObject; if (Math.abs(balance - anAccount.getBalance()) <= EPSILON) return 0; if (balance < anAccount.getBalance()) return -1; return 1; } /** Constructs a bank account with a zero balance. */ public BankAccount() { balance = 0; } /** Constructs a bank account with a given balance. */ public BankAccount(double initialBalance) { balance = initialBalance; } /** Deposits money into the bank account. */ public void deposit(double amount) { balance = balance + amount; } /** Withdraws money from the bank account. */ public void withdraw(double amount) { balance = balance - amount; } public double getBalance() { return balance; } private double balance; final double EPSILON = 1E-14; }
run
|
edit
|
history
|
help
0
Login Silencioso
Fórum ➡ DataTable #1's rows that are NOT present in DataTable #2 ♦
gass
RGEFCSZX
Intuit // C# // listing_4.3 (StreamWriter // output.txt)
Riemann Sums
gfrsdfdfvgh
123
nums y lists
Hello World