COMPILE ERRORS

need help correcting errors in my code

  • (2 Pages)
  • +
  • 1
  • 2

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

#16 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon



Reputation: 2707
  • View blog
  • Posts: 10,579
  • Joined: 15-July 08

Re: COMPILE ERRORS

Posted 21 January 2010 - 01:58 PM

Except that pbl made a slight typo...nothing major.
	 public void setRate(double rate)
	{
		chosenRate = rate;
	}

	// DECLARE THE CONSTRUCTOR
	 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..."); 




You need to name every code block... ;)
Was This Post Helpful? 0
  • +
  • -

#17 pbl  Icon User is offline

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

Reputation: 8066
  • View blog
  • Posts: 31,310
  • Joined: 06-March 08

Re: COMPILE ERRORS

Posted 21 January 2010 - 02:27 PM

View PostDogstopper, on 21 Jan, 2010 - 12:58 PM, said:

Except that pbl made a slight typo...nothing major.
	 public void setRate(double rate)
	{
		chosenRate = rate;
	}

	// DECLARE THE CONSTRUCTOR
	 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..."); 




You need to name every code block... ;)

Corrected thanks
Was This Post Helpful? 0
  • +
  • -

#18 vrichh  Icon User is offline

  • New D.I.C Head

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

Re: COMPILE ERRORS

Posted 22 January 2010 - 01:15 PM

okay so, i then had to make a second class with a size selection included.
I think i did everything okay except i get one compile error:
I can't seem to fix this, any suggestions?

C:\JAVA\Furniture22.java:48: '(' expected
{
^
1 error





import java.util.Scanner;
public class Furniture
{

	int furnitureType;
	String chosenWood = " ";
	double chosenRate = 0;
	 char chosenSize;
	Furniture woodFurniture = new Furniture();
	final int PINE_CODE = 1;
	final int OAK_CODE = 2;
	final int MAHOGANY_CODE = 3;
	 final char LARGE_TABLE = 'L';
	 final char SMALL_TABLE = 'S';
	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 PINE_RATE_LARGE = 135.00;
	final double OAK_RATE = 225.00;
	 final double OAK_RATE_LARGE = 260.00;
	final double MAHOGANY_RATE = 310.00;
	 final double MAHOGANY_RATE_LARGE = 345.00;
	boolean choiceIsGood = true;

	public int getType()
	{
		return furnitureType;
	}
	 public char getSize();
	 {
	 	return chosenSize;
	} 
	public double getRate()
	{
		return chosenRate;
	}
	public void setType(int furniType)
	{
		furnitureType = furniType;
	}
	public void setRate(double rate)
	{
		chosenRate = rate;
	}
	 
	   public void Furniture
	 {
		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..."); 
		  System.out.printin("You have chosen " + chosenWood +".");
		  Scanner input =  new Scanner(System.in);
		  System.out.println("What size are you looking for?");
		  System.out.print("Enter " + SIZE_LARGE + "for a large table, or " + SIZE_SMALL + "for a small table.");
		furnitureType = input.nextInt(); 
		if (furnitureType == PINE_CODE)
		{
			chosenWood = PINE_WOOD;
				if(chosenSize = SIZE_LARGE);
					chosenRate = PINE_RATE_LARGE;
				if(chosenSize = SIZE_SMALL);		
					chosenRate = PINE_RATE;
		}
		else
			if (furnitureType == OAK_CODE)
			{		
					   chosenWood = OAK_WOOD;
					 if(chosenSize = SIZE_LARGE);
					 chosenRate = OAK_RATE_LARGE;
					 if(chosenSize = SIZE_SMALL);
				chosenRate = OAK_RATE;
			}
			else
				if (furnitureType == MAHOGANY_CODE)
				{
					chosenWood = MAHOGANY_WOOD;
						 if(chosenSize = SIZE_LARGE);
						 	chosenRate = MAHOGANY_RATE_LARGE;
						 if(chosenRate = SIZE_SMALL);
					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 a" + chosenSize + "table" +  woodFurniture.getType() +
				" which will cost: " + woodFurniture.getRate());
	  ;
	}
	
	public static void main(String[] args) {
		Furniture f = new Furniture();
	}
}


Was This Post Helpful? 0
  • +
  • -

#19 vrichh  Icon User is offline

  • New D.I.C Head

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

Re: COMPILE ERRORS

Posted 22 January 2010 - 01:45 PM

or if i take away the void from between public and furniture it tells me <identifer> expected....?



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)
			{
	 				System.out.println("You have chosen Oak wood which will cost");		
						
					 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();
	}
}





C:\JAVA\Furniture.java:37: <identifier> expected
public Furniture


along with 39 other errors lol.... im so lost. HELP.
Was This Post Helpful? 0
  • +
  • -

#20 vrichh  Icon User is offline

  • New D.I.C Head

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

Re: COMPILE ERRORS

Posted 22 January 2010 - 02:04 PM

oh my i feel like such a moron.
Im posting the wrong code!!!!!



import java.util.Scanner;
public class Furniture22
{

	int furnitureType;
	String chosenWood = " ";
	double chosenRate = 0;
	 char chosenSize;
	Furniture woodFurniture = new Furniture();
	final int PINE_CODE = 1;
	final int OAK_CODE = 2;
	final int MAHOGANY_CODE = 3;
	 final char LARGE_TABLE = 'L';
	 final char SMALL_TABLE = 'S';
	 final String LARGE_NAME = "Large";
	 final String SMALL_NAME = "Small";
	final String PINE_WOOD = "Pine";
	final String OAK_WOOD = "Oak";
	final String MAHOGANY_WOOD = "Mahogany";
	final double PINE_RATE = 100.00;
	 final double PINE_RATE_LARGE = 135.00;
	final double OAK_RATE = 225.00;
	 final double OAK_RATE_LARGE = 260.00;
	final double MAHOGANY_RATE = 310.00;
	 final double MAHOGANY_RATE_LARGE = 345.00;
	boolean choiceIsGood = true;

	public int getType()
	{
		return furnitureType;
	}
	 public char getSize()
	 {
	 	return chosenSize;
	} 
	public double getRate()
	{
		return chosenRate;
	}
	public void setType(int furniType)
	{
		furnitureType = furniType;
	}
	public void setRate(double rate)
	{
		chosenRate = rate;
	}
	 
	   public void Furniture()
	 {
		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..."); 
		  System.out.println("You have chosen " + chosenWood +".");

		  System.out.println("What size are you looking for?");
		  System.out.print("Enter " + LARGE_TABLE + "for a large table, or " + SMALL_TABLE + "for a small table.");
		furnitureType = input.nextInt(); 
		if (furnitureType == PINE_CODE)
		{
			chosenWood = PINE_WOOD;
				if(chosenSize == LARGE_TABLE);
					chosenRate = PINE_RATE_LARGE;
				if(chosenSize == SMALL_TABLE);		
					chosenRate = PINE_RATE;
		}
		else
			if (furnitureType == OAK_CODE)
			{		
					   chosenWood = OAK_WOOD;
					 if(chosenSize == LARGE_TABLE);
					 chosenRate = OAK_RATE_LARGE;
					 if(chosenSize == SMALL_TABLE);
				chosenRate = OAK_RATE;
			}
			else
				if (furnitureType == MAHOGANY_CODE)
				{
					chosenWood = MAHOGANY_WOOD;
						 if(chosenSize == LARGE_TABLE);
						 	chosenRate = MAHOGANY_RATE_LARGE;
						 if(chosenRate == SMALL_TABLE);
					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 a" + woodFurniture.getSize() + "table" +  woodFurniture.getType() +
				" which will cost: " + woodFurniture.getRate());
	  ;
	}
	
	public static void main(String[] args) {
		Furniture f = new Furniture();
	}
}




copy and compile this and tell me what you think i should do?
Was This Post Helpful? 0
  • +
  • -

#21 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 22 January 2010 - 02:11 PM

In your Furniture constructor (from your previous post)
public Furniture

You need to include the parenthesis, even if it won't take any parameters.
public Furniture()

Was This Post Helpful? 0
  • +
  • -

#22 vrichh  Icon User is offline

  • New D.I.C Head

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

Re: COMPILE ERRORS

Posted 22 January 2010 - 06:26 PM

okay but when i run this code in msdos, all i get is

at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)
at Furniture.<init>(Furniture.java:8)

and that is it...?



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)
			{
	 				System.out.println("You have chosen Oak wood which will cost");		
						
					 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();
	}
}

Was This Post Helpful? 0
  • +
  • -

#23 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 22 January 2010 - 06:49 PM

Ahhh, you're getting a StackOverflowError.

This here is the line that is causing it
Furniture woodFurniture = new Furniture();

It is recursively creating a new Furniture Object, and keeps creating more and more Furniture Objects until it eats up all the available space, and dies.

Let me demonstrate what I mean:
1. A Furniture object, f, is created in your main method.
2. This Object then creates another Furniture Object named woodFurniture.
3. This Object also uses the constructor, and in creating a new Object, creates a new Furniture Object.
4. Go to 3

This post has been edited by erik.price: 22 January 2010 - 06:54 PM

Was This Post Helpful? 0
  • +
  • -

#24 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 22 January 2010 - 07:23 PM

I answered your PM, but I'll post the same reply here since the use of PMs for programming questions isn't generally the right way of going about it.

Anyway, basically your Furniture class is creating an infinite number of copies of itself.

I would suggest removing this line Furniture woodFurniture = new Furniture();

Also
//woodFurniture.setType(furnitureType);
//woodFurniture.setRate(chosenRate);
this.setType(furnitureType);
this.setRate(chosenRate);
//anywhere else you see woodFurniture, replace it with this


This post has been edited by erik.price: 22 January 2010 - 07:24 PM

Was This Post Helpful? 0
  • +
  • -

#25 vrichh  Icon User is offline

  • New D.I.C Head

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

Re: COMPILE ERRORS

Posted 22 January 2010 - 07:25 PM

I appologize, im still finding my way around this site, i didn't realize i pm'd you.

Also, i will try that and see what happens, merci beacoupe.
Was This Post Helpful? 0
  • +
  • -

#26 vrichh  Icon User is offline

  • New D.I.C Head

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

Re: COMPILE ERRORS

Posted 23 January 2010 - 07:35 AM

Alright i have another issue.
I now have to make a code that accepts the kind of wood as well as the size. This is the code i have made,
however, the size selection doesn't show up.. what am i doing wrong?

import javax.swing.JOptionPane;
public class Furniture2
{
		  
	 int  size;
	int furnitureType;
	double chosenRate = 0;
	final int PINE_CODE = 1;
	final int OAK_CODE = 2;
	final int MAHOGANY_CODE = 3;
	 final int LARGE_CODE = 4;
	 final int SMALL_CODE = 5;
	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;
	
	{
		

		
		System.out.println("Enter <" + PINE_CODE + "> for a pint table");
		  System.out.println("Enter <" + OAK_CODE + "> for an  Oak table");
		  System.out.println("Enter <" + MAHOGANY_CODE + "> for a Mahogany table");
	 	  
		  System.out.println("What size would you like your table to be?");
		  System.out.println("Enter <" + LARGE_CODE + "> for a large table");
		  System.out.println("Enter <" + SMALL_CODE + "> for a small table");
		  
		  
	   
		 

		  if(furnitureType == PINE_CODE){ 
		 		if( size == LARGE_CODE)
				System.out.println("Large pine table cost is $135.00");
				else
				System.out.println("Small pine table cost is $100.00");
				  }
		else if(furnitureType == OAK_CODE) {
					  if(size == LARGE_CODE)
					System.out.println("Large oak table cost is $260.00");
					else
					System.out.println("Small oak table cost is $225.00");
					}
		else if(furnitureType == MAHOGANY_CODE) {
						  if(size == LARGE_CODE)
						System.out.println("Large mahogany table cost is $345.00");
						else
						System.out.println("Small mahogany table cost is $310.00");
		 		  }	
		else
		 		System.out.println("Invalid selection, please try again.");
		   
	
	 } 
	public static void main(String[] args)  {
		Furniture f = new Furniture();
		  
  }
}


Was This Post Helpful? 0
  • +
  • -

#27 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9161
  • View blog
  • Posts: 33,981
  • Joined: 27-December 08

Re: COMPILE ERRORS

Posted 23 January 2010 - 11:08 AM

The reason none of your output shows up is because you have it in a rogue block (see below code). You should make this block the constructor. So before the opening brace, add public Furniture2(). Also, just FYI, your code doesn't get the user input- it just prints output.
 {
		

		
		System.out.println("Enter <" + PINE_CODE + "> for a pint table");
		  System.out.println("Enter <" + OAK_CODE + "> for an  Oak table");
		  System.out.println("Enter <" + MAHOGANY_CODE + "> for a Mahogany table");
		   
		  System.out.println("What size would you like your table to be?");
		  System.out.println("Enter <" + LARGE_CODE + "> for a large table");
		  System.out.println("Enter <" + SMALL_CODE + "> for a small table");
		  
		  
	   
		 

		  if(furnitureType == PINE_CODE){ 
				 if( size == LARGE_CODE)
				System.out.println("Large pine table cost is $135.00");
				else
				System.out.println("Small pine table cost is $100.00");
				  }
		else if(furnitureType == OAK_CODE) {
					  if(size == LARGE_CODE)
					System.out.println("Large oak table cost is $260.00");
					else
					System.out.println("Small oak table cost is $225.00");
					}
		else if(furnitureType == MAHOGANY_CODE) {
						  if(size == LARGE_CODE)
						System.out.println("Large mahogany table cost is $345.00");
						else
						System.out.println("Small mahogany table cost is $310.00");
				   }	
		else
				 System.out.println("Invalid selection, please try again.");
		   
	
	 } 


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2