⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 account.java

📁 java源程序 对初学者有很大的帮助 从简单到复杂
💻 JAVA
字号:
//********************************************************************//  Account.java       Author: Lewis/Loftus////  Represents a bank account with basic services such as deposit//  and withdraw.//********************************************************************import java.text.NumberFormat;public class Account{   private NumberFormat fmt = NumberFormat.getCurrencyInstance();   private final double RATE = 0.035;  // interest rate of 3.5%   private long acctNumber;   private double balance;   private String name;   //-----------------------------------------------------------------   //  Sets up the account by defining its owner, account number,   //  and initial balance.   //-----------------------------------------------------------------   public Account (String owner, long account, double initial)   {      name = owner;      acctNumber = account;      balance = initial;   }   //-----------------------------------------------------------------   //  Validates the transaction, then deposits the specified amount   //  into the account. Returns the new balance.   //-----------------------------------------------------------------   public double deposit (double amount)   {      if (amount < 0)  // deposit value is negative      {         System.out.println ();         System.out.println ("Error: Deposit amount is invalid.");         System.out.println (acctNumber + "  " + fmt.format(amount));      }      else         balance = balance + amount;      return balance;   }   //-----------------------------------------------------------------   //  Validates the transaction, then withdraws the specified amount   //  from the account. Returns the new balance.   //-----------------------------------------------------------------   public double withdraw (double amount, double fee)   {      amount += fee;      if (amount < 0)  // withdraw value is negative      {         System.out.println ();         System.out.println ("Error: Withdraw amount is invalid.");         System.out.println ("Account: " + acctNumber);         System.out.println ("Requested: " + fmt.format(amount));      }      else         if (amount > balance)  // withdraw value exceeds balance         {            System.out.println ();            System.out.println ("Error: Insufficient funds.");            System.out.println ("Account: " + acctNumber);            System.out.println ("Requested: " + fmt.format(amount));            System.out.println ("Available: " + fmt.format(balance));         }         else            balance = balance - amount;      return balance;   }   //-----------------------------------------------------------------   //  Adds interest to the account and returns the new balance.   //-----------------------------------------------------------------   public double addInterest ()   {      balance += (balance * RATE);      return balance;   }   //-----------------------------------------------------------------   //  Returns the current balance of the account.   //-----------------------------------------------------------------   public double getBalance ()   {      return balance;   }   //-----------------------------------------------------------------   //  Returns the account number.   //-----------------------------------------------------------------   public long getAccountNumber ()   {      return acctNumber;   }   //-----------------------------------------------------------------   //  Returns a one-line description of the account as a string.   //-----------------------------------------------------------------   public String toString ()   {      return (acctNumber + "\t" + name + "\t" + fmt.format(balance));   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -