Results 1 to 6 of 6
  1. #1
    BenH is offline Member
    Join Date
    Dec 2011
    Posts
    48
    Rep Power
    0

    Default 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;
    
    				}
    			}
    
    
    }
    
    }

  2. #2
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: My school assignment keeps generating errors

    Can You explain argument of this method?
    Java Code:
    public void Sort(InventorySort array[])

  3. #3
    BenH is offline Member
    Join Date
    Dec 2011
    Posts
    48
    Rep Power
    0

    Default 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.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default 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?

  5. #5
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default 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.

  6. #6
    BenH is offline Member
    Join Date
    Dec 2011
    Posts
    48
    Rep Power
    0

    Default Re: My school assignment keeps generating errors

    Quote Originally Posted by Fubarable View Post
    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?
    I am using the Bubblesort algorithm to sort the array which you can find in the InventorySort class. I am sorting the array itself. Is there another way of making this work?

Similar Threads

  1. I need help with my school assignment, please
    By burnenator in forum New To Java
    Replies: 13
    Last Post: 11-21-2011, 04:54 AM
  2. Need help with school assignment
    By sljkbn in forum New To Java
    Replies: 6
    Last Post: 10-28-2009, 01:07 PM
  3. Help with noob school assignment
    By debo3381 in forum New To Java
    Replies: 3
    Last Post: 09-23-2009, 04:02 AM
  4. Question about school assignment
    By wata in forum New To Java
    Replies: 7
    Last Post: 08-18-2009, 02:00 PM
  5. Please help... assignment for school
    By confused2000 in forum New To Java
    Replies: 3
    Last Post: 11-12-2007, 08:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •