Error: Cannot find symbol: Help!
Hi there!
I have almost finished my project, but I keep getting the error cannot find symbol error. I don't know why. I made sure everything was spelled correctly. Here is my code maybe you can help! I am getting the error at line 31 in the InventoryAdvanced class.
Code:
/*
Author: Ben Hartnett
Sources: Java: A Beginner's Guide
Source 2: Monster example posted on student forums
Date Retrieved: 1-26-2012
*/
public class InventoryAdvanced {
public static void main(String args[]){
//Define the calculation variables
double c1;
double c2;
double c3;
//Declare the calculation variables
c1 = 13.00;
c2 = 5.00;
c3 = 10.00;
//Declare the 5% restocking fee
double fee = .05;
//Create the objects
InventoryDefine swordstone = new InventoryDefine("Sword In The Stone Movie", 1, 10, 13.00, 130.00);
InventoryDefine hercules = new InventoryDefine("Hercules Movie", 2, 20, 5.00, 100.00);
InventoryDefine mermaid = new InventoryDefine("The Little Mermaid Movie", 3, 30, 10.00, 300.00);
InventorySort sortThis = new InventorySort();
InventoryCal cal = new InventoryCal();
SwordStone movie = new SwordStone();
//Use an object to store the array
InventoryDefine[] inventoryArray = new InventoryDefine[3];
//Declare the arrays
inventoryArray[0] = swordstone;
inventoryArray[1] = hercules;
inventoryArray[2] = mermaid;
//Call the method from the sortThis object
sortThis.Sort(inventoryArray);
//Call the method from InventoryCal
cal.calVar(c1, c2, c3);
//Override the method from InventoryInherit
movie.calVar(c1, fee);
}
}
Code:
/**
/*
Author: Ben Hartnett
Sources: Java: A Beginner's Guide
Source 2: Monster example posted on student forums
Date Retrieved: 1-26-2012
*/
public class InventoryCal {
//Create a method that multiplies the variables
public void calVar(double m1, double m2, double m3){
//Create the calculation variable
double calEquals;
//Create the equation
calEquals = m1 + m2 + m3;
//Display the result
System.out.println("Total inventory value:" + calEquals);
}
public class SwordStone extends InventoryCal {
//Create the calculation method
public void calVar(double m1, double restockFee){
//Create the calculation variable
double calEquals;
//Create the equation
calEquals = m1 + 10 * restockFee;
//Display the result
System.out.println("Sword In The Stone product value with restocking fee:" + calEquals);
}
}
}
Code:
/*
Author: Ben Hartnett
Sources: Java: A Beginner's Guide
Source 2: Monster example posted on student forums
Date Retrieved: 1-26-2012
*/
//Create the class while it implements the Comparable
public class InventoryDefine implements Comparable<InventoryDefine> {
//Define the variables
private String inventoryName;
private int inventoryNumber;
private int inventoryStock;
private double inventoryPrice;
private double inventoryValue;
//Declare the constructor
public InventoryDefine(String inventoryName, int inventoryNumber, int inventoryStock, double inventoryPrice, double inventoryValue){
this.inventoryName = inventoryName;
this.inventoryNumber = inventoryNumber;
this.inventoryStock = inventoryStock;
this.inventoryPrice = inventoryPrice;
this.inventoryValue = inventoryValue;
}
//Use the toString method
public String toString() {
return inventoryName + ", " + inventoryNumber + ", " + inventoryStock + ", " + inventoryPrice + ", " + inventoryValue; //Return values
}
//Use the compareTo method
public int compareTo(InventoryDefine id){
return this.inventoryNumber - id.inventoryNumber; //Return values
}
}
Code:
/*
Author: Ben Hartnett
Sources: Java: A Beginner's Guide
Source 2: Monster example posted on student forums
Date Retrieved: 1-26-2012
*/
import java.util.Arrays;
public class InventorySort {
public void Sort(InventoryDefine[] array){
Arrays.sort(array);
for (int i = 0; i < 3; i++){
System.out.println(array[i]);
}
}
}
Re: Error: Cannot find symbol: Help!
Your SwordStone class is defined inside of InventoryCal for no good reason that I can see and because of this, the compiler can't find it. Get it into its own Java class.
Re: Error: Cannot find symbol: Help!
Quote:
Originally Posted by
Fubarable
Your SwordStone class is defined inside of InventoryCal for no good reason that I can see and because of this, the compiler can't find it. Get it into its own Java class.
This is for a school assignment. I am supposed to create a subclass of the InventoryCal class. I am supposed to show my knowledge of inheritance. Did I not do it correctly?
Re: Error: Cannot find symbol: Help!
Quote:
Originally Posted by
BenH
This is for a school assignment. I am supposed to create a subclass of the InventoryCal class. I am supposed to show my knowledge of inheritance. Did I not do it correctly?
No you didn't. Again, it's not supposed to be an inner class. Give it its own file (again!).