Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with a Java problem: Chord.java: import java.util.Arrays; import stdlib.StdAudio; public class Chord { private double duration, frequencies[]; public Chord(double duration, double[] frequencies) {

Need help with a Java problem:

image text in transcribed

Chord.java:

import java.util.Arrays;

import stdlib.StdAudio;

public class Chord { private double duration, frequencies[];

public Chord(double duration, double[] frequencies) { this.duration = duration; this.frequencies = frequencies; } public void play() { playChord(duration, frequencies); }

private void playChord(double duration, double[] frequencies) { final int sliceCount = (int) (StdAudio.SAMPLE_RATE * duration); final double[] slices = new double[sliceCount+1]; for (int i = 0; i

@Override public String toString() { return "[" + duration + ": " + Arrays.toString(frequencies) + "]"; }

}

TestFinalAnswer.java:

package finalanswer;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Random;

import stdlib.StdIn;

import stdlib.StdOut;

public class TestFinalAnswer {

public static > boolean isSorted(Item[] a) {

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 = new 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 risingChords = FinalAnswer.createRisingChordList(0.2, frequencies, 10);

for (Chord risingChord: risingChords) {

StdOut.println("Playing: " + risingChord);

risingChord.play();

}

StdOut.println();

ArrayList ctaTrains = new 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. 3. Copy into the package the chord class provided below 4. In the package, create a class called FinalAnswer, All of the static methods you are asked to write will go in this class. Swan Song Using the chord class provided below, define in the FinalAnswer class a method with the signature public static ArrayList create RisingchordList double duration, double frequencies int count) that creates, fills, and returns an array list of Chord objects. It will fill it with count chords. Every chord will have the duration specified. The first chord will have the frequencies specified in the parameters. The next chord is formed by multiplying each entry in the frequencies array by the value 1.224. So you'll have a loop that: 1. creates a chord from the duration and frequencies; 2. adds it to the array list 3. updates every value in the frequencies array by multiplying it by 1.224; Follow that with a loop that plays the chords using the play instance method in the Chord class. Testing your code The TestFinalAnswer program provided below will test every one of your methods and classes. It produces (a lot) of output and it will be obvious whether your code works

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions