Homework Solution: Can i get some help modifying this java code. thanks…

    Can i get some help modifying this java code. thanks public class Note { /** Static Constants */ public static final int DEFAULT_INTENSITY = 50; public static final int REST_PITCH = 128; // First illegal pitch, used for rests. private static final int PITCHES_PER_OCTAVE = 12; private static final String[] NOTE_LETTERS = {"c","c#","d","d#","e","f","f#","g","g#","a","a#","b"}; private static final double MIN_DURATION = 1.0/64, // One sixty-fourth MAX_DURATION = 8.0; // Eight whole notes /** Fields (Immutable) */ private final String pitch; private final int midiValue; private final double duration; /** * Instantiates a new note based on a string denoting note letter and octave. * * @param pitch the pitch (e.g. "f6") * @param duration the duration * @throws NullPointerException if pitch is null * @throws IllegalArgumentException if: * 1. The pitch parameter is malformed or out of range. * 2. The duration parameter is out of range. */ public Note(String pitch, double duration) { // TODO // Recommended: First implement toMidi(String). } /** * Instantiates a new note based on MIDI value. * * @param midiValue the MIDI value (e.g. 68) * @param duration the duration * @throws IllegalArgumentException if: * 1. The MIDI pitch parameter is out of range. * 2. The duration parameter is out of range. */ public Note(int midiValue, double duration) { // TODO // Recommended: First implement toPitch(int). } /** * Instantiates a new note from a String matching the format of Note's toString() method. * * @param note the string representation * * @throws IndexOutOfBoundsException if parameter isn't in correct format * @throws NumberFormatException if duration representation cannot be parsed as double * @throws IllegalArgumentException if the elements in the format are not permitted. */ public Note(String note) { this(note.split(" x ")[0], Double.parseDouble(note.split(" x ")[1])); } /** * Converts a pitch string to a MIDI value. * The pitch "rest" should return {@link #REST_PITCH}. * * @param pitch the pitch to convert * @throws NullPointerException if pitch is null * @throws IllegalArgumentException is the String is not a legal pitch * @return the MIDI value */ public static int toMidi(String pitch) { // TODO return -1; } /** * Converts a MIDI value to a pitch string. * The MIDI value 128 should return "rest". * * @param midiValue the MIDI value to convert * @throws IllegalArgumentException if the MIDI value is outside of legal range * @return the pitch string */ public static String toPitch(int midiValue) { // TODO return null; } /** * Gets the pitch string of this note. * * @return the pitch */ public String getPitch() { return pitch; } /** * Gets the MIDI value of this note. * * @return the MIDI value */ public int getMidiPitch() { return midiValue; } /** * Gets the duration of this note. * * @return the duration */ public double getDuration() { return duration; } /** * Returns a new note with the same pitch, but with its duration multiplied by the parameter. * * @param factor the amount to scale by * @throws IllegalArgumentException if resultant duration is outside of valid range * @return the stretched note */ public Note stretch(double factor) { // TODO return null; } /** * Returns a (new) note with the same duration, but transposed by the given interval. * * @param interval the interval to transpose by * @throws IllegalArgumentException if note is transposed beyond valid bounds [c0, g10] * @return the transposed note */ public Note transpose(int interval) { // TODO return null; } /** * Returns a string representation of this Note. * It should follow the format found in songs/InMyLife.song, namely: * For a Note with pitch "g#4" and duration 1.0625 -> "g#4 x 1.0625" * NB1: Identical spacing and format are important! * NB2: For a "rest" note, the same format must be used (including duration). * * @return the string representation */ @Override public String toString() { // TODO return null; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object o) { // TODO: Return equal if the argument is a Note and the midiValue and duration are equal return false; } @Override public int hashCode() { // TODO: Compute hash using pieces. (Don't take hash code of strings.) return -1; } }

    Expert Answer

     
    1. main() method missing in Note Class. public static void main(String[] args)

    Can i gain some aid modifying this java principle. thanks

    public collocate Silence {

    /** Static Constants */

    public static last int DEFAULT_INTENSITY = 50;

    public static last int REST_PITCH = 128; // First unfair cast, used ce rests.

    private static last int PITCHES_PER_OCTAVE = 12;

    private static last String[] NOTE_LETTERS = {“c”,”c#”,”d”,”d#”,”e”,”f”,”f#”,”g”,”g#”,”a”,”a#”,”b”};

    private static last inclose MIN_DURATION = 1.0/64, // One sixty-fourth

    MAX_DURATION = 8.0; // Eight entire silences

    /** Fields (Immutable) */

    private last String cast;

    private last int midiValue;

    private last inclose term;

    /**

    * Instantiates a fantastic silence domiciled on a string denoting silence epistle and octave.

    *

    * @param cast the cast (e.g. “f6″)

    * @param term the term

    * @throws NullPointerException if cast is null

    * @throws UnfairArgumentException if:

    * 1. The cast parameter is malformed or extinguished of systematize.

    * 2. The term parameter is extinguished of systematize.

    */

    public Silence(String cast, inclose term) {

    // TODO

    // Recommended: First utensil toMidi(String).

    }

    /**

    * Instantiates a fantastic silence domiciled on MIDI estimate.

    *

    * @param midiEstimate the MIDI estimate (e.g. 68)

    * @param term the term

    * @throws UnfairArgumentException if:

    * 1. The MIDI cast parameter is extinguished of systematize.

    * 2. The term parameter is extinguished of systematize.

    */

    public Silence(int midiValue, inclose term) {

    // TODO

    // Recommended: First utensil toPitch(int).

    }

    /**

    * Instantiates a fantastic silence from a String matching the cemat of Silence’s toString() manner.

    *

    * @param silence the string justice

    *

    * @throws IndexOutOfBoundsException if parameter isn’t in amend cemat

    * @throws NumberFormatException if term justice canreferable be parsed as inclose

    * @throws UnfairArgumentException if the elements in the cemat are referable open.

    */

    public Silence(String silence) {

    this(note.split(” x “)[0], Inclose.parseDouble(note.split(” x “)[1]));

    }

    /**

    * Converts a cast string to a MIDI estimate.

    * The cast “rest” should restore {@link #REST_PITCH}.

    *

    * @param cast the cast to convert

    * @throws NullPointerException if cast is null

    * @throws UnfairArgumentException is the String is referable a allowable cast

    * @restore the MIDI estimate

    */

    public static int toMidi(String cast) {

    // TODO

    restore -1;

    }

    /**

    * Converts a MIDI estimate to a cast string.

    * The MIDI estimate 128 should restore “rest”.

    *

    * @param midiEstimate the MIDI estimate to convert

    * @throws UnfairArgumentException if the MIDI estimate is extinguishedside of allowable systematize

    * @restore the cast string

    */

    public static String toPitch(int midiValue) {

    // TODO

    restore null;

    }

    /**

    * Gains the cast string of this silence.

    *

    * @restore the cast

    */

    public String gainPitch() { restore cast; }

    /**

    * Gains the MIDI estimate of this silence.

    *

    * @restore the MIDI estimate

    */

    public int gainMidiPitch() { restore midiValue; }

    /**

    * Gains the term of this silence.

    *

    * @restore the term

    */

    public inclose gainDuration() { restore term; }

    /**

    * Restores a fantastic silence with the corresponding cast, referablewithstanding with its term sundry by the parameter.

    *

    * @param element the healthy to lamina by

    * @throws UnfairArgumentException if subordinate term is extinguishedside of sound systematize

    * @restore the firm silence

    */

    public Silence tighten(inclose element) {

    // TODO

    restore null;

    }

    /**

    * Restores a (new) silence with the corresponding term, referablewithstanding interchanged by the abandoned interspace.

    *

    * @param interspace the interspace to interchange by

    * @throws UnfairArgumentException if silence is interchanged over sound environs [c0, g10]

    * @restore the interchanged silence

    */

    public Silence interchange(int interspace) {

    // TODO

    restore null;

    }

    /**

    * Restores a string justice of this Silence.

    * It should thrive the cemat establish in carols/InMyLife.song, namely:

    * Ce a Silence with cast “g#4” and term 1.0625 -> “g#4 x 1.0625”

    * NB1: Identical spacing and cemat are important!

    * NB2: Ce a “rest” silence, the corresponding cemat must be used (including term).

    *

    * @restore the string justice

    */

    @Override

    public String toString() {

    // TODO

    restore null;

    }

    /* (non-Javadoc)

    * @see java.lang.Object#equals(java.lang.Object)

    */

    @Override

    public boolean similars(Object o) {

    // TODO: Restore similar if the topic is a Silence and the midiEstimate and term are similar

    restore false;

    }

    @Override

    public int hashCode() {

    // TODO: Compute hash using pieces. (Don’t conduct hash principle of strings.)

    restore -1;

    }

    }

    Expert Response

     

    1. deep() manner missing in Silence Collocate.

    public static nugatory deep(String[] args)
    {
    }

    2. Initializations are missing

    private last String cast = “F#”;
    private last int midiEstimate = 42;
    private last inclose term = 0.02;

    public collocate Silence {
    public static nugatory deep(String[] args)
    {
    // This is deep manner.
    }
    /** Static Constants */
    public static last int DEFAULT_INTENSITY = 50;
    public static last int REST_PITCH = 128; // First unfair cast, used ce rests.
    private static last int PITCHES_PER_OCTAVE = 12;
    private static last String[] NOTE_LETTERS = {“c”,”c#”,”d”,”d#”,”e”,”f”,”f#”,”g”,”g#”,”a”,”a#”,”b”};
    private static last inclose MIN_DURATION = 1.0/64, // One sixty-fourth
    MAX_DURATION = 8.0; // Eight entire silences
    /** Fields (Immutable) */
    private last String cast = “F#”;
    private last int midiEstimate = 42;
    private last inclose term = 0.02;

    /**
    * Instantiates a fantastic silence domiciled on a string denoting silence epistle and octave.
    *
    * @param cast the cast (e.g. “f6″)
    * @param term the term
    * @throws NullPointerException if cast is null
    * @throws UnfairArgumentException if:
    * 1. The cast parameter is malformed or extinguished of systematize.
    * 2. The term parameter is extinguished of systematize.
    */
    public Silence(String cast, inclose term) {
    // TODO
    // Recommended: First utensil toMidi(String).
    }
    /**
    * Instantiates a fantastic silence domiciled on MIDI estimate.
    *
    * @param midiEstimate the MIDI estimate (e.g. 68)
    * @param term the term
    * @throws UnfairArgumentException if:
    * 1. The MIDI cast parameter is extinguished of systematize.
    * 2. The term parameter is extinguished of systematize.
    */
    public Silence(int midiValue, inclose term) {
    // TODO
    // Recommended: First utensil toPitch(int).
    }
    /**
    * Instantiates a fantastic silence from a String matching the cemat of Silence’s toString() manner.
    *
    * @param silence the string justice
    *
    * @throws IndexOutOfBoundsException if parameter isn’t in amend cemat
    * @throws NumberFormatException if term justice canreferable be parsed as inclose
    * @throws UnfairArgumentException if the elements in the cemat are referable open.
    */
    public Silence(String silence) {
    this(note.split(” x “)[0], Inclose.parseDouble(note.split(” x “)[1]));
    }
    /**
    * Converts a cast string to a MIDI estimate.
    * The cast “rest” should restore {@link #REST_PITCH}.
    *
    * @param cast the cast to convert
    * @throws NullPointerException if cast is null
    * @throws UnfairArgumentException is the String is referable a allowable cast
    * @restore the MIDI estimate
    */
    public static int toMidi(String cast) {
    // TODO
    restore -1;
    }
    /**
    * Converts a MIDI estimate to a cast string.
    * The MIDI estimate 128 should restore “rest”.
    *
    * @param midiEstimate the MIDI estimate to convert
    * @throws UnfairArgumentException if the MIDI estimate is extinguishedside of allowable systematize
    * @restore the cast string
    */
    public static String toPitch(int midiValue) {
    // TODO
    restore null;
    }
    /**
    * Gains the cast string of this silence.
    *
    * @restore the cast
    */
    public String gainPitch() { restore cast; }
    /**
    * Gains the MIDI estimate of this silence.
    *
    * @restore the MIDI estimate
    */
    public int gainMidiPitch() { restore midiValue; }
    /**
    * Gains the term of this silence.
    *
    * @restore the term
    */
    public inclose gainDuration() { restore term; }
    /**
    * Restores a fantastic silence with the corresponding cast, referablewithstanding with its term sundry by the parameter.
    *
    * @param element the healthy to lamina by
    * @throws UnfairArgumentException if subordinate term is extinguishedside of sound systematize
    * @restore the firm silence
    */
    public Silence tighten(inclose element) {
    // TODO
    restore null;
    }
    /**
    * Restores a (new) silence with the corresponding term, referablewithstanding interchanged by the abandoned interspace.
    *
    * @param interspace the interspace to interchange by
    * @throws UnfairArgumentException if silence is interchanged over sound environs [c0, g10]
    * @restore the interchanged silence
    */
    public Silence interchange(int interspace) {
    // TODO
    restore null;
    }
    /**
    * Restores a string justice of this Silence.
    * It should thrive the cemat establish in carols/InMyLife.song, namely:
    * Ce a Silence with cast “g#4” and term 1.0625 -> “g#4 x 1.0625”
    * NB1: Identical spacing and cemat are important!
    * NB2: Ce a “rest” silence, the corresponding cemat must be used (including term).
    *
    * @restore the string justice
    */
    @Override
    public String toString() {
    // TODO
    restore null;
    }
    /* (non-Javadoc)
    * @see java.lang.Object#equals(java.lang.Object)
    */
    @Override
    public boolean similars(Object o) {
    // TODO: Restore similar if the topic is a Silence and the midiEstimate and term are similar
    restore false;
    }
    @Override
    public int hashCode() {
    // TODO: Compute hash using pieces. (Don’t conduct hash principle of strings.)
    restore -1;
    }
    }