Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


A bit of help with Java Programming.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Doomwinner
Advanced Cheater
Reputation: -1

Joined: 07 Oct 2009
Posts: 79
Location: USA

PostPosted: Tue Feb 19, 2013 7:40 pm    Post subject: A bit of help with Java Programming. Reply with quote

I need to set the program to list user-entered names and times in the order they finish.

I simply don't know how to set an order.

Here's what I have so far:



Code:
/*
Write a program that asks for three runners and their time (in minutes).
Set the program to order them in the order they finish.
*/
import javax.swing.JOptionPane;

public class Racers
{
   public static void main (String[] args)
   {
      String Racer1N;
      String Racer2N;
      String Racer3N;

      Racer1N = JOptionPane.showInputDialog("Enter the first racer's name");
      Racer2N = JOptionPane.showInputDialog("Enter the second racer's name");
      Racer3N = JOptionPane.showInputDialog("Enter the third racer's name");

      String Racer1;
      Double Racer1D;
      Racer1 = JOptionPane.showInputDialog("Enter the first racer's time (In minutes only).");
      Racer1D = Double.parseDouble(Racer1);

      String Racer2;
      Double Racer2D;
      Racer2 = JOptionPane.showInputDialog("Enter the second racer's time (In minutes only).");
      Racer2D = Double.parseDouble(Racer2);

      String Racer3;
      Double Racer3D;
      Racer3 = JOptionPane.showInputDialog("Enter the third racer's time (In minutes only).");
      Racer3D = Double.parseDouble(Racer3);

      JOptionPane.showMessageDialog(null,);

            }
   }

_________________
Do I frustrate you? How about now?
Back to top
View user's profile Send private message
Screitor
Cheater
Reputation: 1

Joined: 26 Nov 2012
Posts: 33
Location: Venezuela

PostPosted: Tue Feb 19, 2013 11:57 pm    Post subject: Reply with quote

There is a statement called "if"...

And... http://goo.gl/oV2JM.

_________________
Everybody lies.
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Feb 20, 2013 1:40 am    Post subject: Reply with quote

Store the data in some sort of container and sort the containers objects based on the racers times.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
deviluc
Cheater
Reputation: 1

Joined: 02 Jun 2010
Posts: 28

PostPosted: Wed Feb 20, 2013 8:24 am    Post subject: Reply with quote

I suppose the racer with the shortest time is the fastest one.
If you're just dealing with 3 racers, you can do a simple if-comparison:
Code:

String 1 = new String;
String 2 = new String;
String 3 = new String;
if (Racer1D < Racer2D) {
     if (Racer1D < Racer3D) {
          1 = Racer1N;
          if (Racer2D < Racer3D) {
               2 = Racer2N;
               3 = Racer3N;
          } else {
               2 = Racer3N;
               3 = Racer2N;
          }
     } else {
          2 = Racer1N;
          3 = Racer2N;
          1 = Racer3N;
     }

} else if (Racer1D > Racer2D) {
     if (Racer1D > Racer3D) {
          3 = Racer1N;
          if (Racer2D > Racer3D) {
               2 = Racer2N;
               3 = Racer3N;
          } else {
               2 = Racer3N;
               3 = Racer2N;
          }
    } else {
          2 = Racer1N;
          1 = Racer2N;
          3 = Racer3N;
}


With this code you'll store the fastest racer in String 1 and the slowest in String 3.

But if you want to sort more than just 3 times, you'll have to use quickSort (which is relative simple aswell)
Back to top
View user's profile Send private message
Doomwinner
Advanced Cheater
Reputation: -1

Joined: 07 Oct 2009
Posts: 79
Location: USA

PostPosted: Thu Feb 21, 2013 1:24 pm    Post subject: Reply with quote

I entered your code, but it complains of "reaching the end while parsing."

Can't figure out how to fix it.

Edit: Well, I am stuck, and I have to turn it in today. Ah well.


Code:
/*
Write a program that asks for three runners and their time (in minutes).
Set the program to order them in the order they finish.
*/
import javax.swing.JOptionPane;

public class Racers
{
   public static void main (String[] args)
   {
      String Racer1N;
      String Racer2N;
      String Racer3N;

      Racer1N = JOptionPane.showInputDialog("Enter the first racer's name");
      Racer2N = JOptionPane.showInputDialog("Enter the second racer's name");
      Racer3N = JOptionPane.showInputDialog("Enter the third racer's name");

      String Racer1;
      Double Racer1D;
      Racer1 = JOptionPane.showInputDialog("Enter the first racer's time (In minutes only).");
      Racer1D = Double.parseDouble(Racer1);

      String Racer2;
      Double Racer2D;
      Racer2 = JOptionPane.showInputDialog("Enter the second racer's time (In minutes only).");
      Racer2D = Double.parseDouble(Racer2);

      String Racer3;
      Double Racer3D;
      Racer3 = JOptionPane.showInputDialog("Enter the third racer's time (In minutes only).");
      Racer3D = Double.parseDouble(Racer3);


      String First;
      String Second;
      String Third;
      if (Racer1D < Racer2D) {
           if (Racer1D < Racer3D) {
                First = Racer1N;
                if (Racer2D < Racer3D) {
                     Second = Racer2N;
                     Third = Racer3N;
                } else {
                     Second = Racer3N;
                     Third = Racer2N;
                }
           } else {
                Second = Racer1N;
                Third = Racer2N;
                First = Racer3N;
           }

      } else if (Racer1D > Racer2D) {
           if (Racer1D > Racer3D) {
                Third = Racer1N;
                if (Racer2D > Racer3D) {
                     Second = Racer2N;
                     Third = Racer3N;
                } else {
                     Second = Racer3N;
                     Third = Racer2N;
                }
          } else {
                Second = Racer1N;
                First = Racer2N;
                Third = Racer3N;
           }
                JOptionPane.showMessageDialog(null,First + Second + Third);


            }
   }

_________________
Do I frustrate you? How about now?
Back to top
View user's profile Send private message
Chris12
Expert Cheater
Reputation: 1

Joined: 27 Apr 2012
Posts: 103

PostPosted: Thu Feb 21, 2013 11:49 pm    Post subject: Reply with quote

"reaching the end while parsing"
check if all '{' have a matching '}'
From what i can see you have 12 {
but only 11 }
Back to top
View user's profile Send private message
deviluc
Cheater
Reputation: 1

Joined: 02 Jun 2010
Posts: 28

PostPosted: Fri Feb 22, 2013 7:53 am    Post subject: Reply with quote

You forgot the last }, just put it at the end of the code and you took the inizialisation of the Strings out (that I put in), so here's your working code:
Code:
/*
Write a program that asks for three runners and their time (in minutes).
Set the program to order them in the order they finish.
*/
import javax.swing.JOptionPane;

public class Racers
{
   public static void main (String[] args)
   {
      String Racer1N;
      String Racer2N;
      String Racer3N;

      Racer1N = JOptionPane.showInputDialog("Enter the first racer's name");
      Racer2N = JOptionPane.showInputDialog("Enter the second racer's name");
      Racer3N = JOptionPane.showInputDialog("Enter the third racer's name");

      String Racer1;
      Double Racer1D;
      Racer1 = JOptionPane.showInputDialog("Enter the first racer's time (In minutes only).");
      Racer1D = Double.parseDouble(Racer1);

      String Racer2;
      Double Racer2D;
      Racer2 = JOptionPane.showInputDialog("Enter the second racer's time (In minutes only).");
      Racer2D = Double.parseDouble(Racer2);

      String Racer3;
      Double Racer3D;
      Racer3 = JOptionPane.showInputDialog("Enter the third racer's time (In minutes only).");
      Racer3D = Double.parseDouble(Racer3);


      String First = new String();
      String Second = new String();
      String Third = new String();
      if (Racer1D < Racer2D) {
           if (Racer1D < Racer3D) {
                First = Racer1N;
                if (Racer2D < Racer3D) {
                     Second = Racer2N;
                     Third = Racer3N;
                } else {
                     Second = Racer3N;
                     Third = Racer2N;
                }
           } else {
                Second = Racer1N;
                Third = Racer2N;
                First = Racer3N;
           }

      } else if (Racer1D > Racer2D) {
           if (Racer1D > Racer3D) {
                Third = Racer1N;
                if (Racer2D > Racer3D) {
                     Second = Racer2N;
                     Third = Racer3N;
                } else {
                     Second = Racer3N;
                     Third = Racer2N;
                }
          } else {
                Second = Racer1N;
                First = Racer2N;
                Third = Racer3N;
           }
         }
      JOptionPane.showMessageDialog(null,First + ", " + Second + ", " + Third);
     
   }
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites