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

Similar Messages

  • Sorting elements within an array

    Hi, I'm working on a small piece of software and I've got to a little problem. The software has a Train class, which has two integers (departureTime and arrivalTime). In my main controlling class, there are methods to add Trains to a Trains array (called "trains"), to delete these trains, to display the trains present in the form of a timetable, etc.
    I am trying to get it so that the trains, when the user decides to display the timetable, are display in ascending order based on their departureTime. I can't use a simply Array.sort() as the array is an array of Train objects, and not of the integers themselves.
    I've played round with FOR loops, etc. I have a Time class, which has in it a method that goes as follows...
    public int compare(Time t) {
    // compare this Time with Time t
    if (this.minutes == t.minutes) return 0;
    if (this.minutes > t.minutes) return 1;
    return -1;
    So I can easily find out whether the individual train is sooner or later than the other, but it is a case of doing this in such a way that the trains end up in an order in the array of ascending numerical order by the departureTime.
    A seperate array could be created, "displayTrains" which holds them in, that would be fine. I only need the trains to be sorted by departuretime for the display method, they can be in any order in the rest of the program.
    Any ideas? The following is what I have so far for the display method, though where the sorting code will go there is a comment....
    //method to display the trains currently in the system, in departure time order
    public static void displayTrains() {
    String trainsDisplay="", sdeptTime, sarrTime, sjourTime;
    Time deptTime = new Time();
    Time arrTime = new Time();
    Time jourTime = new Time();
    Time sortDeptTimeA = new Time();
    Time sortDeptTimeB = new Time();
    Train [] displayTrains = new Train[numberTrains];
    int counter1=0, counter2=0, counter=0, compare, arrayPos=0;
    boolean earlier=false;
    //code to sort here
    trainsDisplay = "Loughborough to Leicester Train Timetable:\n\n";
    for (counter=0; counter<numberTrains; counter++) {
    deptTime = trains[counter].getDepartureTime();
    arrTime = trains[counter].getArrivalTime();
    jourTime = trains[counter].getJourneyTime();
    sdeptTime = deptTime.toString();
    sarrTime = arrTime.toString();
    sjourTime = jourTime.toString();
    trainsDisplay = trainsDisplay + "Departure: " + sdeptTime +
    " Arrival: " + sarrTime + " Duration: " + sjourTime + "\n";
    JOptionPane.showMessageDialog(null, trainsDisplay);
    I would really appreciate any ideas people have, I'm learning Java at the moment, so if its really simple, then the code would also be greatly appreciated!
    Kindest regards,
    David.

    Okay, create another class that implements the Comparator interface, e.g.TrainComparator and then one of its methods should be compareTo(Object,Object)
    public class TrainComparator implements Comparator {
        public int compareTo(Object o1, Object o2) {
    }How compareTo is implemented is up to you. But you should return a negative int if o1 is less than o2, 0 if o1 is equal to o2 and a positive integer if o1 is greater than o2. You can cast o1 and o2 as Train objects and call methods from that class to help you.

  • Can't duplicate movieclips as an array within an array

    Hello.
    I have an animation that loads an xml into it and traces back
    an array within an array. I have tried to apply this to duplicated
    movieclips thereby creating a structured set of links. What I am
    trying to do is this:
    Chicken Nuggets
    __Compression
    __Texture
    __Disgust
    Mega Warhead
    __Taste
    __Hardness
    __Pain
    This traces fine but I can't seem to get the duplicated
    movieclips to assemble in this fashion.
    The code for the XML is as follows:
    var controlArray:Array;
    var variable:Array;
    var testTopic = new Array ();
    var test = new Array ();
    var controlsXML:XML = new XML();
    controlsXML.ignoreWhite = true;
    controlsXML.onLoad = function(success:Boolean){
    if (success){
    var mainnode:XMLNode = controlsXML.firstChild;
    var controlNodes:Array =
    controlsXML.firstChild.firstChild.firstChild.firstChild.childNodes;
    var list:Array = new Array();
    for (var i:Number = 0; i < controlNodes.length; i++) {
    var personnode:XMLNode = controlNodes
    .attributes.Name;
    trace(personnode);
    testTopic.push (new struct (personnode));
    var specificNode:Array = controlNodes.childNodes;
    for (var j:Number = 0; j < specificNode.length; j++){
    var itemnode:XMLNode = specificNode[j].attributes.Variable;
    trace(itemnode);
    test.push (new struct2 (itemnode));
    printer ();
    printer2 ();
    } else {
    trace('error reading XML');
    controlsXML.load ("controls3.xml");
    The code for the movieclip duplication is as follows:
    x = 50;
    function printer ()
    for (m = 0; m < testTopic.length; m++)
    duplicateMovieClip ( slotTopic, "slotTopic" + m, m );
    slotTopic = eval ( "slotTopic" + m );
    slotTopic._y += x;
    slotTopic.slotTopicContent.text = testTopic[m].personnode;
    function printer2 ()
    for (k = 0; k < test.length; k++)
    duplicateMovieClip ( slot, "slot" + k, k );
    slot = eval ( "slot" + k );
    slot._y += x;
    slot.slotContent.text = test[k].itemnode;
    function struct (personnode)
    this.personnode = personnode;
    function struct2 (itemnode)
    this.itemnode = itemnode;
    On the stage are two movieclips, titled "slotTopic" and
    "slot". Within those are dynamic text boxes titled respectively
    "slotTopicContent" and "slotContent". When I preview this file it
    only displays the text within the "slot" movieclip and it lists all
    six of the subtopics with no break. So, there are two dilemmas:
    1) The movieclips won't duplicate into the structured set of
    links that I want.
    2) "slotTopic" is not displaying text at all.
    If anyone has any advice, I'd really appreciate it.
    Thx!

    ok, I'm sorry but there are quite a few things wrong here.
    first though, when posting code please use the 'attach code'
    button.
    1) i can't imagine that you have a XML structure as deep as
    your calling to or the need for it with the limited amount of
    infomation your pulling, in addition your storing the info in
    attributes, so I can't see how this would work, it may 'trace' out
    the right text (somehow) but it's not getting into the arrays
    properly.
    2) you do not assign an attribute value to a XMLNode, and
    then try to push it into an array.
    3) you do not call a method (struct or struct2) using the
    'new' operator. this is how you envoke a new 'class' instance.
    4) do not use 'x' as a variable name as it is a reserved var
    in flash, assigned to an Object instance.
    5) the duplicateMovieClip() method needs to be called upon
    the existing clip as in:
    slotTopic.duplicateMovieClip('slotTopic'+m, m);
    additionally you can pass the _y placement within the
    initObject.
    6) you do not need to use eval, it isn't doing anything here,
    you will gain the correct path by calling duplicateMovieClip
    correctly.
    7) the reason why slotTopic is not being displayed at all is
    because of the second loop, you are duplicating the clips
    (incorrectly) into the same depths thereby replacing all of the
    contents of the slotTopic depths previously constructed.
    the solution to this problem is to construct both items with
    the same loop but increament one of the depth assignments by a
    specific number, in other words at depths much higher or at least
    different, than that of the first element, as in:
    slotTopic.duplicateMovieClip('slotTopic'+m, m, {_y:50});
    slot.duplicateMovieClip('slot'+(m+100), m+100, {_y:50});
    again I'm sorry man, but it will take some work to sort this
    out.

  • Error: An integer constant expression is required within the array subscrip

    hello all,
    here is a small piece of code which compile well with g++:
    #include <iostream>
    using namespace std;
    int main () {
    int i= 0, j=4 ;
    cout <<" i=" ; cin >> i ;
    cout  << "i="<<i<< endl;
    if ( i > 1) {
       double xx [i+5];
       int n= i+5;
       for (int k =0 ; k < n ; k++) xx[k] =k;
      cout << "xx[2]=" << xx[2] << " xx[4]=" << xx[4] <<" xx["<<i<<"]="<< xx[i] <<en
    dl;
      cout << "xx[1]=" << xx[3] << " xx[5]=" << xx[4] <<" xx["<<n-1<<"]="<< xx[n-1]
    <<endl;
    }with Sun Studio 12 CC, the error is:
    "x.C", line 12: Error: An integer constant expression is required within the array subscript operator.
    1 Error(s) detected.Is there an option to force CC to accept it? i read that CC has some gnu extensions (http://docs.sun.com/source/820-4155/c++.html)
    Thanks in advance for help,
    gerard

    This works:
    #include <iostream>
    #include <alloca.h>
    using namespace std;
    int main () {
    int i= 0, j=4 ;
    cout <<" i=" ; cin >> i ;
    cout  << "i="<<i<< endl;
    if ( i > 1) {
       double *xx = ( double * ) alloca( sizeof( *xx ) * ( i + 5 ) );
       int n= i+5;
       for (int k =0 ; k < n ; k++) xx[k] =k;
      cout << "xx[2]=" << xx[2] << " xx[4]=" << xx[4] <<" xx["<<i<<"]="<< xx[i] <<en
    dl;
      cout << "xx[1]=" << xx[3] << " xx[5]=" << xx[4] <<" xx["<<n-1<<"]="<< xx[n-1]
    <<endl;
    }

  • 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 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

  • Change value of string within an array?

    Alright, so im trying to change "hello" to "Aello", there fore im changing the first letter of the string to an "A". This string is within an array:
    This is what i have:
    System.out.println ((char)split[1].charAt(0))='a');
    but im getting an error

    I think you mean:
    split[1] = "a" + split[1].substring(1);
    System.out.println(split[1]);
    Strings are immutable which means they cant be changed. The only
    thing you can do is create new Strings.
    hello <- you cant make the 'h' an 'a'
    a + ello <- but you can create a new string from 'a' and the rest of 'hello'
    Edited by: TuringPest on Nov 25, 2007 10:01 PM

  • 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]

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

  • Custom sorting within "for-each-group:current-group"

    Hi, I need some help in doing a custom sort within a "for-each-group:current-group". My formatting is in a table format but I'm not sure how to post a table here so I'm just arranging the column details out as it would look in a table. I have a column on the left for the YEAR and a second column on the right for the DESCR. Under the DESCR column I've inserted a nested table with four columns: SUBJECT, CATALOG_NBR, DESCR250 and GRADE.
    COLUMN 1:
    <?for-each-group:row_table;./ YEAR?><?sort: YEAR;'ascending';data-type='text'?><?YEAR?>      
    COLUMN 2:
    <?for-each-group:current-group();./DESCR?><?DESCR?>
    NESTED TABLE (with 4 columns):
    +<?for-each:current-group()?><?SUBJECT?><?CATALOG_NBR?><?DESCR250?><?GRADE?><?end for-each?>+
    <?end for-each-group?> <?end for-each-group?>
    I'm able to sort by YEAR in the "for-each-group" on the left column. But I also want to do a custom sort on DESCR in the right column.
    I've seen this blog on custom sorting by Vetriselvan: http://winrichman.blogspot.com/2009/09/custom-dynamic-sort-in-bi-publisher.html and I tried inserting this sort below after <?for-each-group:current-group();./DESCR?> but I get an error message.
    <?sort:(number(DESCR='Status')*1)+(number(DESCR='First Semester')*2)+(number(DESCR='Second Semester')*3);'ascending';data-type='number'?>
    I've also seen this thread: Re: Sort within group and tried inserting <?for-each:DESCR?> before the sort (as below) - this time I can preview the results, but it is not sorting as required.
    <?for-each:DESCR?><?sort:(number(DESCR='Status')*1)+(number(DESCR='First Semester')*2)+(number(DESCR='Second Semester')*3);'ascending';data-type='number'?>
    Can anyone help me custom sort the DESCR column? I'm using Template Builder for Word version 5.6 build 45. Thanks in advance for any help!

    Hi Vetsrini,
    I tried adding <?sort: ./DESCR;'ascending';data-type='text'?> after <?for-each-group:current-group();./DESCR?> but I'm getting an error message.
    The DESCR values are below and I'm trying to sort them in the following order.
    STATUS
    SUMMER SEMESTER
    FIRST SEMESTER
    AUTUMN SEMESTER
    WINTER SEMESTER
    SECOND SEMESTER
    SPRING SEMESTER
    Because I need them in the above order, I can't use ascending or descending, and instead need to use a custom sort order. Do you know how I can go about creating a custom sort order?
    Thanks!

  • How can i sort out the N lowiest elements from an 1D array faster than using the build in sort function (1D-array) in Labview?

    I need an algorithm that is based on the same sorting-algorithm that Labview uses (or one that is just as fast) but it only needs to sort out the N lowiest elements (and the N-element output array don't need to be sorted).
    /Jonas

    I want all three zeros in the output. You can se the algorithm that I'm looking for as a soft version of Labviews own sort algorithm that only gives you the N (always less then the length of the array) lowiest values as output.If two elements contain the same small value both should be sorted out.
    /Jonas

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

  • Not able to use @section and Sort within a group in RTF Template

    When i try to use sort with for-each-group@section in my template, the Output Post processor is throwing the following exception
    Caused by: oracle.xdo.parser.v2.XSLException: <Line 31, Column 84>: XML-22047: (Error) Invalid instantiation of 'xsl:sort' in 'fo:flow' context.
    My tags in the RTF template are as below:
    <?for-each-group@section:G_PERSON_ID;./DEPT?><?sort:DEPT;'ascending';data-type='text'?>
    -- there are 2 more groups within this.
    <?end for-each-group?>
    I don't get the error if i remove @section from the above tag in my RTF template.
    OR
    IF i remove the sort tag and keep the @section , it still works.
    I need the "sort" so that i can sort the output by department number and I need the "section" so that i can acheieve context based header title for the page using the tag given below in the header area of the word RTF doc. The DEPT number should change as per the data shown in the report.
    DEPT <?DEPT?> CLASSIFICATION SENIORITY LISTING BY CLASS CODE & DATE
    I am stuck with either being able to use the Sort or the Header feature but not both.
    I guess that section is needed for the context based header title to work, because all the data shown in the current page should correspond to only one single DEPT value (to make the Header title consistent with the data). But i dont get why i am not able to sort. The exception from OPP simply beats me. Please help!!
    I am using the XML Pub Desktop 5.6.2 to develop my templates.
    Is there any way to acheive this? Can someone throw some light on this.
    Thanks in advance.

    Help About says I'm on 20.0.1
    Up until last week, I was able to use the tab key when typing emails and other multi-line text boxes.
    Suddenly the behavior of the tab key changed. This isn't the first time. It's been quite a while ago that the function of the tab key changed from indenting to moving around the page, then after some time it changed back to indenting.
    Can we get this fixed and leave it alone, please?
    I may give one of those add-ins a try, but my problem with add-ins is that they break when FF is patched or upgraded, then I'm left with out the solution they provide.
    Can we just fix Firefox, please?
    Thanks,
    Frank
    P.S. Another potential fix I came across suggested starting FF in safe mode to see if the problem goes away. It does not. It seems to be a change to FF that appeared after an update last week. On or just befor 24 Apr.

Maybe you are looking for

  • Help with floating a Div tag?

    I am having difficulty properly floating a div tag in my site.  The page is http://www.planetwhistler.com/bandbs.html  The Div on the bottom of the second column with 'content for right_bandb_div' goes here will not properly float to the right of the

  • Problem with logical domain and boot net

    Trying to install a new domain on a T2000. Able to get to "Configuring devices" but then it just sits and twirls... What have I configured wrong in the domain creation? I have: {0} ok show-devs /cpu@7 /cpu@6 /cpu@5 /cpu@4 /cpu@3 /cpu@2 /cpu@1 /cpu@0

  • IDOC urgent

    Hi Gurus i have to make a new field into a standard segment E!MBXYH mess type wmmbxy can i enter a new field into a new segment? please provide me with the solution

  • DDK - How to install only the Driver development kit ??

    Hi Colleagues - I can't, for the life of me, figure out exactly how to go about installing JUST the DDK from the custom (custom/expand installation) menu option when launching setup.exe from a supported Windows 2003 server. I've tried "Generic ODBC,

  • How do I locate my serial number for Dreamweaver?

    I bought and downloaded Dreamweaver 2 months ago (March 2015) but had to re-install as my computer died but now I cannot find the Serial Number to activate it on my new computer. I cannot find the original email and there is no reference to serial nu