Untitled
unknown
java
2 years ago
3.0 kB
8
Indexable
import java.util.Scanner;
import java.lang.String;
public class Lab_1 {
public static void main(String[] args) {
// TODO Auto-generated method stub}
System.out.println("Welcome to Mont-Halloween Skiing Contest Ranker."
+ ("\nWhenever a skiier makes it to the finish line, enter their name and skiing time."));
Scanner input = new Scanner(System.in);
String[] name = new String[20];
double[] time = new double[20];
double firstPodiumIndex = 0;
double secondPodiumIndex = 0;
double thirdPodiumIndex= 0;
double temp;
int counter;
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 1; j++) {
System.out.println("Please input the skier's name: ");
name[i] = input.next();
System.out.println("Please input the skier's time: ");
time[i] = input.nextInt();
}
if (i == 0) {
System.out.println("First podium goes to " + name[(int) firstPodiumIndex] + " who made it in " + time[(int) firstPodiumIndex]);
}
else if (i == 1) {
secondPodiumIndex = 1;
if (time[(int) firstPodiumIndex] < time[(int) secondPodiumIndex]) {
System.out.println("First podium goes to " + name[(int) firstPodiumIndex] + " who made it in " + time[(int) firstPodiumIndex]);
System.out.println("Second podium goes to " + name[(int) secondPodiumIndex] + " who made it in " + time[(int) secondPodiumIndex]);
}
else {
temp = firstPodiumIndex;
firstPodiumIndex = secondPodiumIndex;
secondPodiumIndex = temp;
System.out.println("First podium goes to " + name[(int) firstPodiumIndex] + " who made it in " + time[(int) firstPodiumIndex]);
System.out.println("Second podium goes to " + name[(int) secondPodiumIndex] + " who made it in " + time[(int) secondPodiumIndex]);
}
}
else if (i > 1){
thirdPodiumIndex = i;
if (time[(int) thirdPodiumIndex] < time[(int) secondPodiumIndex] && time[(int) thirdPodiumIndex] < time[(int) firstPodiumIndex]) {
temp = secondPodiumIndex;
secondPodiumIndex = firstPodiumIndex;
firstPodiumIndex = thirdPodiumIndex;
thirdPodiumIndex = temp;
}
else if (time[(int) thirdPodiumIndex] < time[(int) secondPodiumIndex] && time[(int) thirdPodiumIndex] > time[(int) firstPodiumIndex]) {
temp = secondPodiumIndex;
secondPodiumIndex = thirdPodiumIndex;
thirdPodiumIndex = temp;
}
System.out.println("First podium goes to " + name[(int) firstPodiumIndex] + " who made it in " + time[(int) firstPodiumIndex]);
System.out.println("Second podium goes to " + name[(int) secondPodiumIndex] + " who made it in " + time[(int) secondPodiumIndex]);
System.out.println("Third podium goes to " + name[(int) thirdPodiumIndex] + " who made it in " + time[(int) thirdPodiumIndex]);
}
System.out.println("Do you want to add another skiier? ");
String answer = input.next();
if (answer.equals("Y") || answer.equals("yes") || answer.equals("y")) {
continue;
}
else {
System.out.print("Goodbye!");
break;
}
}
input.close();
}
}
Editor is loading...