posted 3 years ago

Hey guys I am new to java and would like to know how to start this off:

this is what i have so far

~~

public class Notes

{

private double middleC;

private double[] frequency = new double[13];

private String[] notes = new String[]{"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "C'"};

~~

All help is appreciated, thanks!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Homework~~~~~~~~~~~~~~~~~~~~~~~~~~

The programme will calculate the frequencies of a musical scale based on middle C.

Write two classes named: Notes and UseNotes.

The IO.java static class can be used for keyboard and display.

Arrays will be used to store doubles and Strings.

All files will be in a package called notes.

Also from command line in directory src compile and run

a private double variable for middle C

a private array of doubles for 13 note frequencies or semitones

a private array of Strings for the note names C C# D D# E F F# G G# A A# B C'

a default constructor to set middle C to 260 Hz.

a constructor taking one double value to initialize middle C.

Setters for middle C and getters for the arrays

a calculate method to find the 13 semitones. When is the appropriate time for this method to be called?

a display method to show note names and frequency in 2 columns

a linear search function to retrieve a particular note frequency by the name which can be entered in upper or lower case. Prompt if not found, go again.

Calculation note: Each semitone is 2 to the power of 1/12 higher than the previous one.

So if C = 256, C# = 256 * 2 1/12

Use the Math class power function for this and find all 13 notes.

C' should be twice the frequency of C. This is called an Octave due to the 8 white keys in the musical scale. An Octave is a frequency ratio of 2 to one.

. Limit the input for middle C from 250 Hz to 270 Hz

1. This class will have the main function. It will create a Notes object and print out the initial values of the 13 notes.

2. It will ask for a new value of middle C and print a new scale.

3. It will ask for the name of a particular note and then print it and its frequency. It will prompt for a new name if a bad note name is entered.

4. It will offer a choice to continue or exit.

this is what i have so far

~~

public class Notes

{

private double middleC;

private double[] frequency = new double[13];

private String[] notes = new String[]{"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "C'"};

~~

All help is appreciated, thanks!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Homework~~~~~~~~~~~~~~~~~~~~~~~~~~

The programme will calculate the frequencies of a musical scale based on middle C.

**Procedure:**Write two classes named: Notes and UseNotes.

The IO.java static class can be used for keyboard and display.

Arrays will be used to store doubles and Strings.

All files will be in a package called notes.

Also from command line in directory src compile and run

**Notes:**a private double variable for middle C

a private array of doubles for 13 note frequencies or semitones

a private array of Strings for the note names C C# D D# E F F# G G# A A# B C'

a default constructor to set middle C to 260 Hz.

a constructor taking one double value to initialize middle C.

Setters for middle C and getters for the arrays

a calculate method to find the 13 semitones. When is the appropriate time for this method to be called?

a display method to show note names and frequency in 2 columns

a linear search function to retrieve a particular note frequency by the name which can be entered in upper or lower case. Prompt if not found, go again.

Calculation note: Each semitone is 2 to the power of 1/12 higher than the previous one.

So if C = 256, C# = 256 * 2 1/12

Use the Math class power function for this and find all 13 notes.

C' should be twice the frequency of C. This is called an Octave due to the 8 white keys in the musical scale. An Octave is a frequency ratio of 2 to one.

. Limit the input for middle C from 250 Hz to 270 Hz

**UseNotes:**1. This class will have the main function. It will create a Notes object and print out the initial values of the 13 notes.

2. It will ask for a new value of middle C and print a new scale.

3. It will ask for the name of a particular note and then print it and its frequency. It will prompt for a new name if a bad note name is entered.

4. It will offer a choice to continue or exit.

niraj pateI

Greenhorn

Posts: 5

posted 3 years ago

thanks, updated

******

import java.lang.Math;

import java.text;

public class Notes

{

private double middleC = 260;

private double[] frequency = new double[13];

private String[] notes = new String[]{"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "C'"};

public Notes(int middleC) //constructor

{

this.middleC = middleC;

}

public void setmiddleC(double newmiddleC)

{

middleC = newmiddleC;

}

public double[] getfrequency()

{

return frequency;

}

public String[] getnotes()

{

return notes;

}

public void Calculate()

{

frequency[0] = middleC;

frequency[1] = middleC * Math.pow(2,0.0833);

frequency[2] = frequency[1] * Math.pow(2,0.0833);

frequency[3] = frequency[2] * Math.pow(2,0.0833);

frequency[4] = frequency[3] * Math.pow(2,0.0833);

frequency[5] = frequency[4] * Math.pow(2,0.0833);

frequency[6] = frequency[5] * Math.pow(2,0.0833);

frequency[7] = frequency[6] * Math.pow(2,0.0833);

frequency[8] = frequency[7] * Math.pow(2,0.0833);

frequency[9] = frequency[8] * Math.pow(2,0.0833);

frequency[10] = frequency[9] * Math.pow(2,0.0833);

frequency[11] = frequency[10] * Math.pow(2,0.0833);

frequency[12] = frequency[11] * Math.pow(2,0.0833);

frequency[13] = frequency[12] * Math.pow(2,0.0833);

}

public void Display()

{

System.out.println("Notes\tFrequences\n");

for(int i =0; i<13; i++)

{

System.out.println(" "+notes[i] + " "+"\t" + frequency[i] + "Hz");

}

}

public static void main(String[] args)

{

}

******

Campbell Ritchie wrote:Welcome to the Ranch

Middle C should be 261.626, if A is 440, its conventional value.

thanks, updated

******

import java.lang.Math;

import java.text;

public class Notes

{

private double middleC = 260;

private double[] frequency = new double[13];

private String[] notes = new String[]{"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "C'"};

public Notes(int middleC) //constructor

{

this.middleC = middleC;

}

public void setmiddleC(double newmiddleC)

{

middleC = newmiddleC;

}

public double[] getfrequency()

{

return frequency;

}

public String[] getnotes()

{

return notes;

}

public void Calculate()

{

frequency[0] = middleC;

frequency[1] = middleC * Math.pow(2,0.0833);

frequency[2] = frequency[1] * Math.pow(2,0.0833);

frequency[3] = frequency[2] * Math.pow(2,0.0833);

frequency[4] = frequency[3] * Math.pow(2,0.0833);

frequency[5] = frequency[4] * Math.pow(2,0.0833);

frequency[6] = frequency[5] * Math.pow(2,0.0833);

frequency[7] = frequency[6] * Math.pow(2,0.0833);

frequency[8] = frequency[7] * Math.pow(2,0.0833);

frequency[9] = frequency[8] * Math.pow(2,0.0833);

frequency[10] = frequency[9] * Math.pow(2,0.0833);

frequency[11] = frequency[10] * Math.pow(2,0.0833);

frequency[12] = frequency[11] * Math.pow(2,0.0833);

frequency[13] = frequency[12] * Math.pow(2,0.0833);

}

public void Display()

{

System.out.println("Notes\tFrequences\n");

for(int i =0; i<13; i++)

{

System.out.println(" "+notes[i] + " "+"\t" + frequency[i] + "Hz");

}

}

public static void main(String[] args)

{

}

******

Campbell Ritchie

Marshal

Posts: 58438

178

Campbell Ritchie

Marshal

Posts: 58438

178

posted 3 years ago

I would have added code tags which make your code look better, but you haven't indented it.

posted 3 years ago

Doing it this way will give you rounding errors. Rather than calculating each note from the previous one, you might be better calculating each one directly.

This assignment is not just a programming assignment - it's a test of whether or not you understand exponents and logarithms.

This assignment is not just a programming assignment - it's a test of whether or not you understand exponents and logarithms.