My assignment array program will not run
Hi there.
I finally figured out how to create my week 6 assignment (I posted another topic in which I needed help with it). Now I cannot get it to run. I get this error at line 21 ".class" expected on Class 1 (posted below) What does this mean? How do I fix this? How do I get my program to run and sort the array?
Class 1:
Code:
public class InventoryAdvanced {
public static void main(String args[]){
int size = 4;
InventoryDefine swordstone = new InventoryDefine("Sword In The Stone Movie", 1, 10,13.00);
InventoryDefine hercules = new InventoryDefine("Hercules", 2, 20, 5.00);
InventoryDefine mermaid = new InventoryDefine("The Little Mermaid", 3, 30, 10.00);
InventorySort methodCall = new InventorySort();
InventoryDefine inventoryArray = new InventoryDefine[3];
inventoryArray[0] = swordstone;
inventoryArray[1] = hercules;
inventoryArray[2] = mermaid;
//Call the sort method
methodCall.Sort(inventoryArray[]);
//Display the sorted array
for (int i = 0; i < size; i++){
System.out.println(inventoryArray[i]);
}
}
}
Class 2:
Code:
/**
* @(#)InventoryAdvanced.java
*
* InventoryAdvanced application
*
* @author
* @version 1.00 2012/1/26
*/
public class InventoryDefine {
//Define the variables
public String inventoryName;
public int inventoryNumber;
public int inventoryStock;
public double inventoryPrice;
//Declare the constructor
public InventoryDefine(String name, int productNumber, int productStock, double productPrice){
this.inventoryName = name;
this.inventoryNumber = productNumber;
this.inventoryStock = productStock;
this.inventoryPrice = productPrice;
}
}
Class 3:
Code:
/**
* @(#)InventorySort.java
*
*
* @author
* @version 1.00 2012/1/28
*/
public class InventorySort {
public void Sort(array[]){
int a, b, t;
int size;
size = 4;
for (a=1; a < size; a++)
for (b=size-1; b >= a; b--){
if(array[b-1] > array[b]) {
t = array[b-1]
array[b-1] = array[b];
array[b] = t;
}
}
}
}
Re: My assignment array program will not run
Quote:
.class" expected on Class 1 (posted below) What does this mean?
Your syntax for calling a method is incorrect. You should use only the variable name. Leave off the []