Westonci.ca is the Q&A platform that connects you with experts who provide accurate and detailed answers. Our platform provides a seamless experience for finding reliable answers from a network of experienced professionals. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.
Sagot :
Answer:dddd
Explanation:
//The code is all written in Java and here are the three classes in order ReportDriver, RaceReport, and Race
class ReportDriver {
public static void main(String[] args) {
boolean continueRace = true;
Scanner in = new Scanner(System.in);
ArrayList<ArrayList<Integer>> races = new ArrayList<>();
while (continueRace == true) {
System.out.println("Would you like to enter into a race? Y or N");
char answer = in.next().toLowerCase().charAt(0);
if (answer == 'y') {
Race race = new Race();
races.add(race.Race());
} else {
break;
}
}
for (int x = 0; x <= races.size()-1; x++) {
RaceReport report = new RaceReport();
report.RaceReport(races.get(x));
report.printRange();
report.printAverage();
}
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package sample;
import java.util.ArrayList;
public class RaceReport {
int range, average;
String first, second, third;
public void RaceReport(ArrayList<Integer> times) {
if (times.get(2) == times.get(1)) {
if (times.get(2) == times.get(0)) {
System.out.println(first = "Times tied for first place are " + times.get(2) + " and " + times.get(1) + " and " + times.get(0));
} else {
System.out.println(first = "Times tied for first place are " + times.get(2) + " and " + times.get(1));
System.out.println(second = "Second place time is " + times.get(0));
}
} else if (times.get(1) == times.get(0)) {
System.out.println(first = "First place time is " + times.get(2));
System.out.println(second = "Times tied for Second place are " + times.get(1) + " and " + times.get(0));
} else {
System.out.println(first = "First place time is " + times.get(2));
System.out.println(second = "Second place time is " + times.get(1));
System.out.println( third = "Third place time is " + times.get(0));
}
range = Math.abs(times.get(0) - times.get(2));
average = (times.get(2) + times.get(1) + times.get(0) / 3);
}
public void printRange() {
System.out.println("The range of the race was " + range);
}
public void printAverage() {
System.out.println("The average of the race was " + average);
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package sample;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Race {
Scanner in = new Scanner(System.in);
ArrayList<Integer> times = new ArrayList<>();
public ArrayList<Integer> Race() {
System.out.println("Input time 1:");
times.add(in.nextInt());
System.out.println("Input time 2:");
times.add(in.nextInt());
System.out.println("Input time 3:");
times.add(in.nextInt());
Collections.sort(times);
return times;
}
}
We appreciate your visit. Hopefully, the answers you found were beneficial. Don't hesitate to come back for more information. Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. Thank you for using Westonci.ca. Come back for more in-depth answers to all your queries.