Sorting a multi array help

I am new to programming and have issues writing the proper code to sort an array, I am not looking for anyone to write the entire code for me as it is already done but I cannot get it to sort and print the information by the item name. Here is my array and every code I have tried does not sort the information it only prints in the order of the array.
Prod[0] = new Product( "Computer", "40-7-1-0", 25, 1250 );
Prod[1] = new Product( "Video Card", "30-4-18-0", 150, 500);
Prod[2] = new Product( "Drive", "30-5-20-0", 500, 89);
When the program shows the data it is supposed to print in order IE
Computer ....
Drive ....
Video Card ...
I just do not understand how to get the program to sort the information correctly, if anyone can point me towards some information or examples on how to sort the array type it would be greatly appreciated so I can move forward, thanks!!

try this:
package com.myCompany;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Product implements Comparable<Product> {
     String      name;
     String      productNumber;
     int      numberInStock;
     /** constructor */
     public Product(String name, String productNumber, int numberInStock){
          this.name=               name;
          this.productNumber=     productNumber;
          this.numberInStock=     numberInStock;
     public String getName(){
          return name;
    public int compareTo(Product n) {
        int lastCmp = name.compareTo(n.name);
        return (lastCmp != 0 ? lastCmp :
                name.compareTo(n.name));
     public String toString(){
          return name+" "+productNumber+" "+numberInStock;
     /** demonstrates that this class sorts Product by name */
     public static void main(String[] args){
          //lets get an unsorted list of items (name= a,c,b)
          Product product1=new Product("a","1234",5);
          Product product2=new Product("c","1234",7);
          Product product3=new Product("b","1234",3);
          List<Product> products= new ArrayList<Product>();
          products.add(product1);
          products.add(product2);
          products.add(product3);
          Collections.sort(products);
          //this shows products are printed out by name sorted (name= a,b,c)
          for(Product product :  products){
               System.out.println(product.toString());
}

Similar Messages

  • Newbie trying to sort 2D string array

    Dear all,
    After read some book chapters, web sites including this, I still don't get the point.
    If I have a file like,
    1 aaa 213 0.9
    3 cbb 514 0.1
    2 abc 219 1.3
    9 bbc 417 10.4
    8 dee 887 2.1
    9 bba 111 7.1
    and I load into memory as a String[][]
    here comes the problem, I sort by column 1 (aaa,...,bba) using an adaptation of the Quicksort algorithm for 2D arrays
    * Sort for a 2D String array
    * @param a an String 2D array
    * @param column column to be sort
    public static void sort(String[][] a, int column) throws Exception {
    QuickSort(a, 0, a.length - 1, column);
    /** Sort elements using QuickSort algorithm
    static void QuickSort(String[][] a, int lo0, int hi0, int column) throws Exception {
    int lo = lo0;
    int hi = hi0;
    int mid;
    String mitad;
    if ( hi0 > lo0) {
    /* Arbitrarily establishing partition element as the midpoint of
    * the array.
    mid = ( lo0 + hi0 ) / 2 ;
    mitad = a[mid][column];
    // loop through the array until indices cross
    while( lo <= hi ) {
    /* find the first element that is greater than or equal to
    * the partition element starting from the left Index.
    while( ( lo < hi0 ) && ( a[lo][column].compareTo(mitad)<0))
    ++lo;
    /* find an element that is smaller than or equal to
    * the partition element starting from the right Index.
    while( ( hi > lo0 ) && ( a[hi][column].compareTo(mitad)>0))
    --hi;
    // if the indexes have not crossed, swap
    if( lo <= hi )
    swap(a, lo, hi);
    ++lo;
    --hi;
    /* If the right index has not reached the left side of array
    * must now sort the left partition.
    if( lo0 < hi )
    QuickSort( a, lo0, hi, column );
    /* If the left index has not reached the right side of array
    * must now sort the right partition.
    if( lo < hi0 )
    QuickSort( a, lo, hi0, column );
    * swap 2D String column
    private static void swap(String[][] array, int k1, int k2){
    String[] temp = array[k1];
    array[k1] = array[k2];
    array[k2] = temp;
    ----- end of the code --------
    if I call this from the main module like this
    import MyUtil.*;
    public class kaka
    public static void main(String[] args) throws Exception
    String[][]a = MyUtil.fileToArray("array.txt");
    MyMatrix.printf(a);
    System.out.println("");
    MyMatrix.sort(a,1);
    MyMatrix.printf(a);
    System.out.println("");
    MyMatrix.sort(a,3);
    MyMatrix.printf(a);
    for the first sorting I get
    1 aaa 213 0.9
    2 abc 219 1.3
    9 bba 111 7.1
    9 bbc 417 10.4
    3 cbb 514 0.1
    8 dee 887 2.1
    (lexicographic)
    but for the second one (column 3) I get
    3 cbb 514 0.1
    1 aaa 213 0.9
    2 abc 219 1.3
    9 bbc 417 10.4
    8 dee 887 2.1
    9 bba 111 7.1
    this is not the order I want to apply to this sorting, I would like to create my own one. but or I can't or I don't know how to use a comparator on this case.
    I don't know if I am rediscovering the wheel with my (Sort String[][], but I think that has be an easy way to sort arrays of arrays better than this one.
    I've been trying to understand the Question of the week 106 (http://developer.java.sun.com/developer/qow/archive/106/) that sounds similar, and perfect for my case. But I don't know how to pass my arrays values to the class Fred().
    Any help will be deeply appreciated
    Thanks for your help and your attention
    Pedro

    public class StringArrayComparator implements Comparator {
      int sortColumn = 0;
      public int setSortColumn(c) { sortColumn = c; }
      public int compareTo(Object o1, Object o2) {
        if (o1 == null && o2 == null)
          return 0;
        if (o1 == null)
          return -1;
        if (o2 == null)
          return 1;
        String[] s1 = (String[])o1;
        String[] s2 = (String[])o2;
        // I assume the elements at position sortColumn is
        // not null nor out of bounds.
        return s1[sortColumn].compareTo(s2[sortColumn]);
    // Then you can use this to sort the 2D array:
    Comparator comparator = new StringArrayComparator();
    comparator.setSortColumn(0); // sort by first column
    String[][] array = ...
    Arrays.sort(array, comparator);I haven't tested the code, so there might be some compiler errors, or an error in the logic.

  • Sort a string :: Please help.

    Hello Everyone,
    I am having this very simple problem of sorting a String. please help.
         static String sortString(String str){
              List list = Arrays.asList(str);                    
              Collections.sort(list);
              for(int i=0, n=list.size();i<n;i++){
                   System.out.println(","+ list.get(i));
    The function is supposed to take a String and sort it & print it out. This should be simple. Where am I making mistakes? Please help!!

    Hello Everyone,
    I am having this very simple problem of sorting a String. please help.
         static String sortString(String str){
              List list = Arrays.asList(str);                    
              Collections.sort(list);
              for(int i=0, n=list.size();i<n;i++){
                   System.out.println(","+ list.get(i));
                   return str;
    The function is supposed to take a String and sort it & print it out. This should be simple. Where am I making mistakes? Please help!!

  • Sort within an array?

    public class Input3
         private String[] input = new String[40];
         private static int StringNum = -1;
         public static final int NUMBER_OF_TEAMS = 3;
         public static final int NUMBER_OF_PLAYERS = 5;
         public Input3()
              //The first six inputs will be for the first team
              input[0] = "LAKERS";
              input[1] = "Kobe Bryant";
              input[2] = "Derek Fisher";
              input[3] = "Shaquille O'Neal";     
              input[4] = "Karl Malone";
              input[5] = "Brian Cook";
              //The next six inputs will be for the second team
              input[6] = "MAVERICKS";
              input[7] = "Antoine Walker";
              input[8] = "Dirk Nowitzki";
              input[9] = "Tony Delk";
              input[10] = "Shawn Bradley";
              input[11] = "Travis Best";
              //The next six inputs will be for the third team
              input[12] = "KNICKS";
              input[13] = "Mike Sweetney";
              input[14] = "Allan Houston";
              input[15] = "Howard Eisley";
              input[16] = "Kurt Thomas";
              input[17] = "Shanon Anderson";
         //This method returns the strings one after the other.
         public String getNextString()
              StringNum++;
              return input[StringNum];
    }What I'm supposed to do with this is sort that data by last names within each team. By that I mean I have to sort input[1] through input[5] by last names, input[7] through input[11] by last names, and same for the Knicks team. I'm not sure how to do 3 separate sorts within an array.
    The output should look like this:
    KNICKS:
    Sharon Anderson
    Howard Eisley
    Allan Houston
    Mike Sweetney
    Kurt Thomas
    Any help is greatly appreciated!

    Yeah, I don't really understand it. But my professor actually gave us that code to work with to be part of a bigger assignment. I actually just posted another question about the same assignment if you want to look at that to see if it might help.
    I dunno how to use the insert link button on here so I'll just let you copy and paste if you are interested in helping me out... Thanks!
    It's here >>> http://forum.java.sun.com/thread.jspa?threadID=5268839

  • Sorting between multiple arrays.

    I thought that I had posted this yesterday; however as I can not find my post...
    I need assistance with part of a project where I need to sort between multiple arrays; using one of the columns as the sort criteria. The arrays contain integers, strings, and doubles; however I would like to sort and display the arrays alphabetically using the string column. I was told that a bubble array may work, however as I can not find specific information on the use of a bubble array, I really don't know where to start. The arrays look like the following:
    productArray[0] = new Product(1, "binder ", 15, 1.5, 0, 0);
    productArray[1] = new Product(2, "marker ", 13, .5, 0, 0);
    productArray[2] = new Product(3, "paper ", 24, .95, 0, 0);
    productArray[3] = new Product(4, "pen ", 5, .25, 0, 0); \
    Any assistance that anyone could provide would be greatly appreciated. I am a newbie when it comes to Java and the course materials are extremely vague.
    Dman

    Thank you for your assistance.
    The site that I found to be most helpful was the http://www.onjava.com/lpt/a/3286 site; however I am still experiencing problems. I have added code to the program as noted below:
    public class Inventoryprogrampart3
    /** Creates a new instance of Main */
    * @param args the command line arguments
    public static void main(String[] args)
    // create Scanner to obtain input from command window
    java.util.Scanner input = new java.util.Scanner( System.in );
    double totalInventoryValue = 0;
    NumberFormat nf = NumberFormat.getCurrencyInstance();
    System.out.println(); // Displays a blank line
    System.out.println( " Welcome to the Inventory Program - Part 2 " ); // Display the string
    System.out.println( " ----------------------------------------- " ); // displays a line of characters
    System.out.println(); // Displays a blank line
    System.out.println( "This program will output an office supply inventory" ); // Display the string
    System.out.println( "listing that includes item numbers for the" ); // Display the string.
    System.out.println( "inventoried products, the items product names, the" ); // Display the string.
    System.out.println( "quantity of each product in stock, the unit price" ); // Display the string
    System.out.println( "for each product, the total value of each products" ); // Display the string
    System.out.println( "inventory, and a total value of the entire inventory." ); // Display the string
    System.out.println(); // Displays a blank line
    System.out.println( "*****************************************************" ); // Displays a line of characters
    System.out.println(); // Displays a blank line
    Product[] productArray = new Product[ 7 ]; // creates 7 product arrays
    // adds data to the 7 arrays
    productArray[0] = new Product();
    productArray[0].setitemNumber(1);
    productArray[0].setproductName ( "binder" );
    productArray[0].setitemQuantity(15);
    productArray[0].setitemPrice(1.5);
    productArray[0].setinventoryValue(0);
    productArray[1] = new Product();
    productArray[1].setitemNumber(2);
    productArray[1].setproductName( "paper" );
    productArray[1].setitemQuantity(24);
    productArray[1].setitemPrice(.95);
    productArray[1].setinventoryValue(0);
    productArray[2] = new Product();
    productArray[2].setitemNumber(4);
    productArray[2].setproductName( "pen" );
    productArray[2].setitemQuantity(5);
    productArray[2].setitemPrice(.25);
    productArray[2].setinventoryValue(0);
    productArray[3] = new Product();
    productArray[3].setitemNumber(3);
    productArray[3].setproductName( "marker" );
    productArray[3].setitemQuantity(13);
    productArray[3].setitemPrice(.5);
    productArray[3].setinventoryValue(0);
    productArray[4] = new Product();
    productArray[4].setitemNumber(5);
    productArray[4].setproductName( "pencil" );
    productArray[4].setitemQuantity(28);
    productArray[4].setitemPrice(.4);
    productArray[4].setinventoryValue(0);
    productArray[5] = new Product();
    productArray[5].setitemNumber(7);
    productArray[5].setproductName( "tape" );
    productArray[5].setitemQuantity(14);
    productArray[5].setitemPrice(1.65);
    productArray[5].setinventoryValue(0);
    productArray[6] = new Product();
    productArray[6].setitemNumber(6);
    productArray[6].setproductName( "staples" );
    productArray[6].setitemQuantity(13);
    productArray[6].setitemPrice(1.25);
    productArray[6].setinventoryValue(0);
    System.out.println( "Inventory listing prior to sorting by product name:" );
    System.out.println(); // Displays a blank line
    System.out.println( "Item #"+"\t"+"Product Name"+"\t"+"Stock"+"\t"+"Price"+"\t"+"Total Value"); // Displays a header line for the inventory array display
    System.out.println(); // Displays a blank line
    System.out.println( "-----------------------------------------------------" ); // Displays a line of characters
    System.out.println(); // Displays a blank line
    for (int i=0; i<=6; i++)
    Product products = productArray;
    String productName = products.getproductName();
    int itemNumber = products.getitemNumber();
    int itemQuantity = products.getitemQuantity();
    double itemPrice = products.getitemPrice();
    double inventoryValue = products.getinventoryValue();
    System.out.println( productArray[i].getitemNumber() +"\t"+ productArray[i].getproductName() +"\t"+"\t" + productArray[i].getitemQuantity() +"\t"+ nf.format(productArray[i].getitemPrice()) +"\t"+ nf.format(productArray[i].getinventoryValue()) );
    Arrays.sort(productArray);
    System.out.println( "-----------------------------------------------------" ); // Displays a line of characters
    System.out.println(); // Displays a blank line
    System.out.println( "Inventory listing after being sorted by product name:" );
    System.out.println(); // Displays a blank line
    System.out.println( "Item #"+"\t"+"Product Name"+"\t"+"Stock"+"\t"+"Price"+"\t"+"Total Value"); // Displays a header line for the inventory array display
    System.out.println(); // Displays a blank line
    System.out.println( "-----------------------------------------------------" ); // Displays a line of characters
    for(int i=0; i <= 6; i++)
    totalInventoryValue = totalInventoryValue + productArray[i].getinventoryValue(); // calculates the total value of the entire products inventory
    System.out.println( productArray[i].getitemNumber() +"\t"+ productArray[i].getproductName() +"\t"+"\t"+ productArray[i].getitemQuantity() +"\t"+ nf.format(productArray[i].getitemPrice()) +"\t"+ nf.format(productArray[i].getinventoryValue()) );
    }// end for
    System.out.println(); // Displays a blank line
    System.out.println( "The total value of the entire inventory is: " + nf.format(totalInventoryValue) ); // Displays the entire inventory value
    System.out.println(); // Displays a blank line
    System.out.println( "*****************************************************" ); // Displays a line of characters
    } // end public static void main
    }// end public class Inventoryprogrampart3 main
    The following utilities have been set:
    import java.io.*;
    import java.text.*;
    import java.util.Scanner;
    import java.util.*;
    import java.util.Arrays;
    import java.util.ArrayList;
    import java.util.Comparator;
    The program compiles, however when I try to run the program I receive the following error (which outputs about 1/2 way through the program:
    Exception in thread "main" java.lang.ClassCastException: Product can not be cast to java language comparable.
    (along with a listing of other errors - I can't even get my cut and paste to work on my command prompt window).
    I've tried about 50 different iterations and nothing seems to work.

  • Multi-language Help in a multi-language web app

    Hello!
    I had posted this on the RH HTML forum but removed that and
    posted here for a wider audience...
    ***Please note: this question is not specific to RH but is
    applicable now that RH 7 is unicode enabled. If you have experience
    that does not relate to RH, please share anyway!
    Once I have developed WebHelp (for example) in multiple
    languages, how do I connect the help files to the web application
    that the help is about? How does the correct language output get
    displayed? For example, the application (that the help documents)
    changes its interface based on browser language. Can the
    appropriate help content be displayed based on browser language?
    How is multi-language help generally implemented for an end user?
    And, equally important, how does context-sensitive help
    (mapping) work with multiple languages?
    I have never been involved in a multi-language development
    effort and so I have no experience to relate this to. Any guidance
    will be greatly (and gratefully
    ) appreciated!
    Kathy

    That's how our developers do it, but I just want to throw in
    one other detail. The help output for each language has to be in a
    separate directory. So if you have 5 languages, you'll have 5
    directories. It's up to the developers to code the app so it
    detects the browser language, then looks in the appropriate help
    directory when the user clicks your help link or icon.
    --Ben

  • Sort and Object array of Arrays

    Hi,
    I have an object array that contains a String[] and an int[].
    Object[String[], int[]]
    The values in the Strings array must be in the same position in the array as those in the int array i.e
    String [0] is the string representation of int[0].
    Its for a bar chart.
    That is all working beautifully.
    Now however I want to sort the int array in descending order by the value of the ints in the array and thus the order or the String array has to mirror this.
    I am using a comparator to do this but it just wont work. I'm sure this is the way but how should it look?
    Has anybody got any ideas?
    Thanks in advance,
    L.

    use the bubblesort:
        for (int i = a.length; --i >= 0; ) {
            for (int j = 0; j < i; j++) {
                if (a[j][1] > a[j+1][1]) {
                    int temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
        }

  • What types of sort performed by sort method of Array class ?

    I use normal bubble sort and method Array.sort() to sort some given data of an Array and then count the time.But Array.sort() method takes more time then normal bubble sort.
    Can anybody tell me what types of sort performed by sort method of Array class?

    I'm pretty sure that in eariler versions (1.2, 1.3
    maybe?) List.sort's docs said it used quicksort. Or I
    might be on crack.You are actually both correct, and wrong :)
    From the documentation of the sort methods hasn't changed in 1.2 -> 1.4 (as far as I can notice), and the documentation for sort(Object[]) says (taken from JDK 1.2 docs):
    "This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.
    The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n*log(n) performance, and can approach linear performance on nearly sorted lists."
    So, how could you be correct? The documentation for e.g. sort(int[]) (and all other primities) says:
    "Sorts the specified array of ints into ascending numerical order. The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance."
    Your memory serves you well :)
    /Kaj

  • Why can't I buy any app ? Iv tried creating a new Appel account ect but it says the same thing everytime . Sorry your payment was declined . How can I sort this ? Please help

    Why can't I buy any app ? Iv tried creating a new Appel account ect but it says the same thing everytime . Sorry your payment was declined . How can I sort this ? Please help

    - Try another payment method.
    - Contact iTunes
    Apple - Support - iTunes - Contact Us
    - Create a NEW account using these instructions. Make sure you follow the instructions. Many do not and if you do not you will not get the None option. You must use an email address that you have not used with Apple before.
    Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card

  • About the sort method of arrays

    Hi,
    I found that for primitive types such as int, float, etc., algorithm for sort is a tuned quicksort. However the algorithm for sorting an object array is a modified merge sort according to the java API. What is the purpose of using two different sorting strategy?
    Thanks.

    The language knows how to compare two ints, two doubles, etc. For Object arrays, however, it's not a simple matter of comparing two reference values as ints or longs. We're not comparing the references. We have to compare the objects, according to the class's compareTo() method (if it implements Comparable) or a provided Comparator. The size of an int is known, fixed, and small. The size of an object is unknown, variable, and essentially unbounded. I don't know for sure that that difference is what drove the different approaches, but it is a significant difference, and mergesort is better suited to use cases where we can't fit the entire array into memory at one time. It seems reasonable that we'd get better locality of reference (fewer cache misses, less need to page) with an array of ints than with an array of objects.
    Edited by: jverd on Mar 18, 2011 3:16 AM

  • Need to sort an object array using an element in the object.

    hi all,
    i need to sort an object array using an element in the object.can someone throw some light on this.
    Edited by: rageeth on Jun 14, 2008 2:32 AM

    [http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html]

  • I submitted my podcast and I got an email saying error, I checked with the feed validator and got this message: This feed does not validate. line 40, column 6: Undefined item element: itunes:order, how do sort this out, someone help me please.

    I submitted my podcast and I got an email saying error, I checked with the feed validator and got this message: This feed does not validate. line 40, column 6: Undefined item element: itunes:order, how do sort this out, someone help me please.

    Ignore it. 'itunes:order' is a recent addition which FeedValidator doesn't know about. If your podcast is rejected that is unlikely to be the reason. Of course as you haven't posted the feed URL nor the text of the error message I can't make any further comment.

  • Insertion Sort,, User Inputs Array Size!!! URGENT HELP

    guys please sum1 help me..
    i knows its a small tweak but i jus cant seem to figure it out..
    my main post is lower down.. with my sample codes
    thanks

    Don't crosspost. That makes people ignore you.

  • Trying to sort a multidimensional array

    I'm in a Java class and am trying to create an inventory program. It doesn't have to store the data to a file, just create and sort arrays to display the information sorted. I'm using golfing discs as my inventory and was able to get the arrays stuffed and printed out how I liked. Now I just need to figure out how to sort the MasterArray by the disc name column (MasterArray[ ][2]) and, if those are the same, the SKU column (MasterArray[ ][0]).
    The error I'm getting is:
    DiscInventoryCall.java:134: non-static variable this cannot be referenced from a
    static context
    Arrays.sort( MasterArray, new DiscComparator() );
    ^
    Note: DiscInventoryCall.java uses unchecked or unsafe operations.
    Here is my code:
    // Disc Inventory Program
    import java.util.*;
    public class DiscInventoryCall
         // start main method
         public static void main( String args[] )
        // create Scanner to grab input
        Scanner input = new Scanner( System.in );
              // declare variables
              String sendDiscSKU;
              String sendDiscBrand;
              String sendDiscName;
              String sendDiscType;
              int sendDiscWeight = 0;
              double sendDiscPrice = 0.00;
              int sendDiscCount = 0;
              double InventoryTotal = 0.00;
              int AllDone = 0;
              int Counter = 0;
              String DiscStop = "done"; // string value to stop the program
              int Weight1 = 0;
              int Weight2 = 0;
              int Price1 = 0;
              int Price2 = 0;
              int Count1 = 0;
              int Count2 = 0;
              int Value1 = 0;
              int Value2 = 0;
              // declare array variables
              String MasterArray[][] = new String[100][12];
              Double DoubleArray[][] = new Double[100][2];
              int IntArray[][] = new int[100][2];
              System.out.print( "Enter Disc SKU (enter \"done\" when finished): " );
              sendDiscSKU = input.nextLine();
              if ( sendDiscSKU.equals(DiscStop) )
             AllDone = 1;
        } // bypass while loop
              // begin while loop
              while ( AllDone == 0 )
                   System.out.print( "Enter Disc Brand: " );
                   sendDiscBrand = input.nextLine();
                   System.out.print( "Enter Disc Name: " );
                   sendDiscName = input.nextLine();
                   System.out.print( "Enter Disc Type: " );
                   sendDiscType = input.nextLine();
                   System.out.print( "Enter Disc Weight (in grams): " );
                   sendDiscWeight = input.nextInt();
                   System.out.print( "Enter Disc Price: $" );
                   sendDiscPrice = input.nextDouble();
                   System.out.print( "Enter Disc Count: " );
                   sendDiscCount = input.nextInt();
                   // instantiate DiscInventory object
                   DiscInventory Disc = new DiscInventory( sendDiscSKU, sendDiscBrand, sendDiscName, sendDiscType, sendDiscWeight, sendDiscPrice, sendDiscCount );
                   // get Disc data
                   //System.out.println();
                   //System.out.println( "Disc information summary:");
                   //System.out.println();
                   //System.out.printf( "%15s %s\n", "Disc SKU:", Disc.getDiscSKU() );
                   //System.out.printf( "%15s %s\n", "Disc Brand:", Disc.getDiscBrand() );
                   //System.out.printf( "%15s %s\n", "Disc Name:", Disc.getDiscName() );
                   //System.out.printf( "%15s %s\n", "Disc Type:", Disc.getDiscType() );
                   //System.out.printf( "%15s %d grams\n", "Disc Weight:", Disc.getDiscWeight() );
                   //System.out.printf( "%15s $%.2f\n", "Disc Price:", Disc.getDiscPrice() );
                   //System.out.printf( "%15s %d\n", "No. Available:", Disc.getDiscCount() );
                   System.out.printf( "%15s $%.2f\n\n", "Total Value:", Disc.DiscValue() );
                   // System.out.printf( "\n%s:\n\n%s\n", "Disc information obtained by toString", Disc );
                   // Add total inventory values
                   InventoryTotal = InventoryTotal + Disc.DiscValue();
                   System.out.printf( "%15s %.2f\n", "Total Inventory Value:", InventoryTotal );
                   // Stuff the array
                   MasterArray[Counter][0] = Disc.getDiscSKU();
                   MasterArray[Counter][1] = Disc.getDiscBrand();
                   MasterArray[Counter][2] = Disc.getDiscName();
                   MasterArray[Counter][3] = Disc.getDiscType();
                   MasterArray[Counter][4] = Integer.toString(Counter);
                   MasterArray[Counter][5] = "0";        
                   MasterArray[Counter][6] = Integer.toString(Counter);
                   MasterArray[Counter][7] = "0";        
                   MasterArray[Counter][8] = Integer.toString(Counter);
                   MasterArray[Counter][9] =  "1";
                   MasterArray[Counter][10] = Integer.toString(Counter);
                   MasterArray[Counter][11] =  "1";
                   DoubleArray[Counter][0] = Disc.getDiscPrice();
                   DoubleArray[Counter][1] = Disc.DiscValue();
                   IntArray[Counter][0] = Disc.getDiscWeight();
                   IntArray[Counter][1] = Disc.getDiscCount();
                   Counter++;
                   System.out.print( "Enter Disc SKU (enter \"done\" when finished): " );
                   input.nextLine();
                   sendDiscSKU = input.nextLine();
             if ( sendDiscSKU.equals(DiscStop) )
                  AllDone = 1;
                 } // stop while loop
              } // end while loop
              Arrays.sort( MasterArray, new DiscComparator() );
              System.out.printf( "%-11s %-6s %-6s %-15s %-5s %-10s %-6s %-10s\n", "SKU", "Brand", "Name", "Type", "Weight", "Price", "Count", "Value" );
              for ( int Countup = 0; Countup < Counter; Countup++ )
                   Weight1 = Integer.parseInt(MasterArray[Countup][4]);
                   Weight2 = Integer.parseInt(MasterArray[Countup][5]);
                   Price1 = Integer.parseInt(MasterArray[Countup][6]);
                   Price2 = Integer.parseInt(MasterArray[Countup][7]);
                   Count1 = Integer.parseInt(MasterArray[Countup][8]);
                   Count2 = Integer.parseInt(MasterArray[Countup][9]);
                   Value1 = Integer.parseInt(MasterArray[Countup][10]);
                   Value2 = Integer.parseInt(MasterArray[Countup][11]);
                   System.out.printf( "%-11s %-6s %-6s %-15s %-6d $%-8.2f %5d $%-9.2f\n",
                   MasterArray[Countup][0],
                   MasterArray[Countup][1],
                   MasterArray[Countup][2],
                   MasterArray[Countup][3],
                   IntArray[Weight1][Weight2],
                   DoubleArray[Price1][Price2],
                   IntArray[Count1][Count2],
                   DoubleArray[Value1][Value2] );
              System.out.printf( "\n\nThank you for using this program. \nYour total inventory value is: $%.2f\n", InventoryTotal );
         } // end main method
         // begin sorting method
         class DiscComparator implements Comparator
              public int compare( Object obj1, Object obj2 )
                   int result = 0;
                   String[] str1 = (String[]) obj1;
                   String[] str2 = (String[]) obj2;
                   // sort on name of disc
                   if (( result = str1[2].compareTo(str2[2])) == 0 )
                        // if disc names are the same, sort on sku
                        result = str1[0].compareTo(str2[1]);
                   return result;
         }     // end sorting method
    } // end class DiscInventoryCallAny help on what I'm doing wrong would be appreciated.

    I'm pretty new to OOP and, to be honest, wouldn't know what parts could be broken into separate objects.
    There are some extra lines in there I could have removed (commented out) but forgot to do so before I posted it.
    So when it shows:
    DiscInventoryCall.java:134: non-static variable this cannot be referenced from a
    static context
    Arrays.sort( MasterArray, new DiscComparator() );
    ^
    Is that saying the DiscComparator() is a non-static variable? or the MasterArray?

  • How to sort via multi value parameter in ssrs

    I have a parameter with multi values. when the user selects ,he get of options like acount name, first name, last name.
    so if user selects firstname , the data has to sort by firstname.
    if he selects acount name , the data has to sort by account name.
    please help me how to sort the data using parameter with multivalue? in ssrs 2008.
    Thank you?

    Hi Venku,
    Based on your description, it seems that you create a parameter with available values and you want to sort the report data based on the parameter value. If the available values are the field names in the report, you can try to open the Tablix properties
    dialog box and specify the sort expression on "Sorting" tab as follows:
    =Fields(Parameter!parametername.value).value
    If the parameter allow multiple values and you want to sort the report data by more than one field, for example, sort the report data by "accountname" and then by "firstname", please add two sort expressions as follows:
    =Fields(Parameter!parametername.value(0)).value
    =Fields(Parameter!parametername.value(1)).value
    If you have any question, please let me know.
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

Maybe you are looking for

  • Problem with Grouping Tag in iTunes

    Hi, I am trying to use getID3 to read the 'Grouping' tag from iTunes. It would seem that iTunes is writing these tags to my MP3 files, as, when I open them in Media Rage the Grouping Tag shows up OK. However, when I then upload the tracks to my serve

  • Resource / Cost Loading Schedule

    I am seeking some ideas about Resource Loading and Cost Loading schedules in P6. My Resources are the subcontractors on the project. Each Subcontractor is the Resource for series of activities. The Resource Type is "Labor" and we plug Labor Units for

  • Mounting drives using LabVIEW

    Hi all, To start off, I'm using LabVIEW 2011 on a Windows 7 machine. I've been mounting flash drives to a work computer, so that I can plug in more than 26 flash drives at a time, and now I've been asked to create a LabVIEW program that can mount the

  • Problems when Exporting large PDF files.

    Hi there, We're trying to run a scheduled report that's huge and the PDF would usually be about 2,000 pages. The smaller resultset of about 1000 pages would work eventually, but 2000 seems to be not working. We're using BOXI R2 in our servers right n

  • Wie löscht man einzelne Bilder aus einer Slideshow?

    Ich finde keinen Befehl dazu!