Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Account{
- //fields
- public static int NumberOfAccounts;
- public static int Id;
- public static double Balance;
- public static double AnnualInterestRate;
- // constructor with no arg
- Account(){
- NumberOfAccounts = 0;
- Id = 0;
- Balance = 0;
- AnnualInterestRate = 0;
- }
- //constructor
- public Account(int Id, double newBal, double annIntRate){
- Id = NumberOfAccounts+1;
- Balance = newBal;
- AnnualInterestRate = annIntRate;
- NumberOfAccounts++;
- }
- //methods
- public int getId(){
- return Id;
- }
- public double getBalance(){
- return Balance;
- }
- public double getAnnualInterestRate(){
- return AnnualInterestRate;
- }
- public void setID(int newID){
- newID = NumberOfAccounts + 1;
- Id = newID;
- }
- public void setBalance(double newBal){
- if (newBal > 0){
- Balance = newBal;
- }
- else{
- System.out.print("Balance cannot be set below zero");
- }
- }
- public void setAnnualInterestRate(double userAnnualInterestRate){
- if(userAnnualInterestRate > 0){
- AnnualInterestRate = userAnnualInterestRate;
- }
- else{
- System.out.print("You cannot set an interest rate below zero");
- }
- }
- public double getMonthlyInterestRate(){
- return AnnualInterestRate/12;
- }
- public void withdraw(double amount){
- if(amount <= 0){
- System.out.print("You must withdraw an amount greater than zero");
- }
- if(Balance < amount){
- System.out.print("Insufficient funds");
- }
- else{
- Balance = Balance - amount;
- }
- }
- public void deposit(double amount){
- if(amount < 0){
- System.out.print("You must deposit an amount greater than zero");
- }
- else{
- Balance += amount;
- }
- }
- public int getNumberOfAccounts(){
- return NumberOfAccounts;
- }
- public void transfer(Account x, double amount){
- withdraw(amount);
- x.deposit(amount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement