Runner.java
public class Runner
{
String runner; \\remember the tradition of variables always being lowercase
private double time;
public Runner(String r, double t)
{
runner = r;
time = t;
}
public String getRunner()
{
return runner;
}
public double getTime()
{
return time;
}
}
RunnerDemo.java
import java.util.Scanner;
public class RunnerDemo
{
public static void main(String[] args)
{
String runner1, runner2, runner3;
double time1;
double time2;
double time3;
int status = -1;
Scanner keyboard = new Scanner(System.in);
System.out.print("What is the name of the first runner? ");
runner1 = keyboard.nextLine();
System.out.print("What is the name of the second runner? ");
runner2 = keyboard.nextLine();
System.out.print("What is the name of the third runner? ");
runner3 = keyboard.nextLine();
System.out.print("What was the time for " + Runner1 + "? ");
time1 = keyboard.nextDouble();
System.out.print("What was the time for " + Runner2 + "? ");
time2 = keyboard.nextDouble();
System.out.print("What was the time for " + Runner3 + "? ");
time3 = keyboard.nextDouble();
Runner run1 = new Runner(runner1, time1);
Runner run2 = new Runner(runner2, time2);
Runner run3 = new Runner(runner3, time3);
if (run1.getTime() > run2.getTime() && run1.getTime() > run3.getTime())
{
System.out.println(run1.getRunner());
if (run2.getTime() > run3.getTime())
System.out.println(run2.getRunner());
else
System.out.println(run3.getRunner());
}
if (run2.getTime() > run1.getTime() && run2.getTime() > run3.getTime())
{
System.out.println(run2.getRunner());
if (run1.getTime() > run3.getTime())
System.out.println(run1.getRunner());
else
System.out.println(run3.getRunner());
}
if (run3.getTime() > run1.getTime() && run3.getTime() > run2.getTime())
{
System.out.println(run3.getRunner());
if (run1.getTime() > run2.getTime())
System.out.println(run1.getRunner());
else
System.out.println(run2.getRunner());
}
}
}
This, or some variant, should work. I will note that there are a few easier ways using ArrayLists, but I don't know whether or not you have gotten that far into learning java yet, so I used the brute force method with the if statements. I hoped this helped! ^^