   import java.text.*;
/**
* A savings account that does not allow withdrawals
* (except upon graduation) and does not earn interest.
*
* @author Prof. David Bernstein, James Madison University
* @version 0.1 (Stub)
* @author Prof. Elizabeth Adams
* @version 1.0 (implementation)
*/
    public class FixedTermSavingsAccount
   {
   // Attributes of objects
      private double balance;
      private final int accountNumber;
      private NumberFormat accountFormatter;
      private String userName;
      
   // Attributes of the class
      private static int nextAccountNumber;
      private String myString;   // optional
      
   /**
   * Explicit Value Constructor
   *
   * @param user The JMU username of the account holder
   */
       public FixedTermSavingsAccount(String user)
      {
      // Initialize userName
         this.userName = user;
      
      // Initialize the accountNumber
         accountNumber = nextAccountNumber; //nextAccountNumber;
         
      // Update nextAccountNumber for the next object
         nextAccountNumber++;
      
      // Construct and initialize accountFormatter so that
      // it always creates String objects with 10 digits
         accountFormatter = NumberFormat.getInstance();  
         accountFormatter.setMinimumIntegerDigits(10); // 10 digits
         accountFormatter.setGroupingUsed(false); // no commas
      
      // Initialize the balance
         this.balance = 0.0;
      }
      
   /**
   * Compare the account number on this account to the
   * account number on a given account
   *
   * @param other The given account
   * @return -1/1 if this account comes before/after the given account
   */
       public int compareTo(FixedTermSavingsAccount other) // one version
      {  
         int ans; 
         String myTemp, otherTemp;
         myTemp = this.getAccountNumber();
         System.out.println (myTemp + " is my acct #");  	// for debugging
         otherTemp = other.getAccountNumber();
         System.out.println ( otherTemp + " is her acct # "); // for debugging
         if ( myTemp.compareTo(otherTemp) < 0)    		// myTemp - otherTemp 
            ans = -1;
         else
            if(otherTemp.compareTo(myTemp) < 0)  // otherTemp - myTemp
               ans = 1;
            else
               ans = 0; 
         return ans;			   
      }
      
   /**
   * Deposit money into this account
   *
   * @param amount The amount of the deposit (should be positive)
   * @return A message describing the deposit
   */
       public String deposit(double amount)
      {
         String result;
      // If amount <= 0.0 create an error message
      // otherwise create an informational message and
      // increase balance
         if (amount <= 0.0)
            result = " erroneous attempt to deposit negative amount ";
         else
         {
            this.balance = this.balance + amount; 
            	//OR setBalance(this.balance + amount);
            result = " balance updated by amount deposited ";
         }
         return result;          }
      
   /**
   * Get the ID associated with this account
   *
   * The ID consists of the characters "FT-" followed
   * by the 10-digit account number
   *
   * @return The ID
   */
       public String getAccountID()
      {
          // return "FT-0000000000";
         return "FT-" + this.myString;
      	 // OR  "FT-" + accountFormatter.format(getAccountNumber());
      	 // OR  "FT-" + getAccountNumber();  
      } 
      
   /**
   * Get the number associated with this account
   *
   * The number consists of s String containing
   * the 10-digit account number
   *
   * @return The account number
   */
       public String getAccountNumber()
      {
         this.myString = accountFormatter.format (this.accountNumber);
         return this.myString;      //return "0000000000";
         // OR return accountFormatter.format (accountNumber);
      }
      
   /**
   * Get the current balance
   *
   * @return The balance
   */
       public double getBalance()
      {
     			 return this.balance;      //return 0.0; - was default for stub
      }
      
   /**
   * Get a String description of the current balance
   *
   * The description consists of the String "Balance: "
   * followed by the balance (with a leading $, two digits
   * after the decimal place, and a ',' as the grouping character)
   *
   * @return A description of the balance
   */
       public String getBalanceMessage()
      {
         NumberFormat myNumberFormat;
         String myCurrencyString;
      
   		 myNumberFormat = NumberFormat.getCurrencyInstance();
      
         // set fractional digits to 2
         myNumberFormat.setMaximumFractionDigits(2); // only 2 decimal places
         myNumberFormat.setGroupingUsed(true);// insert commas
         myCurrencyString = myNumberFormat.format(this.balance);
         System.out.println
         (myCurrencyString  + " value in getBalanceMessage ");//debugging
         return myCurrencyString;  // return "Balance: $1,000,000.00";stub 
    }
      
   /**
   Get the JMU username of the account holder
   *
   * The STring returned consists of the username (which
   * is 8 characters or less) followed by the String
   * "@jmu.edu"
   *
   * @return The username
   */
       public String getUserName()
      {
      	int temp;
      	String ans; 
      	temp = this.userName.length();
      	if (temp <= 8)
      	   ans =  this.userName + "@jmu.edu";
      	else
      	   ans = this.userName.substring(0,8) + "@jmu.edu";
      	return ans;
      }
      
   /**
   * Set the current balance
   * Note: This method should be used with caution
   * (We'll learn how to fix this later)
   *
   * @param balance The new balance
   */
       public void setBalance(double balance)
      {
         this.balance = balance;
      }
   }
