Results 1 to 6 of 6
- 01-29-2012, 11:03 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 48
- Rep Power
- 0
My school assignment keeps generating errors
Hi.
The assignment that I am supposed to code for school keeps generating errors. First, the errors I get are in the InventorySort class. These are the errors:
Line 22: bad operand types for binary operator '>'
Line 24: error: incompatible types
Line 26: error: incompatible types
Then I get errors on the InventoryAdvanced class that says:
Line 21: Error: ".class" expected.
I tried removing the [] then it generated even more errors
Can someone help me fix these? I need to get this assignment in ASAP.
Classes:
Java 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]); } } }Java 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; } }Java Code:/** * @(#)InventorySort.java * * * @author * @version 1.00 2012/1/28 */ public class InventorySort { public void Sort(InventorySort 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; } } } }
- 01-29-2012, 11:10 PM #2
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
Re: My school assignment keeps generating errors
Can You explain argument of this method?
Java Code:public void Sort(InventorySort array[])
- 01-29-2012, 11:34 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 48
- Rep Power
- 0
Re: My school assignment keeps generating errors
Hey!
That method is supposed to sort the array. The reason why the class name acts as the identifier is because that is what my instructor told me to do. I cannot seem to get it to work for some reason. I posted all the errors up on my previous post. I put the [] to show that the parameters take an array.
-
Re: My school assignment keeps generating errors
But what objects is it supposed to be sorting? Certainly not an array of itself, right? Perhaps you want the method to accept an array of InventoryDefine objects?
- 01-29-2012, 11:48 PM #5
Re: My school assignment keeps generating errors
never heard about the interface comparable, then look at some examples: Object Ordering (The Java™ Tutorials > Collections > Interfaces)
Last edited by j2me64; 01-29-2012 at 11:51 PM.
- 01-29-2012, 11:56 PM #6
Member
- Join Date
- Dec 2011
- Posts
- 48
- Rep Power
- 0
Similar Threads
-
I need help with my school assignment, please
By burnenator in forum New To JavaReplies: 13Last Post: 11-21-2011, 04:54 AM -
Need help with school assignment
By sljkbn in forum New To JavaReplies: 6Last Post: 10-28-2009, 01:07 PM -
Help with noob school assignment
By debo3381 in forum New To JavaReplies: 3Last Post: 09-23-2009, 04:02 AM -
Question about school assignment
By wata in forum New To JavaReplies: 7Last Post: 08-18-2009, 02:00 PM -
Please help... assignment for school
By confused2000 in forum New To JavaReplies: 3Last Post: 11-12-2007, 08:12 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks