Help with sorting a deck class

I am using this from a card class...and am trying to sort the cards in numeric order, but keep getting errors
public class Deck
private int top;
private int count;
private int deckSize;
Card [] cards=new Card[53];
public Deck()
for (int x=0; x<cards.length; x++)
cards[x]=new Card();
deckSize++;
for (int z=0; z<cards.length; z++)
for (int x=0; x<4; x++)
if(cards[z].suit==x)
for (int y=1; y>14; y++)
if (cards[z].value==y)
int cardLen=cards.length;
Card temp=new Card(cards[z.suit],cards[z.value]);
cards[z]=cards[cardLen-z-1];
cards[cardLen-z-1]=temp;
}

tjacobs01 wrote:
Create a java.util.Comparator for your cards, and then use Arrays/Collections.sortArr, ye mateys! Swap the deck!

Similar Messages

  • Help with Sort function in Terminal

    Hello all... this is my first post on here as I'm having some trouble with some Termianl commands. I'm trying to learn Terminal at the moment as it is but I would appreciate some help with this one....
    I'm trying to sort a rather large txt file into alphabetical order and also delete any duplicates. I've been using the following command in Terminal:
    sort -u words.txt > words1.txt
    but after a while I get the following error
    sort: string comparison failed: Illegal byte sequence
    sort: Set LC_ALL='C' to work around the problem.
    sort: The strings compared were `ariadnetr\345dens\r' and `ariadnetr\345ds\r'.
    What should my initial command be? What is Set LC_ALL='C'?
    Hope you guys can help?

    Various languages distinct sorting - collation - sequences. 
    The characters can and variously do sort differently, depending on what language is involved. 
    Languages here can include the written languages of humans, and a few settings associated with programming languages.  This is all part of what is known as internationalization and localization, and there are are various documents around on that topic.
    The LC_ALL environment variable sets all of the locale-related settings en-mass, including the collation sequence that is established via LC_COLLATE et al, and the sort tool is suggesting selecting the C language collation.
    Here, the tool is suggesting the following syntax:
    LC_ALL=C sort -u words.txt > words1.txt
    This can also be done by exporting the LC_ALL, but it's probably better to just do this locally before invoking the tool.
    Also look at the lines of text in question within the files, and confirm the character encoding of the file.
    Files can have different character encodings, and there's no reliable means to guess the encoding.  For some related information, see the file command:
    file words.txt
    ...and start reading some of the materials on internationalization and localization that are posted around the 'net. Here's Apple's top-level overview.
    In this case, it looks like there's an "odd" character and probably an å character on that line and apparently the Svenska ariadnetrådens. 
    Switching collation can help here, or - if the character is not necessary - removing it via tr or replacing it via sed can be equally effective solutions. 
    Given it appears to be Svenska, it might work better to switch to Svenska collation thanto  the suggested C collation.
    I think that's going to be sv_SE, which would make the command:
    LC_ALL=sv_SE sort -u words.txt > words1.txt
    This is all generic bash shell scripting stuff, and not specific to OS X.  If you haven't already seen them, the folks over at tldp have various guides including a bash guide for beginners, and an advanced bash scripting guide - both can be worth skimming.  They're not exactly the same as bash on OS X and some specific commands and switches can differ, and as bash versions can differ, but bash is quite similar across all the platforms.

  • Help with sorting a list

    Hi,
    can anyone help me with sorting of a list by date?
    I have like 5 objects in the list, 4 are string and one is list.
    I want to sort them by Date..
    How can I do that?
    I don't know if I can use CompateTo?? I am new to programing, I would appreciate if anyone can explain with sample code.
    Your help is appreciated.

    ASH_2007 wrote:
    Hey thanks for your response, but there is a little problem with what I said earlier.
    Actually my List is a type of record (it's called Employee record)
    Here what exactly I have:
    for Iint i=0; i< employeeRecord.getList().size(); i++)
    EmployeeRecord emp = employeeRecord.getList().get(i);
    //so if I can not hold my date information in an object, coz it's says type mismatch
    //I am not sure how can I do this?
    }Can you please help with sample code?
    Thanks tonsEither cast or learn about generics. Also, use an Iterator or a foreach loop, NOT get(i).
    [Collections tutorial|http://java.sun.com/docs/books/tutorial/collections/]
    [Generics intro|http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html]
    [Generics tutorial|http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf]
    Foreach

  • Help with dynamic creation of class object names

    Hi all
    Wonder if you can help. I have a class player.java. I want to be able to create objects from this class depending on a int counter variable.
    So, for example,
    int counter = 1;
    Player p+counter = new Player ("Sam","Smith");the counter increments by 1 each time the method this sits within is called. The syntax for Player name creation is incorrect. What I am looking to create is Player p1, Player p2, Player p3.... depending on value of i.
    Basically I think this is just a question of syntax, but I can't quite get there.
    Please help if you can.
    Thanks.
    Sam

    here is the method:
    //add member
      public void addMember() {
        String output,firstName,secondName,address1,address2,phoneNumberAsString;
        long phoneNumber;
        boolean isMember=true;
        this.memberCounter++;
        Player temp;
        //create HashMap
        HashMap memberList = new HashMap();
        output="Squash Court Booking System \n";
        output=output+"Enter Details \n\n";
        firstName=askUser("Enter First Name: ");
        secondName=askUser("Enter Second Name: ");
        address1=askUser("Enter Street Name and Number: ");
        address2=askUser("Enter Town: ");
        phoneNumberAsString=askUser("Enter Phone Number: ");
        phoneNumber=Long.parseLong(phoneNumberAsString);
        Player p = new Player(firstName,secondName,address1,address2,phoneNumber,isMember);
        //place member into HashMap
        memberList.put(new Integer(memberCounter),p);
        //JOptionPane.showMessageDialog(null,"Membercounter="+memberCounter,"Test",JOptionPane.INFORMATION_MESSAGE);
        //create iterator
        Iterator members = memberList.values().iterator();
        //create output
        output="";
        while(members.hasNext()) {
          temp = (Player)members.next();
          output=output + temp.getFirstName() + " ";
          output=output + temp.getSecondName() + "\n";
          output=output + temp.getAddress1() + "\n";
          output=output + temp.getAddress2() + "\n";
          output= output + temp.getPhoneNumber() + "\n";
          output= output + temp.getIsMember();
        //display message
        JOptionPane.showMessageDialog(null,output,"Member Listings",JOptionPane.INFORMATION_MESSAGE);
      }//end addMemberOn running this, no matter how many details are input, the HashMap only gives me the first one back....
    Any ideas?
    Sam

  • Help with sort please

    I have my first java assignment to hand in on monday and im having a few problems and was wondering if someone could help me solve the problem.
    I have to display the most frequently occuring double of a set of dice the problem is that I seem to be only able to display the amount of times it was rolled rather than the actually double.
    I would really appreciate some help in this matter.
    Thanks
    import cs1.*;
    import java.util.*;
    public class TestDice
              public static void p(String s)
                   System.out.print(s);
              public static int sort(int[] dubs)
                     int x,y,max=0,temp;
                     for (x = 0; x < 6 ; x++)
                       max = x;
                        for (y = x+1; y < 6; y++)
                              if (dubs[y] > dubs[max])
                                max = y;
                        temp = dubs[x];
                        dubs[x] = dubs[max];
                        dubs[max] = temp;                 
                   return max;
              public static void main(String[] args)
               PairOfDie dice; 
               int noRolls,x,doubles=0;
                 int [] dubs;
                 dice = new PairOfDie();                   
               dubs = new int[6];
                 p("\n\n");
               for (noRolls=0; noRolls < 1000; noRolls++)
                   dice.roll();
                   p("" + dice.getDice1() + "," + dice.getDice2() + "   ");
                      for (x=0;x<6;x++)
                           if(dice.getDice1() == (x+1) && dice.getDice2() == (x+1))
                                 dubs[x]++;
                 occurences(dubs);              
                 p("\n\n\n(B) Display the most frequently occuring double or doubles = " +  dubs[0]);
                 histogram(dubs);
            }//End of Main
              public static void occurences(int[] dubs)
                      int x,max;
                    p("\n\n(A) Count and display the occurences of each of the doubles");
                      p("\n\n Double\tOccurences\n ------\t----------\n");
                      for (x=0;x<6;x++)
                          p("\n   " + (x+1) +" \t\t    " + dubs[x]);
              }//End of Occurences
              public static void histogram (int [] dubs)
                   int y,x;
                   p("\n\n\n(C) Draw a Histogram of the occurences of each of the doubles");
                   p("\n\n Double\t    Occurences\n ------\t    ----------\n");
                   for(y=0;y<6;y++)
                        p("\n   " + (y+1) + "\t\t    ");
                        for (x=1; x<=dubs[y];x++)
                             p("*");
                   p("\n\n");
              }//End of Histogram
    }//End of Class

    > No I cant thats why I am doing a course in it at the moment,
    I said, then at the end. So if mlk can't read, then you can't program. I also posted a smiley to emphasize it was more of a cynical remark of me.
    > I was not looking for someone to do my
    homework I had a question regarding a sorting
    problem.
    I'm sure you aren't, but I don't see a question in there. I can only see a bunch of lines without comments. You also didn't provide some sample in/output, but only wrote "I want to do Y, but are only able to do X...".
    I have told you this before:
    Try to look at your own post as if you had never seen it, and are not familiar with the exact assignment. Would you be able to post a meaningfull answer to your "question"? I don't think so.
    In previous posts you were given numerous links to basic tutorials (including sorting tutorials) which you apparently didn't read. That's too bad.
    > Im sure everyone wont be as ignorant
    What do you mean by that?

  • Need help with AS 2 Tween class

    Hi,
    I'm using the tween class just fine, but I want my tween to
    move on a curve.
    I can't seem to figure out how to achievve this.
    I get the math to do this sort of thing, and I think I could
    manage it with
    AS3, but the project requires the use of AS2. I'm having
    issues
    transitioning what I know to what I need.
    Can anyone help??
    Thanks,
    KB

    you can use the tween class to update an object property and,
    if you have a parametric equation for your curve, you can use your
    tween's onMotionChanged event to update your object's _x and _y
    properties.

  • Help with Sort sequence and reset preferences

    Hi,
    I have checked the "sort" checkboxes and the "sort sequence" in my first 5 columns of the sql report. The sequence are straight 1,2,3,4,5.
    I have also create two buttons. The first one that will trigger a pl/sql that would execute RESET_USER_PREFERENCES built-in package, and a second button that just submit. The page submit to itself by default.
    It appears that the Reset Preferences does not follow the "sort sequences". Take a look at: http://htmldb.oracle.com/pls/otn/f?p=15031:2:
    Check what happen with the second column OBJECT NAME: I expect to see CUSTOM_AUTH first and then CUSTOM_HASH second once you Reset User Preferences. Interesting is that when I just press the refresh button, then i get what I want, but i think that is just coincidence as there is not guarantee that the data are going to be displayed in that order once you start deleting and inserting in the middle.
    Any help in order to understand the "sort sequences" concept is appreciated.
    Thanks

    Anybody?

  • Help with java (2 simple classes)

    would anyone be able to help me with some questions about two very short java classes?
    i have come up with some answers of my own, but yeah, i'm not sure how correct my answers are....
    the 4 questions are:
    1. The data attributes m, n and grid in the HeatGrid class are declared private, and methods
    such as gridHeight(), gridWidth() and copyGrid() are provided to extract their value. Why
    is the better class design than simply declaring those attributes as public?
    My answer: So other classes accessing them cannot modify those data atributes, i am not sure why this is better class design.
    2. Why must the (global) constants in HeatSim.java be declared static ?
    My Answer: because HeatSim is what you run first and so you don't create a HeatSim object, you just access its methods, thus the need to make them static.
    3. Assuming HeatGrid has been fully implemented, during the execution of the statement
    HeatGrid = new HeatGrid(inGridFile), how many objects of HeatGrid, double [][] and
    Scanner are created?
    My Answer: 1 HeatGrid object, 1 doulbe[][] object and 1 scanner object
    Which of these objects must still exist after the statement completes execution?
    4. For each of the classes HeatSim and HeatGrid, identify the client and supplier classes
    (including library classes).
    My Answer: So far this is what i have done. for the HeatSim class, i said that the supplier classea are:
    double
    int
    boolean
    String
    Math Class
    viewgrid class
    array
    and the clients for the HeatSim class are:
    HeatGrid class
    if anyone can help me i will but up the VERY short code to these two classes. I am really stuck and any help woould be greatly appriciated! :)
    Lots o love
    Sarah

    ok here is the code (i don't have my compelted copy on me but this will do for the moment).....
    import java.lang.Integer;
    import java.lang.Double;
    import java.text.DecimalFormat;
    public class HeatSim {
        final static boolean ENABLE_VIEW = true; // if true, create GUI to view grid
        final static double DEFAULT_THR = 1.0e-02;
        final static int DEFAULT_PAUSE = 100; // pause between each update of window in ms
        final static int DISPLAY_WIDTH = 7;   // width to print each grid value
        final static int MAX_MN_DISPLAY = 10; // maximum grid size to be displayed
        public static void main(String[] args) {
            // initialize program `parameters' according to the command line,
            // entering `default' values if none were given
            String inGridFile = (args.length < 1)? "": args[0];
            int nIter = (args.length < 2)? 1: Integer.parseInt(args[1]);
            double Thr = (args.length < 3)? DEFAULT_THR: Double.parseDouble(args[2]);
            String dumpFile = (args.length < 4)? "": args[3];
         DecimalFormat residFormat = new DecimalFormat("0.00E0");
            ViewGrid view = null;
            System.out.println("HeatFlow simulation program");
            if (inGridFile.equals("")) {
                System.out.println("Error: an empty grid file name was entered");
                return;
            // create HeatGrid object
            HeatGrid heatGrid = new HeatGrid(inGridFile);
            int m = heatGrid.gridHeight();
            int n = heatGrid.gridWidth();
            if (m <= MAX_MN_DISPLAY  && n <= MAX_MN_DISPLAY) {
                System.out.println("\nGrid at time 0:" );
                heatGrid.display(DISPLAY_WIDTH);
            if (ENABLE_VIEW) {
                // create a ViewGrid WINDOW object to view the grid
                view = new ViewGrid(m+2, n+2, DEFAULT_PAUSE);
                view.display(heatGrid.time(), 0.0, heatGrid.copyGrid());
            while (heatGrid.time() != nIter && heatGrid.residual() > Thr) {
                heatGrid.iterate();
                if (m <= MAX_MN_DISPLAY  && n <= MAX_MN_DISPLAY) {
                    System.out.println("Grid at time " + heatGrid.time() +
                                    " has residual " +
                         residFormat.format(heatGrid.residual()));
                    heatGrid.display(DISPLAY_WIDTH);
                if (ENABLE_VIEW) {
                     view.display(heatGrid.time(), heatGrid.residual(),
                                  heatGrid.copyGrid());
            } //while(...)
            if (ENABLE_VIEW) {
                view.finalize();
            if (!dumpFile.equals("")) {
             heatGrid.dumpGrid(dumpFile);
            System.out.println("\nHeat Flow simulation of (" + m + "+2)x(" + n +
                               "+2) grid ends at time " +  heatGrid.time() +
                               " with residual " +
                      residFormat.format(heatGrid.residual()));
        } //mainProgram()
    } //HeatSim
    import java.util.Scanner;
    import java.io.*;
    import java.text.DecimalFormat;
    public class HeatGrid {
        private int m, n;
        private double[][] grid;     // m+2 x n+2 array representing a grid
        private int t;               // the time the grid has been evolved
        private double resid;        // residual left from the last timestep
        // initializes m, n and grid according to the information in the grid file
        // of name gridFileN; sets t to 0, and resid to Double.MAX_VALUE
        public HeatGrid(String gridFileN) {
        } //HeatGrid()
        // returns the value of m
        public int gridHeight() {
            return 0;         // [ replace with an appropriate value ]
        } //gridHeight()
        // returns the value of n
        public int gridWidth() {
            return 0;         // [ replace with an appropriate value ] =
        } //gridWidth()
        // returns the value of t
        public int time() {
            return 0;         // [ replace with an appropriate value ]
        } //time()
        // returns the value of the residual from the previous timestep
        public double residual() {
            return 0;         // [ replace with an appropriate value ]
        } //residual()
        // returns a copy of the grid
        public double[][] copyGrid() {
            return null;         // [ replace with an appropriate value ]
        } //copyGrid
        // precondition: all elements of grid can be printed to 1 decimal place
        // using width characters.
        // prints the m+2 x n+2 grid by rows, rows in descending order.
        // All values are printed to 1 decimal place, and are right-justified
        // in a text field of width characters.
        // Note: this method is for debugging; hence right-justification is useful
        public void display(int width) {
        } //display()
        // advance the simulation a single timestep
        public void iterate() {
         } //iterate()
        // prints the m+2 x n+2 grid by rows, rows in ascending order.
        // All values are printed to 2 decimal places, with at least one space
        // between them.
        // Note: this method is intended for result checking by a computer program;
        // thus justification is not important.
        public void dumpGrid(String outGridFileN) {
        } //dumpGrid

  • Help with "sorting by composer"

    Hello to all of you,
    I'm writing this subject to get some help. I'm trying to sort my music by composers on iTunes 11. So, I write down the "Composer" like "Johann Sebastian Bach", and everything is fine on the composer view : I have "Johann Sebastian Bach" :
    Then I'm going to the "Sort by composer" Field, and I write "Bach" for all the Johan Sebastian Bach Music. I'm closing iTunes and reopen it (or else, composer view is not refreshed - perhaps there is a trick to force refreshing ?) and TADAM, my Bach entry becomes two :
    I've tried to change the view with Option+J, but nothing works, I've got two Johann Sebastian Bach, and two Bach/Busoni.
    So I'm cleaning the "sort by composer" field, and the two Johan Sebastian Bach becomes one entry again.
    It does the same with a lot of others composers. Don't know how to get the things right...
    Could someone help me ?
    Thanks in advance.

    Hi,
    Try adding Bach, Bach Busoni, Bach Hess etc in sort by composer field. Does this help.
    Jim

  • Please help with setData of Datagram class

    hi
    im new to J2ME stuff. while working with BOOK "wireless java programming with java 2 micro edition" i encountered a problem in networking chapter.
    Im gating NULLPointer Exception while using setData() method of Datagram Class
                   byte[] message = new byte[length];
                   System.arraycopy(msg.getBytes(),0,message,0,length);
    // null poninter exception// sendDatagram.setData(message,0,length);
                   sendDatagram.setLength(length);
    the whole code of client program is as...
    import javax.microedition.midlet.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    public class DatagramClient extends MIDlet implements CommandListener{
         private Form mainScreen;
         private TextField sendingField;
         private Display myDisplay = null;
         private DatagramClientHandler client;
         //define the GUI components for displaying the returned message
         private Form resultScreen;
         private StringItem resultField;
         private String resultString;
         Command sendCommand = new Command("SEND",Command.OK,1);
         public DatagramClient() {
              //intialize the GUI components
              myDisplay = Display.getDisplay(this);
              mainScreen = new Form("Datagram Client");
              sendingField = new TextField("Enter your message",null,30,TextField.ANY);
              mainScreen.append(sendingField);
              mainScreen.addCommand(sendCommand);
              mainScreen.setCommandListener(this);
         public void startApp(){
              myDisplay.setCurrent(mainScreen);
              client = new DatagramClientHandler();
         public void pauseApp(){
         public void destroyApp(boolean unconditional){
         public void commandAction (Command c, Displayable s) {
              if(c==sendCommand){
                   //get the message text from user input
                   String sendMessage = sendingField.getString();
                   try{
                        resultString = client.send_receive(sendMessage);
                   }catch(IOException e){
                        System.out.println("Failed in Send_receive(); "+e);
                   resultScreen = new Form ("Message confirmed:");
                   resultField = new StringItem(null,resultString);
                   resultScreen.append(resultField);
                   resultScreen.setCommandListener(this);
                   myDisplay.setCurrent(resultScreen);
         public class DatagramClientHandler extends Object {
              private DatagramConnection dc;
              private Datagram sendDatagram;
              private Datagram receiveDatagram;
              public DatagramClientHandler() {
                   try{
                        dc = (DatagramConnection)Connector.open("datagram://"+":9000");
                        receiveDatagram = dc.newDatagram(dc.getMaximumLength());
                   } catch(IOException e){
                        System.out.println(e.toString());
              public String send_receive(String msg) throws IOException {
                   int length = msg.length();
                   System.out.println("length of string "+length+"message "+msg);
                   byte[] message = new byte[length];
                   System.arraycopy(msg.getBytes(),0,message,0,length);
                   System.out.println("message is : "+message+" length is "+length);
                   sendDatagram.setData(message,0,length);
                   sendDatagram.setLength(length);
                   String retval = "";
                   try{
                        dc.send(sendDatagram);
                        dc.receive(receiveDatagram);
                        byte[] data = receiveDatagram.getData();
                        retval = new String(data,0,receiveDatagram.getLength());
                   }catch (Exception e ){System.out.println("sirfra excep: "+e);}
                   finally{
                        if(dc!=null) dc.close();
                   return retval;
    sir i hav to submit an assignment on networking and RMS on thursday. so please help me as early as possible . ill be really very thankful to you.

    please change "sendDatagram" to "receiveDatagram"
    public String send_receive(String msg) throws IOException {
    int length = msg.length();
    System.out.println("length of string "+length+"message "+msg);
    byte[] message = new byte[length];
    System.arraycopy(msg.getBytes(),0,message,0,length);
    System.out.println("message is : "+message+" length is "+length);
    sendDatagram.setData(message,0,length);
    sendDatagram.setLength(length);

  • Help with first approach to Class and Constructor

    Hello guys
    I have a homework but I'm totally lost.
    Here is the assignment:
    **Write the fields, the constructor and the methods of the class below.**
    **public class HourlyEmployee**
    **The class has 4 private fields:**
    **private String name; // the name**
    **private String position; // the position in the company**
    **private double rate; // the hourly rate**
    **private double hours = 0.0; // the hours that the employee worked**
    **The constructor has the header**
    **public HourlyEmployee( String n, Spring pos, double pay)**
    **that puts n into name, pos into position, and pay into rate.**
    **The class has the methods below.**
    **public String getName()**
    **public String getPosition()**
    **public double getRate()**
    **public double getHours()**
    **public void setName(String newName)**
    **public void getARaise(double inc)**
    **public void work(double time)**
    **public double getPaid()**
    **public boolean equals(HourlyEmployee other)**
    **public String toString()**
    **The first 4 methods return the name, the position, the rate**
    **and the hours, in this order.**
    **The method getARaise adds inc to rate.**
    **The method work adds time to hours.**
    **The program getPaid computes and returns the weekly pay.**
    **The worker gets paid one time and a half for overtime (over**
    **40 hours of work). Don't forget to reset hours to 0 before**
    **you leave this method.**
    **The method**
    **public boolean equals(HourlyEmployee other)**
    **returns true if this is equals to other and false**
    **if they are not. Two hourly employees are equal**
    **if they have the same name, the same position and**
    **the same rate.**
    **The last method returns the string**
    **HourlyEmployee[name = ...][position = ....][rate = ...]**
    **where ... stands for the name, position, and the rate**
    **of the employee.**
    Here is what I have so far:
    public class HourlyEmployee
    *// the fields*
    private String name; // the name
    private String position; // the position in the company
    private double rate; // the hourly rate
    private double hours = 0.0; // the hours that the employee worked
    *// This constructor sets the name, position and rate*
    */ @param n is the name*
    *@param pos is the position*
    *@param pay is the rate*
    public HourlyEmployee( String n, String pos, double pay)
    name = n;
    position = pos;
    rate = pay;
    *//get a new name*
    *//@param newName is the new name to be entered*
    public void setName (String newName)
    <
    +//get a raise+
    +//@param inc is the amount to be increased+
    public void getARaise (double inc)*
    *+{+*
    rate = inc;*
    System.out.println ("The rate is " rate);*
    +}+
    +//get the time worked+
    +//@param time is the amount of hours worked+
    public void work (double time)*
    *+{+*
    hours = time;*
    System.out.println ("The amount of hour is " hours);*
    +}+
    +//get the amount paid+
    +//@param rate is the amount of money+
    public void getPaid ()*
    *+{+*
    rate = hours;*
    if ( hours > 40 )*
    rate = 1.5; *
    System.out.println ("The amount paid is " rate);*
    *//compare employees*
    *//@param rate*
    public boolean equals (HourlyEmployee other)
    return rate == other.rate
    *&& name.equals (other.name);*
    But I don't really understand what's going on.
    What is the difference between setName and getName?
    Didn't the constructor set the name, the position and the rate already?
    I don't know where I'm standing or where I'm going.
    Any help?
    Thank you

    Ok, this is what I have so far:
    public class HourlyEmployee
             // the fields
            private String name; // the name
            private String position; // the position in the company
            private double rate; // the hourly rate
            private double hours = 0.0; // the hours that the employee worked
            // This constructor sets the name, position and rate
            /* @param n is the name
             * @param pos is the position
             * @param pay is the rate
            public HourlyEmployee( String n, String pos, double pay)
              name = n;
              position = pos;
                    rate = pay;
            //@param returns the name
            public String getName()
            return name;
            //@param returns the employee position
            public String getPosition()
            return position;
            //@param returns the hourly rate
            public double getRate()
            return rate;
            //@param returns the hours
            public double getHours()
            return hours;
            //get a new name
            //@param newName is the new name to be entered
            public void setName (String newName)
                    name = newName;
            //get a raise
            //@param inc is the amount to be increased
            public void getARaise (double inc)
                    rate += inc;
            //get the time worked
            //@param time is the amount of hours worked
            public void work (double time)
                    hours += time;
            //get the amount paid
            //@param rate is the amount of money
            public double getPaid ()
                   if ( hours > 40 )
                       double payment = rate*hours*40 + 1.5*rate*(hours-40);
                       double payment = rate * hours;
                    hours = 0.0;
            //compare employees
            //check if name, position and rate are the same
            public boolean equals (HourlyEmployee other)
            return name.equals (other.name)
                && position.equals (other.position)
                && rate == other.rate;
            //This method returns a string
            // with the name, position and rate of the employee
            public String toString()
                String myString = "HourlyEmployee[name =" + name
                        + "][position = " + position + "][rate= "
                        + rate + "]";
    }Now I have 2 problems:
    - The method getPaid is specified to return a double and gives me the error "missing return statement". How can I make it return a double?
    - The public String toString gives me the same error, I don't know why
    Any help?

  • Help with GUI (calling one class from other class)

    Hi everybody,
    I am new at GUI and I need your help..
    I have a JPanel, named "holdAll", layout of which is set to BorderLayout. I have implemented all other JPanels in different class files. For example, I have TopPanel, LeftPanel, etc. as shown below
    LeftPanel myLeft = new LeftPanel();
    holdAll.add(myLeft, BorderLayout.WEST);
    RightPanel myRight = new RightPanel();
    holdAll.add(myRight, BorderLayout.EAST);
    TopPanel myTop = new TopPanel();
    holdAll.add(myTop, BorderLayout.NORTH);
    MiddlePanel myMiddle = new MiddlePanel();
    holdAll.add(myMiddle, BorderLayout.CENTER);
    BottomPanel myBottom = new BottomPanel();
    holdAll.add(myBottom, BorderLayout.SOUTH);
    That works well but I have difficulties in ActionListeners.. For example, in my TopPanel class I have the code below:
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnInsert) {
    int returnVal = fc.showOpenDialog(fc);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    myImage newImage = new myImage(file);
    System.out.println(newImage.myHashCode());
    Here, if I have upload new image, then I have to update the listImage in the LeftPanel class.. But, I could not access the lstImage object in the LeftPanel class from the actionListener event in the TopPanel class.
    What should I do? Is my design poor?

    public class TopPanel extends JPanel implements ActionListener { //it doesn't allow "extends JPanel, Observable"
    JFileChooser fc;
    JButton btnInsert;
    JButton btnDelete;
    public TopPanel() {
    setLayout(new FlowLayout());
    setBorder(BorderFactory.createBevelBorder(1, Color.WHITE, Color.GRAY));
    btnInsert = new JButton("Insert");
    btnDelete = new JButton("Delete");
    JLabel myLabel = new JLabel(" Search : ");
    JTextField txtSearch = new JTextField();
    txtSearch.setColumns(20);
    JToolBar searchToolBar = new JToolBar();
    fc = new JFileChooser();
    btnInsert.addActionListener(this);
    searchToolBar.add(btnInsert);
    searchToolBar.add(btnDelete);
    searchToolBar.add(myLabel);
    searchToolBar.add(txtSearch);
    add(searchToolBar);
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnInsert) {
    int returnVal = fc.showOpenDialog(fc);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    *//Here I want to send fc.GetName() to the JList in the LeftPanel*
    my LeftPanel class is below:
    public class LeftPanel extends JPanel{
    public LeftPanel(){
    this.setLayout(new BorderLayout());
    setBorder(BorderFactory.createBevelBorder(1, Color.WHITE, Color.GRAY));
    JPanel pnlButtons = new JPanel();
    JButton btnName = new JButton("Name");
    JButton btnSize = new JButton("Size");
    JButton btnDate = new JButton("Date");
    pnlButtons.add(btnName);
    pnlButtons.add(btnSize);
    pnlButtons.add(btnDate);
    pnlButtons.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    JPanel pnlImage = new JPanel();
    JList lstImage = new JList();
    lstImage.setVisible(true);
    pnlImage.add(new JScrollPane(lstImage));
    add(pnlButtons, BorderLayout.NORTH);
    add(pnlImage, BorderLayout.CENTER);
    Is there any simple way?

  • Help with "Sort Artist" please

    Hi all
    What I'm trying to do is use iTunes to make it so that tracks that are by different artists appear under the same artist when I go through the "Artist" field on my iPod Touch.
    For example, I've got songs that are by Prince & the Revolution, songs that are by Prince & the New Power Generation, songs that are by Prince on his own, and songs that are by O(+>. I want iTunes to know that they are by different artists, but I want them to all appear under Prince in the alphabetical list on my iPod. Am I explaining this right?
    So, when I look at my iPod, I go to Prince, and everything by all those other "artists" are under that name, even though the iPod still knows they are credited differently.
    I thought the "Album Artist" field would do it, like you use for Various Artist albums. But the "Album Artist" field doesn't even appear as an option on my iPod screen, only in iTunes. So I tried the "Sort Artist" field, which put all the various versions of Prince together in the list but still listed them separately.
    I realize I could simplify my own life by just making the basic "Artist" field all the same, which would remove the problem. But that's not strictly accurate, is it? The NPG aren't the Revolution, and I should be able to credit them differently. But I also want, for convenience's sake, to be able to shuffle around all the various versions of Prince all together without having to create a playlist to do it.
    Assuming any of that makes sense, does anybody have any advice?
    thanks
    lvsxy808

    > No I cant thats why I am doing a course in it at the moment,
    I said, then at the end. So if mlk can't read, then you can't program. I also posted a smiley to emphasize it was more of a cynical remark of me.
    > I was not looking for someone to do my
    homework I had a question regarding a sorting
    problem.
    I'm sure you aren't, but I don't see a question in there. I can only see a bunch of lines without comments. You also didn't provide some sample in/output, but only wrote "I want to do Y, but are only able to do X...".
    I have told you this before:
    Try to look at your own post as if you had never seen it, and are not familiar with the exact assignment. Would you be able to post a meaningfull answer to your "question"? I don't think so.
    In previous posts you were given numerous links to basic tutorials (including sorting tutorials) which you apparently didn't read. That's too bad.
    > Im sure everyone wont be as ignorant
    What do you mean by that?

  • Help with sort on OLAP cubes

    Hi,
    I have a requirement to provide a D4O report where one of the cube measures is sorted desc. As I have explored on discoverer, I don't think my problem will be solved on the report side.
    Can I create a sort on the cube but this sort will not affect the cube's default sort? This a new report requirement on an existing cubes and I was thinking if I can have a sort in the cube where it will not affect any of the existing reports. Do I need to create a new measure for this? If so, how will I populate the measure?
    Example:
    Dimensions : TIME, GEOGRAPHY, CUSTOMER
    Cube Measures: Amount1, Amount2, TotalAmount
    Desired output on the report:
    Crosstab report where the rows are : Customer , Amount1, Amount2, TotalAmount
    PageItem: Time and Geography
    Sort on Total Amount desc.
    How to populate a new sort-measure such that it will be for all hierarchies of the dimensions in the cube?
    Any help will really be appreciated.
    Cheers,
    Gina

    Hi Gina,
    This can in fact be done using Discoverer, within the Query Builder. But you cannot sort the cube, this does not make sense from an OLAP perspective. You need to define a sort for each of your dimensions.
    In query builder, in the "Selected" panel on the right side of the dimensions tab there is a "Sort" button at the bottom of the selected list. Clicking on this button will launch the sort dialog. Click on the "Sort Members By:" radio button to enable the buttons on the right side of the dialog, then click on the "Add" button.
    In the "Sort By" pulldown, you will find a list showing the available sort options, such as: name, attribute values, measures included in the query, and a "more" option that will allow you to select any measure not currently included in the query. If you select the requiered measure "Total Amount", set the "Direction" to descending then the last step is to determine the QDR for the sort - that is the dimension selections for the other dimensions that make up the measure "Total Amount". For any dimensions that are on the page edge, or where the dimension is to the left of the dimension being sorted when more than one dimension is in the row edge, the QDR selector will allow a "For Each" selection which will make the sort dynamic for those dimensions. This "For Each" feature seems to be nicely hidden and not really covered in any of the documentation but is a very powerful feature and can be used in query filters as well, such as Top 10, Bottom 10 etc. In this case, using it in a sort, as the user selects a new page member, the sort will be re-applied. For other dimensions, such as the column edge you will have to pick a specific dimension member.
    You will need to repeat this process on each of your dimensions - Time, Geography and Customer (as an FYI, I would expect Customer and Geography to be the same dimension?). When you apply the sort, it will adhere to the hierarchy for your dimension, so as your drill down the members at each level will be correctly sorted using the measure "Total Amount".
    Hope this helps.
    Keith Laker
    Oracle EMEA Consulting
    OLAP Blog: http://oracleOLAP.blogspot.com/
    OLAP Wiki: http://wiki.oracle.com/page/Oracle+OLAP+Option
    DM Blog: http://oracledmt.blogspot.com/
    OWB Blog : http://blogs.oracle.com/warehousebuilder/
    OWB Wiki : http://wiki.oracle.com/page/Oracle+Warehouse+Builder
    DW on OTN : http://www.oracle.com/technology/products/bi/db/11g/index.html

  • Help with sort

    So I have a class called Token and a class called TokenArray. I have a sort function to sort an array of Tokens. I'm pretty new to java so I assumed a sort function would work the same as in C but for some reason it deletes the data instead of switching them. Here is my function:
    public void sortTokens() {
              boolean swapped = false;
              Token temp;
              do {
                   for(int i = 0; i < m_numTokens-1; i++) {
                        if(m_tokenArray.compareToIgnoreCase(m_tokenArray[i+1]) > 0) {
                             temp = m_tokenArray[i];
                             m_tokenArray[i] = m_tokenArray[i+1];
                             m_tokenArray[i+1] = temp;
                             swapped = true;
              } while (swapped);
    Can someone tell me why this isn't working?
    null
    Message was edited by:
    java_dres

    No, you have to tell us why it is not working. Then we might be able to tell you what the problem is. Do you get errors when you compile it? Or when you run it? Or does it do something that you didn't expect?
    If so, tell us about those errors, expectations, what happened, and so on.
    Personally I would not write any sorting code at all, given the existence of the Arrays.sort() method. Unless this is homework and you aren't allowed to use that.

Maybe you are looking for

  • Project does not contain a valid connection problem

    I am using JDeveloper 10.1.3.2.0 and have checked out code that was in CVS. I tried to put the code under an Application and Project, but when I do the check out, the Application Navigator shows it at the Application level. Within that Application, t

  • How to restrict update to a document in state release to the contribution g

    How to restrict update to a document in state release to the contribution group. Hi I'm working with UCM 10g and I want to know if it is possible to restrict the update over a document that is on state release for the group of users that made the che

  • Spry Radio Button widget for CS3

    Hi, I can't seem to find a definitive answer if the Spry Radio Button widget for CS3 is available or not. The help menu says that it's there, but I can't find it. I've updated my Spry and checked the web and can't find an answer. Can anyone help me o

  • How can i instal icloud on my mac book 10.6.8?

    I have a white mac book 10.6.8 and i would like i cloud on it in order to share my pics with my ipad 2 and iphone 4...what do I need to do???

  • How can i modify in TC f-43

    Dear Experts,               I  want to give an error message in TC f-43.      When i am giving the document date,posting date,reference,account number it is posting.But when i am changing only the document date with same reference number and account