Results 1 to 4 of 4
  1. #1
    parme is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default error"<identifier> expected" trough the use of interface

    Hi guys! I have a problem with my project!
    I write 4 different class: 1-BankAccount 2-DataSet 3-Tester 4-Measurable. the last is an interface(i'm sorry for my bad english) .
    the 4 class are the followings:

    Java Code:
    public class BankAccount implements Measurable
    	{ 
    
    	private double balance;
    	private int count_number;
    	public BankAccount(int value)
    		{ 
    		count_number = value; 
    		balance = 0;
    		}
    		
    		public BankAccount(int value, double quantity)
    		{ 
    		count_number = value; 
    		balance = quantity;
    		}
    		
    	public void deposit(double amount)
    		{
    		double newBalance = balance + amount;
    		balance = newBalance;
    		}
    	public void withdrown(double amount)
    		{
    		if (balance<amount){System.out.println("Valore troppo grande");}
    		double newBalance = balance - amount;
    		balance = newBalance;
    		}
    	public double getMeasure()
    		{
    		return balance;
    		}
    			
    		public double countNumber()
    		{
    		return count_number;
    		}
    		
    }


    Java Code:
    public class DataSet
    {
        // instance variables - replace the example below with your own
        private double sum = 0;
        private Measurable maximum;
        private int count=0;
        
        public DataSet( Measurable x)
        {
       
        }
        
        public void add(Measurable x)
        {
         sum = sum + x.getMeasure();
         if (sum==0 || maximum.getMeasure()<x.getMeasure() ){maximum = x;}
        }
        public Measurable getMaximum()
        {
        return maximum; 
        }
    }


    Java Code:
    public class Tester
    {
     DataSet tester = new DataSet(new BankAccount(0)) ;
     tester.add( new BankAccount(1000) );
     tester.add(new BankAccount(2000) );
     tester.add(new BankAccount(3000));
     Measurable max = tester.getMaximum();
     double n = max.getMeasure();
     
     
    }
    and the last

    Java Code:
    public interface Measurable
    {
    double getMeasure();
    }


    when i compile BankAccount,DataSet and the interface i find no problem but when i compile the Tester I erceive the following error
    "<identifier> expected"
    what's wrong?
    thanks!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Tester has many lines of code just hanging out naked in the class that shouldn't be located where they've been placed. They need to be located inside of a method or constructor or static initializer block or similar beast.

    Perhaps you wanted to put those lines in a main method?

  3. #3
    parme is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default

    oh damn! i'm a fool! thanks!:)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Syntax error on token "(", ; expected
    By baltimore in forum AWT / Swing
    Replies: 3
    Last Post: 10-28-2009, 01:19 AM
  2. getting identifier expected error . help me !
    By victorkeath in forum New To Java
    Replies: 3
    Last Post: 11-07-2008, 06:49 PM
  3. Replies: 1
    Last Post: 10-20-2008, 08:35 AM
  4. Identifier expected error
    By vasu18 in forum New To Java
    Replies: 1
    Last Post: 01-01-2008, 06:49 PM
  5. Error: <identifier> expected
    By barney in forum AWT / Swing
    Replies: 2
    Last Post: 07-31-2007, 08:38 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
  •