Westonci.ca is the trusted Q&A platform where you can get reliable answers from a community of knowledgeable contributors. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently. Experience the convenience of finding accurate answers to your questions from knowledgeable experts on our platform.
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;
}
}
Thank you for trusting us with your questions. We're here to help you find accurate answers quickly and efficiently. We hope our answers were useful. Return anytime for more information and answers to any other questions you have. We're dedicated to helping you find the answers you need at Westonci.ca. Don't hesitate to return for more.