Program help
Okay for my homework my professor said to do ask the user for 3 names and what time they finished the race and put that in from first place - second place to third place.
this is what i got so far but i need help with the outcome of the place they are in.
this is what i got so far but i need help with the outcome of the place they are in.
import javax.swing.JOptionPane; //Needed for Scanner Object
/**
* @(#)Runners.java
*
* Runners application
*
* @author
* @version 1.00 2013/3/3
*/
public class Race {
public static void main(String[] args) {
//Declare variables
int time1;
int time2;
int time3;
String input;
//Ask user for names and time
String runner1;
runner1 = JOptionPane.showInputDialog("Whats the first runners name?");
input = JOptionPane.showInputDialog("What time did he finish?");
time1 = Integer.parseInt(input);
String runner2;
runner2 = JOptionPane.showInputDialog("Whats the second runners name?");
input = JOptionPane.showInputDialog("What time did he finish?");
time2 = Integer.parseInt(input);
String runner3;
runner3 = JOptionPane.showInputDialog("Whats the third runners name?");
input = JOptionPane.showInputDialog("What time did he finish?");
time3 = Integer.parseInt(input);
//Outcome
if (time1<time2<time3)
JOptionPane.showMessageDialog(null, "The winner is " + runner1 + " Followed by " + runner2 + "," + runner3);
else if (time3<time2<time1)
JOptionPane.showMessageDialog(null, "The winner is " + runner3 + " Followed by " + runner2 + "," + runner1);
else if (time2<time1<time3)
JOptionPane.showMessageDialog(null, "The winner is " + runner2 + " Followed by " + runner1 + "," + runner3);
else if (time1<time3<time2)
JOptionPane.showMessageDialog(null, "The winner is " + runner1 + " Followed by " + runner3 + "," + runner2);
else if (time2<time3<time1)
JOptionPane.showMessageDialog(null, "The winner is " + runner2 + " Followed by " + runner3 + "," + runner1);
else if (time3<time1<time2)
JOptionPane.showMessageDialog(null, "The winner is " + runner3 + " Followed by " + runner1 + "," + runner2);
System.exit(0);
}
}
rk the way you seem to intend is mapping out all the possible combinations of the winners. That would be approximately 9 different if/elseif blocks. 3 for each set of numbers.