Syntax error with class definition problem

Syntax error on token "public", class expected after this to

Page 1 of 1

5 Replies - 7616 Views - Last Post: 18 November 2008 - 07:48 PM Rate Topic: -----

#1 simonc  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 17-November 08

Syntax error with class definition problem

Post icon  Posted 18 November 2008 - 12:33 AM

Hi, new to java and am trying to fix a syntax error with a class definition.

The class engine1 is filling an array set with data, which is defined in another class (Timeseries). Could someone let me know what I have to do to fix please, I think its an easy fix but being fresh to oo its been a struggle with no joy. I have included all the code incase you need to see what is happening else where

Thanks for your help
Simon


//**Error on line below 'Syntax error on token "public", class expected after this token'**
public   engine1 {
		  public engine (Timeseries[] MyTimeseries); {
			
			 myTimeseries[0]= {1, 37795, 1.59, 64.84, 1.23, 0, 1.23, 2.39};
			 myTimeseries[1]= {2, 37796, 1.64, 64.84, 1.52, 0, 1.24, 2.45};
			 
			 myTimeseries[1].display();

	}
		 
	}

----------------------------------------------------------------------------------

package StatPairsModel;

public class Timeseries extends Stock {
	private int[] id;
	private int[] date;
	private double[] close_price_euro;
	private double[] close_volume;
	private double[] close_market_cap;
	private int[] corp_action_ind;
	private double[] beta;
	private double[] close_price_local;

	
	public void  setTimeseries(int[] idln, int[] dateln, double[] close_price_euroln,
			double[] close_volumeln, double[] close_market_capln,
			int[] corp_action_indln, double[] betaln,
			double[] close_price_localln) {
		
		id = idln;
		date = dateln;
		close_price_euro = close_price_euroln;
		close_volume = close_volumeln;
		close_market_cap = close_market_capln;
		corp_action_ind = corp_action_indln;
		beta = betaln;
		close_price_local = close_price_localln;

	}
	public void setId(int[] idln) {
		id = idln;
	}
	
	public int[] getId(int[] id) {
		return id;
	}
	
	public void setDate(int[] dateln) {
		date = dateln;
	}
	
	public String[] getDate(String[] date) {
		return date;
	}

	public void setClose_price_euro(double[] close_price_euroln) {
		close_price_euro = close_price_euroln;
	}
	
	public double[] getclose_price_euro(double[] close_price_euro) {
		return close_price_euro;
	}

	public void setClose_volume(double[] close_volumeln) {
		close_volume = close_volumeln;
	}
	
	public double[] getclose_volume(double[] close_volume) {
		return close_volume;
	}

	public void setClose_market_capId(double[] close_market_capln) {
		close_market_cap = close_market_capln;
	}
	
	public double[] getclose_market_cap(double[] close_market_cap) {
		return close_market_cap;
	}

	public void setcorp_action_ind(int[] corp_action_indln) {
		corp_action_ind = corp_action_indln;
	}
	
	public int[] getcorp_action_ind(int[] corp_action_ind) {
		return corp_action_ind;
	}

	public void setbeta(double[] betaln) {
		beta = betaln;
	}
	
	public double[] getbeta(double[] beta) {
		return beta;
	}

	public void setclose_price_local(double[] close_price_localln) {
		close_price_local = close_price_localln;
	}
	
	public double[] getclose_price_local(double[] close_price_local) {
		return close_price_local;
	}
	
	void display() {
		System.out.println(id);
		System.out.println(date);
		System.out.println(close_price_euro);
		System.out.println(close_volume);
		System.out.println(close_market_cap);
		System.out.println(corp_action_ind);
		System.out.println(beta);
		System.out.println(close_price_local);

	}

}

-------------------------------------------------------------------------

public class Engine {
	public static void main(String args[]) {

		int numberOfPairs = 3;

		// for (int i = 0; i<numberOfPairs; i++){
		Stock stock1 = new Stock();
		Stock stock2 = new Stock();

		stock1.setStock("0015425", "Vodafone", "VOD LN", "UK", "TELECOM",
				"GBP", "VOD LN", "FTSE");
		stock2.setStock("0045125", "Telecom Italia", "TIM IM", "IT", "TELECOM",
				"EUR", "TIM IM", "MIB");

		// if(stock1.getSector(sector)==stock2.getSector(sector));

		stock1.setMnemonic("123456");
		stock1.display();
		System.out.println();
		stock2.display();
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Syntax error with class definition problem

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Syntax error with class definition problem

Posted 18 November 2008 - 12:36 AM

The error is specific: you are missing the keyword class.

This post has been edited by n8wxs: 18 November 2008 - 12:39 AM

Was This Post Helpful? 0
  • +
  • -

#3 simonc  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 17-November 08

Re: Syntax error with class definition problem

Posted 18 November 2008 - 01:16 AM

View Postn8wxs, on 17 Nov, 2008 - 11:36 PM, said:

The error is specific: you are missing the keyword class.


thanks, but that seems to open a whole new can of worms, please see below for error messages, not sure what to do, thanks

public  class  engine1 {

public engine (Timeseries[] MyTimeseries); { //This method requires a body instead of a semicolon
			
myTimeseries[0]= {1, 37795, 1.59, 64.84, 1.23, 0, 1.23, 2.39};  //'myTimeseries cannot be resolved'  and  'Array constants can only be used in initializers'
myTimeseries[1]= {2, 37796, 1.64, 64.84, 1.52,	0, 1.234, 2.45}; //'myTimeseries cannot be resolved' and  'Array constants can only be used in initializers'
			 
			 myTimeseries[1].display(); //myTimeseries cannot be resolved

	}
		 
	}


Was This Post Helpful? 0
  • +
  • -

#4 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 284
  • View blog
  • Posts: 1,617
  • Joined: 15-May 08

Re: Syntax error with class definition problem

Posted 18 November 2008 - 01:44 AM

Where is your class Timeseries ?

As in the object you are passing into the function

public engine (Timeseries[] MyTimeseries) ?? ?

As for the errors well i can't help you without the class Timeseries...

Perhaps remember the correct way in java to name classes (they must have a capital first letter)

public  class  Engine
{

	public Engine(Timeseries[] MyTimeseries)
	{ 		        
		MyTimeseries[0]= {1, 37795, 1.59, 64.84, 1.23, 0, 1.23, 2.39};  
		MyTimeseries[1]= {2, 37796, 1.64, 64.84, 1.52,    0, 1.234, 2.45}; 		        
		MyTimeseries[1].display(); 	
	}
}


This throws about the maximum errors possible...
Was This Post Helpful? 0
  • +
  • -

#5 simonc  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 17-November 08

Re: Syntax error with class definition problem

Posted 18 November 2008 - 10:00 AM

The Timeseries class is attached as code at the top in the first part of my post for your reference, thanks
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Syntax error with class definition problem

Posted 18 November 2008 - 07:48 PM

Is the class Engine in the same .java file than Timeseries ?

It is strongly recommended to have class name starting with a capitalized letter but this is not mandatory

This post has been edited by pbl: 18 November 2008 - 07:51 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1