For starters here is one of my methods which is called within the project class ( the name of .java is project)
This method retrieves data from user and loads it into the array which I cannot access from the other method following this one.
// getItem Method defintion **************
public static void getItemData() {
Scanner input = new Scanner(System.in); // create scanner
System.out.println("enter number of items");
int amtOfitms = input.nextInt(); // get # of items
String[] item = new String[amtOfitms]; // initialize arrays
float[] cost = new float[amtOfitms];
float[] weight = new float[amtOfitms];
int i = 0;
int j = 0;
int k = 0;
// begin data collection loop *******
for(i = 0; i < amtOfitms; i++,j++,k++){
System.out.println("Please enter item "+(i+1)+"'s name. Press 0 to exit");
item[i] = input.nextLine();
System.out.println("Please enter item "+(i+1)+"'s weight.");
weight[j] = input.nextFloat();
System.out.println("Please enter item "+(i+1)+"'s cost.");
cost[k] = input.nextFloat();
}
// print data in table ******
for(i = 0, j = 0, k = 0; i < item.length; i++,j++,k++)
System.out.println("\t|"+item[i]+"|-----|"+weight[j]+"|-----|"+cost[k]+"|");
sumData(); // call the other method to calculate the data
}
Now when I call this method, it "cannot find symbol" and is referring to the array variable.
public static void sumData(){
String[] item = getItemData.item; // initialize arrays
float[] cost = getItemData.cost;
float[] weight = getItemData.weight;
final float TAXES = .07f;
final float SHIP_RATE = .05f;
float weightSum = 0;
float costSum = 0;
int j=0;
int k=0;
//sum numerical arrays
for(j = 0, k = 0; j < item.length; j++,k++){
weightSum += weight[j];
costSum += cost[k];
}
// calculate + echo data
float invoiceTax = costSum * TAXES;
float invoiceShip = (weightSum * SHIP_RATE) + 5;
float grandTotal = costSum + invoiceTax + invoiceShip;
System.out.printf( "\t|Subtotal: %-6.2f|\n\t|Taxes: %-6.2f|\n\t|Shipping: %-6.2f|\n",
costSum, invoiceTax, invoiceShip);
System.out.printf("\t|Grand Total: %-6.2f|\n\n", grandTotal);
runningTotal(invoiceTax, invoiceShip, grandTotal);
}
The error message I receive is:
project.java:53: error: cannot find symbol
String[] item = getItemData.item;
symbol: variable getItemData
location: class project
and it repeats for the other two variables that I attempt to retrieve in the same manner
String[] item = getItemData.item;
symbol: variable getItemData
location: class project
and it repeats for the other two variables that I attempt to retrieve in the same manner
I tried not using the Method.arrayvar and it can't find the array.(in this example I use the methods name as MyClass)
Also I tried using MyClass.arrayvar but still no luck.
Any ideas what I am doing wrong? I have been at this all day long and I have made some serious head way but now I seem to be in a rut.
I have attached the full program code ( 4 methods or so ) if anyone would like to check out the full code.
All comments, ideas, tips are VERY MUCH appreciated! Thanks in advance!!
Attached File(s)
-
project.txt (3.76K)
Number of downloads: 22

New Topic/Question
Reply




MultiQuote



|