COMPILE ERRORS

need help correcting errors in my code

  • (2 Pages)
  • +
  • 1
  • 2

26 Replies - 3272 Views - Last Post: 23 January 2010 - 11:08 AM Rate Topic: -----

#1 vrichh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 21-December 09

COMPILE ERRORS

Posted 20 January 2010 - 01:18 PM

The code i have written is for a customer to be able to choose the kind of wood that they would like for the table they have chosen. I've recieved 5 compile errors as follows,


C:\JAVA\Furniture.java:50: cannot find symbol
symbol : method setType(int)
location: class Furniture
woodFurniture.setType(furnitureType);
^
C:\JAVA\Furniture.java:51: cannot find symbol
symbol : method setRate(double)
location: class Furniture
woodFurniture.setRate(chosenRate);
^
C:\JAVA\Furniture.java:54: cannot find symbol
symbol : variable woodType
location: class Furniture
System.out.println("You entered " + woodType +
^
C:\JAVA\Furniture.java:58: cannot find symbol
symbol : method getType()
location: class Furniture
System.out.println("Wood: " + woodFurniture.getType() +
^
C:\JAVA\Furniture.java:59: cannot find symbol
symbol : method getRate()
location: class Furniture
" Cost: " + woodFurniture.getRate());
^
5 errors

I cannot seem to figure out how to correct these errors, as i am still fairly new to java, and was wondering if anyone had advice on how to correct them. Thank you.




import java.util.Scanner;
public class Furniture
{
	public static void main(String[] args)
	{

		int furnitureType;
		String chosenWood = " ";
		double chosenRate = 0;
		Furniture woodFurniture = new Furniture();
		final int PINE_CODE = 1;
		final int OAK_CODE = 2;
		final int MAHOGANY_CODE = 3;
		final String PINE_WOOD = "Pine table";
		final String OAK_WOOD = "Oak table";
		final String MAHOGANY_WOOD = "Mahogany table";
		final double PINE_RATE = 100.00;
		final double OAK_RATE = 225.00;
		final double MAHOGANY_RATE = 310.00;
		boolean choiceIsGood = true;

	
		Scanner input =  new Scanner(System.in);
		System.out.println("What type of wood table are you looking for?");
		System.out.println("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table..."); 
		
		furnitureType = input.nextInt(); 
		if (furnitureType == PINE_CODE)
		{
			chosenWood = PINE_WOOD;
			chosenRate = PINE_RATE;
		}
		else
			if (furnitureType == OAK_CODE)
			{
				chosenWood = OAK_WOOD;
				chosenRate = OAK_RATE;
			}
			else
				if (furnitureType == MAHOGANY_CODE)
				{
					chosenWood = MAHOGANY_WOOD;
					chosenRate = MAHOGANY_RATE;
				}
				else
					choiceIsGood = false;
					
					if (choiceIsGood)
					{
						woodFurniture.setType(furnitureType);
						woodFurniture.setRate(chosenRate);
					}
					else
						System.out.println("You entered " + woodType + 
							" which is invalid.");
							
							System.out.println("You have chosen:");
							System.out.println("Wood: " + woodFurniture.getType() +
								" Cost: " + woodFurniture.getRate());
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: COMPILE ERRORS

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

Re: COMPILE ERRORS

Posted 20 January 2010 - 01:22 PM

Where are all of Furniture's methods?
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10570
  • View blog
  • Posts: 39,137
  • Joined: 27-December 08

Re: COMPILE ERRORS

Posted 20 January 2010 - 01:22 PM

Your compiler is telling you that the methods you are trying to invoke setRate(), setType(), etc. and the variable woodType haven't been defined before you reference them, so they don't exist. You need to define them in your class before you can use them.
Was This Post Helpful? 1
  • +
  • -

#4 vrichh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 21-December 09

Re: COMPILE ERRORS

Posted 20 January 2010 - 01:23 PM

View PostKYA, on 20 Jan, 2010 - 12:22 PM, said:

Where are all of Furniture's methods?



i don't know what you mean by that?
I'm fairly new to java...
Was This Post Helpful? 0
  • +
  • -

#5 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2873
  • View blog
  • Posts: 11,032
  • Joined: 15-July 08

Re: COMPILE ERRORS

Posted 20 January 2010 - 01:23 PM

Well, you have this:
import java.util.Scanner;
public class Furniture
{
	public static void main(String[] args)
	{
		...
	}
}



You have a Furniture class which contains the main method, but none otheres, so that when you call the Furniture's setAnything() method, it doesn't exist. you need to add those methods to this class.

Well, dern it! My edit disappeared. I was going to help clarify.
import java.util.Scanner;
public class Furniture
{
	public static void main(String[] args)
	{
		...
	}
  
	public void setRate(int rate)
	{
		... Do stuff in here
	}
}



Since you define a setRate method in Furniture, you have to have it defined and implemented! Now try it with the other methods that you need. If this is confusing, read up on methods.

This post has been edited by Dogstopper: 20 January 2010 - 01:31 PM

Was This Post Helpful? 1
  • +
  • -

#6 vrichh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 21-December 09

Re: COMPILE ERRORS

Posted 20 January 2010 - 02:34 PM

Okay so i did what was asked(i think) but now im getting other errors.

import java.util.Scanner;
public class Furniture
{
		
		int typeOfFurniture;
		String chosenWood = " ";
		double chosenRate = 0;
		Furniture woodFurniture = new Furniture();
		final int PINE_CODE = 1;
		final int OAK_CODE = 2;
		final int MAHOGANY_CODE = 3;
		final String PINE_WOOD = "Pine table";
		final String OAK_WOOD = "Oak table";
		final String MAHOGANY_WOOD = "Mahogany table";
		final double PINE_RATE = 100.00;
		final double OAK_RATE = 225.00;
		final double MAHOGANY_RATE = 310.00;
		boolean choiceIsGood = true;
	
	public int getType()
	{
		return typeOfFurniture;
	}
	public double getRate()
	{
		return chosenRate;
	}
	public void setType(int furnitureType)
	{
		typeOfFurniture = furnitureType;
	}
	public void setRate(double rate)
	{
		chosenRate = rate;
	}
		
			
	
		Scanner input =  new Scanner(System.in);
		System.out.print("What type of wood table are you looking for?");
		System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table..."); 
		
		furnitureType = input.nextInt(); 
		if (furnitureType == PINE_CODE)
		{
			chosenWood = PINE_WOOD;
			chosenRate = PINE_RATE;
		}
		else
			if (furnitureType == OAK_CODE)
			{
				chosenWood = OAK_WOOD;
				chosenRate = OAK_RATE;
			}
			else
				if (furnitureType == MAHOGANY_CODE)
				{
					chosenWood = MAHOGANY_WOOD;
					chosenRate = MAHOGANY_RATE;
				}
				else
					choiceIsGood = false;
					
					if (choiceIsGood)
					{
						woodFurniture.setType(furnitureType);
						woodFurniture.setRate(chosenRate);
					}
					else
						System.out.println("You entered " + woodType + 
							" which is invalid.");
							
							System.out.println("You have chosen:");
							System.out.println("Wood: " + woodFurniture.getType() +
								" Cost: " + woodFurniture.getRate());
	}
}





Theres 36 errors so...?

HELP?

C:\JAVA\Furniture.java:40: <identifier> expected
System.out.print("What type of wood table are you looking for?");
^
C:\JAVA\Furniture.java:40: illegal start of type
System.out.print("What type of wood table are you looking for?");
^
C:\JAVA\Furniture.java:41: <identifier> expected
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:41: illegal start of type
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:41: ')' expected
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:41: ';' expected
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:41: illegal start of type
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:41: <identifier> expected
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:41: ';' expected
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:41: <identifier> expected
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:41: illegal start of type
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:41: <identifier> expected
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:41: ';' expected
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:41: illegal start of type
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:41: <identifier> expected
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:41: ';' expected
System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table...");
^
C:\JAVA\Furniture.java:43: <identifier> expected
furnitureType = input.nextInt();
^
C:\JAVA\Furniture.java:44: illegal start of type
if (furnitureType == PINE_CODE)
^
C:\JAVA\Furniture.java:44: <identifier> expected
if (furnitureType == PINE_CODE)
^
C:\JAVA\Furniture.java:44: ';' expected
if (furnitureType == PINE_CODE)
^
C:\JAVA\Furniture.java:44: illegal start of type
if (furnitureType == PINE_CODE)
^
C:\JAVA\Furniture.java:44: <identifier> expected
if (furnitureType == PINE_CODE)
^
C:\JAVA\Furniture.java:45: ';' expected
{
^
C:\JAVA\Furniture.java:46: illegal start of type
chosenWood = PINE_WOOD;
^
C:\JAVA\Furniture.java:47: <identifier> expected
chosenRate = PINE_RATE;
^
C:\JAVA\Furniture.java:49: class, interface, or enum expected
else
^
C:\JAVA\Furniture.java:53: class, interface, or enum expected
chosenRate = OAK_RATE;
^
C:\JAVA\Furniture.java:54: class, interface, or enum expected
}
^
C:\JAVA\Furniture.java:59: class, interface, or enum expected
chosenRate = MAHOGANY_RATE;
^
C:\JAVA\Furniture.java:60: class, interface, or enum expected
}
^
C:\JAVA\Furniture.java:64: class, interface, or enum expected
if (choiceIsGood)
^
C:\JAVA\Furniture.java:67: class, interface, or enum expected
woodFurniture.setRate(chosenRate);
^
C:\JAVA\Furniture.java:68: class, interface, or enum expected
}
^
C:\JAVA\Furniture.java:73: class, interface, or enum expected
System.out.println("You have chosen:");
^
C:\JAVA\Furniture.java:74: class, interface, or enum expected
System.out.println("Wood: " + woodFurniture.getType() +
^
C:\JAVA\Furniture.java:76: class, interface, or enum expected
}
^
36 errors
Was This Post Helpful? 0
  • +
  • -

#7 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: COMPILE ERRORS

Posted 20 January 2010 - 02:36 PM

Check your brackets, this usually occurs when you have one less or one too many. Usually less though. Match up each bracket to a bracket and you will find you are either short a bracket or over.
Was This Post Helpful? 0
  • +
  • -

#8 vrichh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 21-December 09

Re: COMPILE ERRORS

Posted 20 January 2010 - 02:52 PM

OKAY FINALLY, alright so i have no more compile errors which is fabulous, but ive run into another problem
when i run the application in msdos all i get is: java.lang.NoSuchMethodError: main
Exception in thread "main"

What does that mean and where have i gone wrong now?

import java.util.Scanner;
public class Furniture
{
		
		int furnitureType;
		String chosenWood = " ";
		double chosenRate = 0;
		Furniture woodFurniture = new Furniture();
		final int PINE_CODE = 1;
		final int OAK_CODE = 2;
		final int MAHOGANY_CODE = 3;
		final String PINE_WOOD = "Pine table";
		final String OAK_WOOD = "Oak table";
		final String MAHOGANY_WOOD = "Mahogany table";
		final double PINE_RATE = 100.00;
		final double OAK_RATE = 225.00;
		final double MAHOGANY_RATE = 310.00;
		boolean choiceIsGood = true;
	
	public int getType()
	{
		return furnitureType;
	}
	public double getRate()
	{
		return chosenRate;
	}
	public void setType(int furniType)
	{
		furnitureType = furniType;
	}
	public void setRate(double rate)
	{
		chosenRate = rate;
	}
		
			
	{
		Scanner input =  new Scanner(System.in);
		System.out.print("What type of wood table are you looking for?");
		System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table..."); 
		
		furnitureType = input.nextInt(); 
		if (furnitureType == PINE_CODE)
		{
			chosenWood = PINE_WOOD;
			chosenRate = PINE_RATE;
		}
		else
			if (furnitureType == OAK_CODE)
			{
				chosenWood = OAK_WOOD;
				chosenRate = OAK_RATE;
			}
			else
				if (furnitureType == MAHOGANY_CODE)
				{
					chosenWood = MAHOGANY_WOOD;
					chosenRate = MAHOGANY_RATE;
				}
				else
					choiceIsGood = false;
					
					if (choiceIsGood)
					{
						woodFurniture.setType(furnitureType);
						woodFurniture.setRate(chosenRate);
					}
					else
						System.out.println("You entered " + furnitureType + 
							" which is invalid.");
							
							System.out.println("You have chosen:");
							System.out.println("Wood: " + woodFurniture.getType() +
								" Cost: " + woodFurniture.getRate());
		}
	}


Was This Post Helpful? 0
  • +
  • -

#9 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: COMPILE ERRORS

Posted 20 January 2010 - 03:14 PM

You need a main method (either in your Furniture class, or in a separate class which uses the Furniture class)
public static void main(String[] args)
{
   Furniture f = new Furniture();
   //do stuff with f
}


Was This Post Helpful? 1
  • +
  • -

#10 vrichh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 21-December 09

Re: COMPILE ERRORS

Posted 20 January 2010 - 03:37 PM

when i put public static void main(String[] args) where it would usually go, i get compile errors.
am i putting in the right spot? Or am i missing something?

import java.util.Scanner;
public class Furniture
{
	public static void main(String[] args);
	  {
		int furnitureType;
		String chosenWood = " ";
		double chosenRate = 0;
		Furniture woodFurniture = new Furniture();
		final int PINE_CODE = 1;
		final int OAK_CODE = 2;
		final int MAHOGANY_CODE = 3;
		final String PINE_WOOD = "Pine table";
		final String OAK_WOOD = "Oak table";
		final String MAHOGANY_WOOD = "Mahogany table";
		final double PINE_RATE = 100.00;
		final double OAK_RATE = 225.00;
		final double MAHOGANY_RATE = 310.00;
		boolean choiceIsGood = true;
	
	public int getType()
	{
		return furnitureType;
	}
	public double getRate()
	{
		return chosenRate;
	}
	public void setType(int furniType)
	{
		furnitureType = furniType;
	}
	public void setRate(double rate)
	{
		chosenRate = rate;
	}
		
	
	{
		Scanner input =  new Scanner(System.in);
		System.out.print("What type of wood table are you looking for?");
		System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table..."); 
	
		
		furnitureType = input.nextInt(); 
		if (furnitureType == PINE_CODE)
		{
			chosenWood = PINE_WOOD;
			chosenRate = PINE_RATE;
		}
		else
			if (furnitureType == OAK_CODE)
			{
				chosenWood = OAK_WOOD;
				chosenRate = OAK_RATE;
			}
			else
				if (furnitureType == MAHOGANY_CODE)
				{
					chosenWood = MAHOGANY_WOOD;
					chosenRate = MAHOGANY_RATE;
				}
				else
					choiceIsGood = false;
					
					if (choiceIsGood)
					{
						woodFurniture.setType(furnitureType);
						woodFurniture.setRate(chosenRate);
					}
					else
						System.out.println("You entered " + furnitureType + 
							" which is invalid.");
							
							System.out.println("You have chosen:");
							System.out.println("Wood: " + woodFurniture.getType() +
								" Cost: " + woodFurniture.getRate());
		}
	}





C:\JAVA\Furniture.java:21: illegal start of expression
public int getType()
^
C:\JAVA\Furniture.java:21: ';' expected
public int getType()
^
C:\JAVA\Furniture.java:25: illegal start of expression
public double getRate()
^
C:\JAVA\Furniture.java:25: ';' expected
public double getRate()
^
C:\JAVA\Furniture.java:29: illegal start of expression
public void setType(int furniType)
^
C:\JAVA\Furniture.java:29: illegal start of expression
public void setType(int furniType)
^
C:\JAVA\Furniture.java:29: ';' expected
public void setType(int furniType)
^
C:\JAVA\Furniture.java:29: ';' expected
public void setType(int furniType)
^
C:\JAVA\Furniture.java:33: illegal start of expression
public void setRate(double rate)
^
C:\JAVA\Furniture.java:33: illegal start of expression
public void setRate(double rate)
^
C:\JAVA\Furniture.java:33: ';' expected
public void setRate(double rate)
^
C:\JAVA\Furniture.java:33: ';' expected
public void setRate(double rate)
^
12 errors
Was This Post Helpful? 0
  • +
  • -

#11 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: COMPILE ERRORS

Posted 20 January 2010 - 03:42 PM

It is illegal to define methods inside the main method. You must define them outside of it.

public class Furniture
{
	public static void main(String[] args)
	{
		//all the good stuff in main
	 }
	 public void some method(){}
	 public void someOtherMethod(){}
	 //etc
}


even better, take Fuzzyness' advice and create a tester class

This post has been edited by erik.price: 20 January 2010 - 03:51 PM

Was This Post Helpful? 0
  • +
  • -

#12 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: COMPILE ERRORS

Posted 20 January 2010 - 03:46 PM

You got it backwards buddy. All of that belongs in the class, you cant just make your entire body a main method. Think of it like this.
We have a computer Program. But it is useless without a computer correct? So pretty much the main method will act as a computer which makes everything go. You can have a main in that class, just has to be on its own method, and cannot have a method inside of a method ye know? Generally we like to create a tester class for things so lets do that.
Option 1:
public class FurnitureTester
{
	 public static void main(String args[])
	 { 
		  Furniture test1 = new Furniture();
	 }
}


Option 2:
public static void main(String[] args); remove the semi-colon and make the method on its own by placing the main method form above, in furniture class.

This post has been edited by Fuzzyness: 20 January 2010 - 03:47 PM

Was This Post Helpful? 1
  • +
  • -

#13 tormentor  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 02-January 10

Re: COMPILE ERRORS

Posted 20 January 2010 - 03:51 PM

View Postvrichh, on 20 Jan, 2010 - 02:37 PM, said:

when i put public static void main(String[] args) where it would usually go, i get compile errors.
am i putting in the right spot? Or am i missing something?

import java.util.Scanner;
public class Furniture
{
	public static void main(String[] args);
	  {
		int furnitureType;
		String chosenWood = " ";
		double chosenRate = 0;
		Furniture woodFurniture = new Furniture();
		final int PINE_CODE = 1;
		final int OAK_CODE = 2;
		final int MAHOGANY_CODE = 3;
		final String PINE_WOOD = "Pine table";
		final String OAK_WOOD = "Oak table";
		final String MAHOGANY_WOOD = "Mahogany table";
		final double PINE_RATE = 100.00;
		final double OAK_RATE = 225.00;
		final double MAHOGANY_RATE = 310.00;
		boolean choiceIsGood = true;
	
	public int getType()
	{
		return furnitureType;
	}
	public double getRate()
	{
		return chosenRate;
	}
	public void setType(int furniType)
	{
		furnitureType = furniType;
	}
	public void setRate(double rate)
	{
		chosenRate = rate;
	}
		
	
	{
		Scanner input =  new Scanner(System.in);
		System.out.print("What type of wood table are you looking for?");
		System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table..."); 
	
		
		furnitureType = input.nextInt(); 
		if (furnitureType == PINE_CODE)
		{
			chosenWood = PINE_WOOD;
			chosenRate = PINE_RATE;
		}
		else
			if (furnitureType == OAK_CODE)
			{
				chosenWood = OAK_WOOD;
				chosenRate = OAK_RATE;
			}
			else
				if (furnitureType == MAHOGANY_CODE)
				{
					chosenWood = MAHOGANY_WOOD;
					chosenRate = MAHOGANY_RATE;
				}
				else
					choiceIsGood = false;
					
					if (choiceIsGood)
					{
						woodFurniture.setType(furnitureType);
						woodFurniture.setRate(chosenRate);
					}
					else
						System.out.println("You entered " + furnitureType + 
							" which is invalid.");
							
							System.out.println("You have chosen:");
							System.out.println("Wood: " + woodFurniture.getType() +
								" Cost: " + woodFurniture.getRate());
		}
	}





C:\JAVA\Furniture.java:21: illegal start of expression
public int getType()
^
C:\JAVA\Furniture.java:21: ';' expected
public int getType()
^
C:\JAVA\Furniture.java:25: illegal start of expression
public double getRate()
^
C:\JAVA\Furniture.java:25: ';' expected
public double getRate()
^
C:\JAVA\Furniture.java:29: illegal start of expression
public void setType(int furniType)
^
C:\JAVA\Furniture.java:29: illegal start of expression
public void setType(int furniType)
^
C:\JAVA\Furniture.java:29: ';' expected
public void setType(int furniType)
^
C:\JAVA\Furniture.java:29: ';' expected
public void setType(int furniType)
^
C:\JAVA\Furniture.java:33: illegal start of expression
public void setRate(double rate)
^
C:\JAVA\Furniture.java:33: illegal start of expression
public void setRate(double rate)
^
C:\JAVA\Furniture.java:33: ';' expected
public void setRate(double rate)
^
C:\JAVA\Furniture.java:33: ';' expected
public void setRate(double rate)
^
12 errors


you need to have it like this
 class PassByValue 
{   // open class
	public static void main(String[] args) 
   {  //  open  main 
		double one = 1.0;
		
		System.out.println("before: one = " + one);
		halveIt(one);
		System.out.println("after: one = " + one);
	} // close main 

	// your methods need to have the static keyword if you are using them  in the same class main is
	public static void halveIt(double arg)
		  {
		arg /= 2.0;	 // divide arg by two
		System.out.println("halved: arg = " + arg);
		  }

}// close class 




notice the static keyword in the method
Was This Post Helpful? 1
  • +
  • -

#14 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: COMPILE ERRORS

Posted 20 January 2010 - 10:03 PM

Indent your code correctlyt and it will become obvious
Beside the ; that terminates
public static void main(String[] args);
and that shouldn't be there... you will see that your main() method contains other methods... you can't do that
also... all your variables are defined within the main method... they cannot be seen by other methods... all these variables should be variables defined as instance variables of your class
The main() method in a Java class should have only a few lines... creating a new object by instantiating a new instance of the class


	public static void main(String[] args)
	{
		int furnitureType;
		String chosenWood = " ";
		double chosenRate = 0;
		Furniture woodFurniture = new Furniture();
		final int PINE_CODE = 1;
		final int OAK_CODE = 2;
		final int MAHOGANY_CODE = 3;
		final String PINE_WOOD = "Pine table";
		final String OAK_WOOD = "Oak table";
		final String MAHOGANY_WOOD = "Mahogany table";
		final double PINE_RATE = 100.00;
		final double OAK_RATE = 225.00;
		final double MAHOGANY_RATE = 310.00;
		boolean choiceIsGood = true;

		public int getType()
		{
			return furnitureType;
		}
		public double getRate()
		{
			


class Furniture {
	int furnitureType;
	String chosenWood = " ";
	double chosenRate = 0;
	Furniture woodFurniture = new Furniture();
	final int PINE_CODE = 1;
	final int OAK_CODE = 2;
	final int MAHOGANY_CODE = 3;
	final String PINE_WOOD = "Pine table";
	final String OAK_WOOD = "Oak table";
	final String MAHOGANY_WOOD = "Mahogany table";
	final double PINE_RATE = 100.00;
	final double OAK_RATE = 225.00;
	final double MAHOGANY_RATE = 310.00;
	boolean choiceIsGood = true;

				public static void main(String[] args) {
				   Furniture f = new Furniture();
				   ....
				}
}


Was This Post Helpful? 0
  • +
  • -

#15 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: COMPILE ERRORS

Posted 21 January 2010 - 01:28 PM

Here is your complete code

import java.util.Scanner;
public class Furniture
{

	int furnitureType;
	String chosenWood = " ";
	double chosenRate = 0;
	Furniture woodFurniture = new Furniture();
	final int PINE_CODE = 1;
	final int OAK_CODE = 2;
	final int MAHOGANY_CODE = 3;
	final String PINE_WOOD = "Pine table";
	final String OAK_WOOD = "Oak table";
	final String MAHOGANY_WOOD = "Mahogany table";
	final double PINE_RATE = 100.00;
	final double OAK_RATE = 225.00;
	final double MAHOGANY_RATE = 310.00;
	boolean choiceIsGood = true;

	public int getType()
	{
		return furnitureType;
	}
	public double getRate()
	{
		return chosenRate;
	}
	public void setType(int furniType)
	{
		furnitureType = furniType;
	}
	public void setRate(double rate)
	{
		chosenRate = rate;
	}
	 
	   public Furniture

	{
		Scanner input =  new Scanner(System.in);
		System.out.print("What type of wood table are you looking for?");
		System.out.print("Enter " + PINE_CODE + " for Pine table " + OAK_CODE + " for Oak table, or " + MAHOGANY_CODE + " for Mahogany table..."); 

		furnitureType = input.nextInt(); 
		if (furnitureType == PINE_CODE)
		{
			chosenWood = PINE_WOOD;
			chosenRate = PINE_RATE;
		}
		else
			if (furnitureType == OAK_CODE)
			{
				chosenWood = OAK_WOOD;
				chosenRate = OAK_RATE;
			}
			else
				if (furnitureType == MAHOGANY_CODE)
				{
					chosenWood = MAHOGANY_WOOD;
					chosenRate = MAHOGANY_RATE;
				}
				else
					choiceIsGood = false;

		if (choiceIsGood)
		{
			woodFurniture.setType(furnitureType);
			woodFurniture.setRate(chosenRate);
		}
		else
			System.out.println("You entered " + furnitureType + 
					" which is invalid.");

		System.out.println("You have chosen:");
		System.out.println("Wood: " + woodFurniture.getType() +
				" Cost: " + woodFurniture.getRate());
	}
	
	public static void main(String[] args) {
		Furniture f = new Furniture();
	}
}



This post has been edited by pbl: 21 January 2010 - 02:27 PM

Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2