Results 1 to 3 of 3
  1. #1
    loftus727 is offline Member
    Join Date
    Feb 2013
    Posts
    24
    Rep Power
    0

    Default A Flexible Account Class

    I am getting an error I cannot figure out at all in the method...

    here is my code for the class:

    Java Code:
    //*******************************************************
    // FlexibleAccount.java
    //
    // A bank account class with methods to deposit to, withdraw from,
    // change the name on, and get a String representation
    // of the account.
    //*******************************************************
    
       import java.util.Random;
       public class FlexibleAccount
       {
          private double balance;
          private String name;
          private long acctNum;
       
       //----------------------------------------------
       //Constructor -- initializes balance, owner, and account number
       //----------------------------------------------
          public FlexibleAccount(double balance, String name, long acctNum)
          {
             this.balance = balance;
             this.name = name;
             this.acctNum = acctNum;
          }
          public FlexibleAccount(double initBal, String owner, double number)
          {
             Random generator = new Random();
             balance = initBal;
             name = owner;
             number=generator.nextDouble();
             this.acctNum= acctNum;
          }
          public FlexibleAccount(String owner)
          {
             balance = 0;
             name=owner;
             Random generator = new Random();
             acctNum=generator.nextLong();
             this.acctNum= acctNum;
          }
       
       //----------------------------------------------
       // Checks to see if balance is sufficient for withdrawal.
       // If so, decrements balance by amount; if not, prints message.
       //----------------------------------------------
          public void withdraw(double amount, int fee)
          {
    		
    			balance-=fee;
    			
             if (balance >= amount)
                balance -= amount;
             else
                System.out.println("Insufficient funds");
          }
       
       //----------------------------------------------
       // Adds deposit amount to balance.
       //----------------------------------------------
          public void deposit(double amount)
          {
             balance += amount;
          }
       
       //----------------------------------------------
       // Returns balance.
       //----------------------------------------------
          public double getBalance()
          {
             return balance;
          }
       
       
       //----------------------------------------------
       // Returns a string containing the name, account number, and balance.
       //----------------------------------------------
          public String toString()
          {
             return "Name: " + name + 
                "\nAccount Number: " + acctNum +
                "\nBalance: " + balance; 
          }
       }
    and here is my code for the method:

    Java Code:
    //*******************************************************
    // TestAccount.java
    //
    // A simple driver to test the overloaded methods of 
    // the Account class.
    //*******************************************************
    
    import java.util.Scanner;
    
    public class TestAccount
    {
        public static void main(String[] args)
        {
    	String name;
    	double balance;
    	long acctNum;
    	FlexibleAccount acct;
    	int fee;
    
    	Scanner scan = new Scanner(System.in);
    
    	System.out.println("Enter account holder's first name");
    	name = scan.next();
    	acct = new FlexibleAccount(name);
    	System.out.println("Account for " + name + ":");
    	System.out.println(acct);
    	
    	System.out.println("\nEnter initial balance");
    	balance = scan.nextDouble();
    	acct = new FlexibleAccount(balance,name);
    	System.out.println("Account for " + name + ":");
    	System.out.println(acct);
    
    	System.out.println("\nEnter account number");
    	acctNum = scan.nextLong();
    	acct = new FlexibleAccount(balance,name,acctNum);
    	System.out.println("Account for " + name + ":");
    	System.out.println(acct);
    
    	System.out.print("\nDepositing 100 into account, balance is now ");
    	acct.deposit(100);
    	System.out.println(acct.getBalance());
    	System.out.print("\nWithdrawing $25, balance is now ");
    	balance-=25;
    	System.out.println(acct.getBalance());
    	System.out.print("\nWithdrawing $25 with $2 fee, balance is now ");
    	balance -= (25 + fee);
    	System.out.println(acct.getBalance());
    
    	System.out.println("\nBye!");
        }
    }

    and this is the error

    ----jGRASP exec: javac -g TestAccount.java

    TestAccount.java:30: cannot find symbol
    symbol : constructor FlexibleAccount(double,java.lang.String)
    location: class FlexibleAccount
    acct = new FlexibleAccount(balance,name);
    ^
    1 error

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.


    any help would be greatly appreciated!

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: A Flexible Account Class

    TestAccount.java:30: cannot find symbol
    symbol : constructor FlexibleAccount(double,java.lang.String)
    location: class FlexibleAccount
    acct = new FlexibleAccount(balance,name);
    This error occurs because your FlexibleAccount class doesn't have constructor that accept two arguments (double and String). You only have constructors that accept either three arguments or one argument.

    Read more here if your are still confuse with constructor: Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

  3. #3
    loftus727 is offline Member
    Join Date
    Feb 2013
    Posts
    24
    Rep Power
    0

    Default Re: A Flexible Account Class

    That is part of the code that hasnt been changed from what was given to me by my instructor, that is why I am not sure about what to do. I have a slight understanding of constructors, I just can not figure out what to change.

Similar Threads

  1. Designing an Account Class
    By son012189 in forum New To Java
    Replies: 9
    Last Post: 09-05-2013, 09:37 PM
  2. Simple Bank Account Class CRASHES help!
    By xcaldk74 in forum New To Java
    Replies: 1
    Last Post: 02-16-2013, 11:07 PM
  3. Create a java class for a bank account!!?
    By singh345 in forum New To Java
    Replies: 1
    Last Post: 03-17-2010, 05:26 PM
  4. Flexible JTable?
    By Alex04 in forum AWT / Swing
    Replies: 0
    Last Post: 09-21-2009, 08:08 AM
  5. bean with flexible version ability
    By nineball in forum Advanced Java
    Replies: 0
    Last Post: 03-26-2008, 10:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •