Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-05-2008, 09:17 PM
Member
 
Join Date: Dec 2008
Posts: 3
Rep Power: 0
parme is on a distinguished road
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:

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;
		}
		
}


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; 
    }
}


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

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!
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-05-2008, 09:25 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,482
Rep Power: 8
Fubarable is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-05-2008, 09:33 PM
Member
 
Join Date: Dec 2008
Posts: 3
Rep Power: 0
parme is on a distinguished road
Default
oh damn! i'm a fool! thanks!
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-05-2008, 09:34 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,482
Rep Power: 8
Fubarable is on a distinguished road
Default
No problem. Happy coding!
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax error on token "(", ; expected baltimore AWT / Swing 3 10-28-2009 01:19 AM
getting identifier expected error . help me ! victorkeath New To Java 3 11-07-2008 06:49 PM
the dollar sign "$", prints like any other normal char in java like "a" or "*" ? lse123 New To Java 1 10-20-2008 08:35 AM
Identifier expected error vasu18 New To Java 1 01-01-2008 06:49 PM
Error: <identifier> expected barney AWT / Swing 2 07-31-2007 08:38 AM


All times are GMT +2. The time now is 06:45 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org