Question
Need help with a short Java problem: TestFinalAnswer.java: package finalanswer; import java.util.ArrayList; import java.util.Arrays; import java.util.Random; import stdlib.StdIn; import stdlib.StdOut; import algs13.Queue; public class TestFinalAnswer
Need help with a short Java problem:
TestFinalAnswer.java:
package finalanswer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import stdlib.StdIn;
import stdlib.StdOut;
import algs13.Queue;
public class TestFinalAnswer {
public static
for (int i = 0; i
if (a[i].compareTo(a[i+1]) > 0) return false;
}
return true;
}
public static void main(String[] args) {
StdOut.println("*** " + FinalAnswer.yourName() + " ***");
StdOut.println();
Integer[] array = new Integer[12];
Random r = new Random();
for (int i = 0; i
array[i] = r.nextInt(1000);
}
StdOut.println("Array before sorting: " + Arrays.toString(array));
FinalAnswer.minpqSort(array);
StdOut.println("Array after sorting: " + Arrays.toString(array));
StdOut.println("Array is sorted: " + isSorted(array));
StdOut.println();
Queue
queue.enqueue("first");
queue.enqueue("second");
queue.enqueue("third");
queue.enqueue("fourth");
StdOut.println("Queue before reversing: " + queue);
FinalAnswer.reverseQueue(queue);
StdOut.println("Queue after reversing: " + queue);
StdOut.println();
double[] frequencies = {110.0, 110.0*1.224, 110.0*1.224*1.224};
ArrayList
for (Chord risingChord: risingChords) {
StdOut.println("Playing: " + risingChord);
risingChord.play();
}
StdOut.println();
ArrayList
StdIn.fromFile("data/CTAdata.txt");
while (!StdIn.isEmpty()) {
int runNumber = StdIn.readInt();
String lineColor = StdIn.readString();
String nextStation = StdIn.readString();
String arrivalTime = StdIn.readString();
ctaTrains.add(new CTATrain(runNumber, lineColor, nextStation, arrivalTime));
}
StdOut.println("--- Trains before sorting ---");
for (CTATrain ctaTrain: ctaTrains) {
StdOut.println(ctaTrain);
}
StdOut.println();
ctaTrains.sort(null);
StdOut.println("--- Trains after sorting by run number ---");
for (CTATrain ctaTrain: ctaTrains) {
StdOut.println(ctaTrain);
}
StdOut.println();
ctaTrains.sort((CTATrain t1, CTATrain t2) -> (t1.getArrivalTime().compareTo(t2.getArrivalTime())));
StdOut.println("--- Trains after sorting by arrival time ---");
for (CTATrain ctaTrain: ctaTrains) {
StdOut.println(ctaTrain);
}
StdOut.println();
StdOut.println("=== " + FinalAnswer.yourName() + " ===");
}
}
Instructions 1. In Eclipse, create a package called finalanswer. 2. Copy and place into the package the file TestFinalAnswer.java provided below Copy into the package the Chord class provided below 4. n the package, create a class called Final Answer. All of the static methods you are a to write will go in this class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started