Can't figure out where I am going wrong. New to java programming so please bare with me. I keep getting the "int cannot be dereferenced" error on program below. Tried changing things around, only makes it worse. I pasted the program first and error msg. below it. Any advise would be greatly appreciated.
import java.util.Scanner;
public class Furniture
{
public static void main(String[] args)
{
int woodType;
String chosenCode = "";
double chosenCost = 0;
Furniture selectedFurniture = new Furniture();
final int PINE_CODE = 1;
final int OAK_CODE = 2;
final int MAHOGANY_CODE = 3;
final double PINE_COST = 100;
final double OAK_COST = 225;
final double MAHOGANY_COST = 310;
boolean choiceIsGood = true;
Scanner input = new Scanner(System.in);
System.out.println("What type of wood do you want ");
System.out.println("Enter " + PINE_CODE + " for Pine " +
OAK_CODE + " for Oak, or " + MAHOGANY_CODE + " for Mahogany... ");
woodType = input.nextInt();
if(woodType == PINE_CODE)
chosenCost = PINE_COST;
else
if(woodType == OAK_CODE)
chosenCost = OAK_COST;
else
if(woodType == MAHOGANY_CODE)
chosenCost = MAHOGANY_COST;
else
choiceIsGood = false;
if(choiceIsGood)
{
woodType.setCode(chosenCode);
woodType.setCost(chosenCost);
}
else
System.out.println("You entered " + woodType + " which is invalid.");
System.out.println("Wood choise: ");
System.out.println("Type: " + woodType.getType() +
" Table: " + woodType.getWood() + " Cost is " + woodType.getCost());
}
}
Error msgs.
Furniture.java:34: int cannot be dereferenced
woodType.setCode(chosenCode);
^
Furniture.java:35: int cannot be dereferenced
woodType.setCost(chosenCost);
^
Furniture.java:40: int cannot be dereferenced
System.out.println("Type: " + woodType.getType() +
^
Furniture.java:41: int cannot be dereferenced
" Table: " + woodType.getWood() + " Cost is " + woodType.getCost());
^
Furniture.java:41: int cannot be dereferenced
" Table: " + woodType.getWood() + " Cost is " + woodType.getCost());
^
5 errors
You declared woodType as an int. It doesn't have a getCost(), getWood(), setCode(), setCost() or getType() method.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks