Question

Homework: Create a Class.... from scratch Design , implement and test a class that can be...

Homework: Create a Class.... from scratch

Design , implement and test a class that can be used to hold information about a musical note. Test it with an appropriate driver program.

A Note is described by two fields: the value of the note and the length of the note.

A programmer should be able to set and retrieve the length of the note and the value of the note.

The length of a note may be a sixteenth note, eight note, quarter note, half note, or a whole note.

The note's value is specified by indicating how far the note lies above or below the A note that orchestras use in tuning (A4 ). In counting "how far", you should include both the white and black notes on a piano.

The default constructor should set a note to the A above middle C (value = 0) and a length of a quarter note. Include methods to set a note to a specified length and value. Write methods to retrieve information about a note, including methods to:

1. tell you the letter name of the note (A, B , C);

2. tell you whether the note is natural or sharp (ie. white or black on the piano), and

3. tell you the frequency of the note in hertz. [[ HINT:  To calculate the frequency, use the formual 440 x 2^(n/12) where n is the note number. ]]

Feel free to include other useful methods ! No GUI interface or applet is required but the problem might extend itself to a cute applet in some way... You are encouraged to explore !

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

code:

public class Note
{
private int length;
private int value;
public Note(int len, int val)
{
length = len;
value = val;
}
public int getLength() {
   return length;
}
public void setLength(int length) {
   this.length = length;
}
public int getValue() {
   return value;
}
public void setValue(int value) {
   this.value = value;
}
public double getFrequency (int n)
{
return (440 * 2^(n/12));
}
public char letterName(char a1, char a2, char a3)
{
   return a1;
}

}

Hit the thumbs up if you liked the answer. :)

Add a comment
Know the answer?
Add Answer to:
Homework: Create a Class.... from scratch Design , implement and test a class that can be...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab 2 (ADTs) 1) LockADT – Show the interface and all abstract methods LockDataStructureClass – Show the following methods: default constructor, overloaded constructor, copy constructor, setX, setY, s...

    Lab 2 (ADTs) 1) LockADT – Show the interface and all abstract methods LockDataStructureClass – Show the following methods: default constructor, overloaded constructor, copy constructor, setX, setY, setZ, alter (change the lock’s combination to the numbers passed) turn (use for loops to show the dial turning), close (locks the lock), attempt (tries to unlock the lock – calls turn( ), inquire (locked or unlocked), current (returns the number the dial is pointing to), toString LockClientDemoClass – You should have a...

  • Creating a Programmer-Defined Class in Java Summary In this lab, you will create a programmer-defined class...

    Creating a Programmer-Defined Class in Java Summary In this lab, you will create a programmer-defined class and then use it in a Java program. The program should create two Rectangle objects and find their area and perimeter. Instructions Make sure the class file named Rectangle.java is open. In the Rectangle class, create two private attributes named lengthand width. Both length and width should be data type double. Write public set methods to set the values for length and width. Write...

  • Creating a Class in C++ Summary In this lab, you create a programmer-defined class and then...

    Creating a Class in C++ Summary In this lab, you create a programmer-defined class and then use it in a C++ program. The program should create two Rectangle objects and find their area and perimeter. Instructions Ensure the class file named Rectangle.cpp is open in your editor. In the Rectangle class, create two private attributes named length and width. Bothlength and width should be data type double. Write public set methods to set the values for lengthand width. Write public...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? 3. Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two...

  • create a java class with the name Brick class: For this part of the assignment, you...

    create a java class with the name Brick class: For this part of the assignment, you will create a class that allows you to specify a colored brick that is capable of drawing itself given a specified Graphics object. Note that this is a regular Java class and does not extend the JApplet class. Your class should a constructor with the following signature: Identifier: Brick(int xPosition, int yPosition, int width, int height, Color color) Parameters: xPosition – an int representing...

  • MUST BE ANSWERED BY USING C++ Question 1 Unsorted List Implement a template class UnsortedList as...

    MUST BE ANSWERED BY USING C++ Question 1 Unsorted List Implement a template class UnsortedList as defined by the following skeleton: #define MAX_ITEMS 10 typedef char ItemType; class UnsortedList {        private:             int length; ItemType values[MAX_ITEMS]; int currentPos;        public:             SortedList( ); // default constructor: lenght=0, currentPos=-1             void MakeEmpty;    // let length=0             void InsertItem(ItemType x);   // insert x into the list                 void DeleteItem(ItemType x); // delete x from the list bool IsFull( );   // test...

  • In this practical task, you need to implement a class called MyTime, which models a time...

    In this practical task, you need to implement a class called MyTime, which models a time instance. The class must contain three private instance variables: hour, with the domain of values between 0 to 23. minute, with the domain of values between 0 to 59. second, with the domain of values between 0 to 59. For the three variables you are required to perform input validation. The class must provide the following public methods to a user: MyTime() Constructor. Initializes...

  • MAKE IT DIFFERENT WAYS TO RUN IT: Design an application for each of the following problems...

    MAKE IT DIFFERENT WAYS TO RUN IT: Design an application for each of the following problems writing the pseudocode for each; include a UML diagram if appropriate. Be sure to follow the CSI 117 Style Criteria for naming conventions, class diagrams, pseudocode, keywords, and operators. 1. Wood Trim, Inc. wants a program that will allow its sales clerks to enter the length (in feet) of the trim ordered by a customer and the price of one foot of trim. Design...

  • Static methods can be called directly from the name of the class that contains the method. Static methods are usually created to do utility operations. For example: public class Test{ public static i...

    Static methods can be called directly from the name of the class that contains the method. Static methods are usually created to do utility operations. For example: public class Test{ public static int timesTwo(int value){ return value * value; } } public class TestDriver{ public static void main(String[] args){ int var = Test.timesTwo(5);   System.out.println(var); } } For your final exercise, create a class called ManyLinkedLists. It will contain a static method called createLinkedList(). That method takes an argument that is...

  • BST_Node *BST_harmonize(BST_Node *root, int semitones, double time_shift) { /* Let's play with no...

    BST_Node *BST_harmonize(BST_Node *root, int semitones, double time_shift) { /* Let's play with notes, because we can. * * This function traverses the BST, and for each existing * note, inserts a new, modified note (i.e. it will add sounds * to an already existing song, based on the notes it already has) * * The new note has the followin properties: * - The frequency is shifted by the specified number of semitones * (A semitone is the difference between...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT