Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with a Java problem please: The playChord method (copy/paste): private void playChord(double duration, double[] frequencies) { final int sliceCount = (int) (StdAudio.SAMPLE_RATE *

Need help with a Java problem please:

image text in transcribed

The playChord method (copy/paste):

 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  

image text in transcribed

When done correctly, you will have two files: a reference class in a file Chord.java and a program class PlayMusic.java.

Specifications For this assignment you will create a package called music. The Chord class In the package you will create a reference class called Chord. A chord consists of a duration in seconds (a double value) and a sequence of frequencies (an array of double values). These will be the instance variables. It has the following API: public Chord (double duration, double frequencies) This is the constructor. NB: In this constructor, copy the values in the parameters frequencies to the instance variable frequencies. Use a for loop to do this. public void play This plays the chord by calling the playChord method, a private method whose code is provided below. public String toString This returns a string version of a chord object. It should be formatted as the duration, followed by a colon, followed by the frequencies, all enclosed in square brackets. For example, if the durations is 1.5 and the frequencies are 440.0, 880.0, and 1760.0 this method would return C1. 5: 440.0 880.0 1760.01 The play Chord method: private void playChord(double duration, double frequencies) f final int slicecount (int) (StdAudio. SAMPLE RATE duration) final double CJ slices E new double slice Count+1]; for (int i 0; i slicecount i++) f double chord 0.0 for (double frequency: frequencies) chord Math sin (2 Math.PI i frequency StdAudio SAMPLE RATE) slices [i] chord/frequencies length; StedAudio. play (slices)

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

2. How will the team select a leader?

Answered: 1 week ago

Question

3. What may be the goal of the team?

Answered: 1 week ago