3 Replies - 3622 Views - Last Post: 12 November 2006 - 07:47 PM Rate Topic: -----

#1 canuckfan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-November 06

Class or interface expected

Posted 12 November 2006 - 01:59 PM

Hello fellows..i need some help here. I've written this stuff and i am getting this error like

java 1 class or interface expected..please forgive me..i am begginer program who requires help. If you guys are able to do so..pin point the error and kind of error i am making. Thanks.

Here are my codes:
public class Vessel
{
 private double xCoord;
 private double yCoord;
 private double velocity;
 private double bearing;

public Vessel(double xCoord, double yCoord, double velocity, double bearing)
	{
		this.setXCoord(xCoord);
		this.setYCoord(yCoord);
		this.setVelocity(velocity);
		this.setBearing(bearing);
	}
 
	public double getXCoord()
	{
		return xCoord;
	}
 
	public boolean setXCoord(double x)
	{
		boolean doSetXcoord = true;
 
		return doSetXcoord;
	}
 
 
	public double getYCoord()
	{
		return yCoord;
	}
 
	public boolean setYCoord(double y)
	{
		if (y <= -1000.0 && y >= 1000.0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
 
	public double getVelocity()
	{
		return velocity;
	}
 
	public boolean setVelocity(double v)
	{
		if (v <= 0.0 && v >= 600.0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
 
	public double getBearing()
	{
		return bearing;
	}
 
	public boolean setBearing(double B)
	{
		if (b <= 0.0 && b >= 360.0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
 
	public String toString
		()
	{
		return "( X-Coordinate = " + xCoord + " Y-Coordinate = " + yCoord + "V-Velocity = " + velocity + " B-Bearing = " + bearing + " )";
	}
 
	public void display()
	{
		System.out.println("(" + this.xCoord + "," + this.yCoord + "," + this.velocity + "," + this.bearing + ")");
	}
}



O yaa and here are the instruction that was given to me..if that helps to help me make understand.

In this assignment you will develop a Vessel class. The Vessel class will represent an ocean-going vessel rather than a freshwater boat. Its characteristics will be modeled as data members for its i) x- and y-coordinates, ii) its velocity, and iii) its direction.
The location of a Vessel object will be determined by the values of its x- and y-coordinates relative to an unspecified, fixed origin. Assume that the units of measure are kilometres. The velocity of a vessel will be stated as km/hour. The direction of the vessel will be measured in degrees using the trigonometric convention. All data members will store decimal values.

edit: added [code] tags ~ jayman9

Is This A Good Question/Topic? 0
  • +

Replies To: Class or interface expected

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 415
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Class or interface expected

Posted 12 November 2006 - 02:34 PM

With the exception of one typo in your setBearing method. You are using uppercase B as your incoming parameter in the constructor, but you use the lowercase b inside the method.
	public boolean setBearing(double B) //change to lowercase
	{
		if (b <= 0.0 && b >= 360.0)



With that one correction it compiles just fine.

Can you post the exact error message you are receiving?
Was This Post Helpful? 0
  • +
  • -

#3 canuckfan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-November 06

Re: Class or interface expected

Posted 12 November 2006 - 04:37 PM

No problem. My error now is something like this:

Error: class Vessel is public, should be declared in a file named Vessel.java

cheers:

Btw here is my method main()

public class MyVessel

{

public static void main(String[] arg)
{

Vessel vessel007 = new Vessel (300.0, 500.0, 100.0, 250.0);

{
System.out.println(vessel007.toString());
}

}
}
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 247
  • View blog
  • Posts: 13,505
  • Joined: 12-July 02

Re: Class or interface expected

Posted 12 November 2006 - 07:47 PM

That error indicates that your file (the one in which the code is written) is named something different than the class itself. What is the file name? As noted by the compiler, it needs to be Vessel.java.

I'm assuming there is more to the code, as there is no Vessel class listed here.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1