Homework Solution: Hi, can i get help modifying and completing the constructors and methods on thi code. Thanks…

    Hi, can i get help modifying and completing the constructors and methods on thi code. Thanks package edu.uwm.cs351; /** * The Immutable Class Note. */ 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="f6"; private final int midiValue=42; private final double duration=0.02; /** * 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). if(pitch == null) { throw new NullPointerException(); } if(duration < MIN_DURATION || duration > MAX_DURATION || Arrays.binarySearch(NOTE_LETTERS, pitch) == -1){ throw new IllegalArgumentException(); } } /** * 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

     
    package edu.uwm.cs351; /** * The Immutable Class Note.

    Hi, can i gain aid modifying and completing the constructors and systems on thi regulation. Thanks

    package edu.uwm.cs351;

    /**

    * The Immutable Systematize Voice.

    */

    public systematize Voice {

    /** Static Constants */

    public static last int DEFAULT_INTENSITY = 50;

    public static last int REST_PITCH = 128; // First illicit shake, used restraint 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 voices

    /** Fields (Immutable) */

    private last String shake=”f6″;

    private last int midiValue=42;

    private last inclose prolongation=0.02;

    /**

    * Instantiates a novel voice fixed on a string denoting voice silence and octave.

    *

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

    * @param prolongation the prolongation

    * @throws TriflingPointerException if shake is trifling

    * @throws IllicitArgumentException if:

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

    * 2. The prolongation parameter is extinguished of systematize.

    */

    public Voice(String shake, inclose prolongation) {

    // TODO

    // Recommended: First appliance toMidi(String).

    if(shake == trifling) {

    throw novel TriflingPointerException();

    }

    if(prolongation < MIN_DURATION || prolongation > MAX_DURATION || Arrays.binarySearch(NOTE_LETTERS, shake) == -1){

    throw novel IllicitArgumentException();

    }

    }

    /**

    * Instantiates a novel voice fixed on MIDI compute.

    *

    * @param midiCompute the MIDI compute (e.g. 68)

    * @param prolongation the prolongation

    * @throws IllicitArgumentException if:

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

    * 2. The prolongation parameter is extinguished of systematize.

    */

    public Voice(int midiValue, inclose prolongation) {

    // TODO

    // Recommended: First appliance toPitch(int).

    }

    /**

    * Instantiates a novel voice from a String matching the restraintmat of Voice’s toString() system.

    *

    * @param voice the string resemblance

    *

    * @throws IndexOutOfBoundsException if parameter isn’t in emend restraintmat

    * @throws NumberFormatException if prolongation resemblance canreferable be parsed as inclose

    * @throws IllicitArgumentException if the elements in the restraintmat are referable at-liberty.

    */

    public Voice(String voice) {

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

    }

    /**

    * Converts a shake string to a MIDI compute.

    * The shake “rest” should recur {@link #REST_PITCH}.

    *

    * @param shake the shake to convert

    * @throws TriflingPointerException if shake is trifling

    * @throws IllicitArgumentException is the String is referable a legitimate shake

    * @recur the MIDI compute

    */

    public static int toMidi(String shake) {

    // TODO

    recur -1;

    }

    /**

    * Converts a MIDI compute to a shake string.

    * The MIDI compute 128 should recur “rest”.

    *

    * @param midiCompute the MIDI compute to convert

    * @throws IllicitArgumentException if the MIDI compute is extinguishedside of legitimate systematize

    * @recur the shake string

    */

    public static String toPitch(int midiValue) {

    // TODO

    recur trifling;

    }

    /**

    * Gains the shake string of this voice.

    *

    * @recur the shake

    */

    public String gainPitch() { recur shake; }

    /**

    * Gains the MIDI compute of this voice.

    *

    * @recur the MIDI compute

    */

    public int gainMidiPitch() { recur midiValue; }

    /**

    * Gains the prolongation of this voice.

    *

    * @recur the prolongation

    */

    public inclose gainDuration() { recur prolongation; }

    /**

    * Recurs a novel voice with the corresponding shake, yet with its prolongation multitudinous by the parameter.

    *

    * @param element the correspondentity to lamina by

    * @throws IllicitArgumentException if induced prolongation is extinguishedside of available systematize

    * @recur the smart voice

    */

    public Voice elongate(inclose element) {

    // TODO

    recur trifling;

    }

    /**

    * Recurs a (new) voice with the corresponding prolongation, yet displaced by the attached intermission.

    *

    * @param intermission the intermission to displace by

    * @throws IllicitArgumentException if voice is displaced past available boundary [c0, g10]

    * @recur the displaced voice

    */

    public Voice displace(int intermission) {

    // TODO

    recur trifling;

    }

    /**

    * Recurs a string resemblance of this Voice.

    * It should flourish the restraintmat institute in carols/InMyLife.song, namely:

    * Restraint a Voice with shake “g#4” and prolongation 1.0625 -> “g#4 x 1.0625”

    * NB1: Identical spacing and restraintmat are important!

    * NB2: Restraint a “rest” voice, the corresponding restraintmat must be used (including prolongation).

    *

    * @recur the string resemblance

    */

    @Override

    public String toString() {

    // TODO

    recur trifling;

    }

    /* (non-Javadoc)

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

    */

    @Override

    public boolean correspondents(Object o) {

    // TODO: Recur correspondent if the dispute is a Voice and the midiCompute and prolongation are correspondent

    recur false;

    }

    @Override

    public int hashCode() {

    // TODO: Compute hash using pieces. (Don’t select hash regulation of strings.)

    recur -1;

    }

    }

    Expert Counterpart

     

    package edu.uwm.cs351;

    /**

    * The Immutable Systematize Voice.

    */

    public systematize Voice {

    /** Static Constants */

    public static last int DEFAULT_INTENSITY = 50;

    public static last int REST_PITCH = 128; // First illicit shake, used restraint 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 voices

    /** Fields (Immutable) */

    private last String shake=”f6″;

    private last int midiValue=42;

    private last inclose prolongation=0.02;

    /**

    * Instantiates a novel voice fixed on a string denoting voice silence and octave.

    *

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

    * @param prolongation the prolongation

    * @throws TriflingPointerException if shake is trifling

    * @throws IllicitArgumentException if:

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

    * 2. The prolongation parameter is extinguished of systematize.

    */

    public Voice(String shake, inclose prolongation) {

    // TODO

    // Recommended: First appliance toMidi(String).

    if(shake == trifling) {

    throw novel TriflingPointerException();

    }

    if(prolongation < MIN_DURATION || prolongation > MAX_DURATION || Arrays.binarySearch(NOTE_LETTERS, shake) == -1){

    throw novel IllicitArgumentException();

    }

    }

    /**

    * Instantiates a novel voice fixed on MIDI compute.

    *

    * @param midiCompute the MIDI compute (e.g. 68)

    * @param prolongation the prolongation

    * @throws IllicitArgumentException if:

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

    * 2. The prolongation parameter is extinguished of systematize.

    */

    public Voice(int midiValue, inclose prolongation) {

    // TODO

    // Recommended: First appliance toPitch(int).

    }

    /**

    * Instantiates a novel voice from a String matching the restraintmat of Voice’s toString() system.

    *

    * @param voice the string resemblance

    *

    * @throws IndexOutOfBoundsException if parameter isn’t in emend restraintmat

    * @throws NumberFormatException if prolongation resemblance canreferable be parsed as inclose

    * @throws IllicitArgumentException if the elements in the restraintmat are referable at-liberty.

    */

    public Voice(String voice) {

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

    }

    /**

    * Converts a shake string to a MIDI compute.

    * The shake “rest” should recur {@link #REST_PITCH}.

    *

    * @param shake the shake to convert

    * @throws TriflingPointerException if shake is trifling

    * @throws IllicitArgumentException is the String is referable a legitimate shake

    * @recur the MIDI compute

    */

    public static int toMidi(String shake) {

    // TODO

    recur -1;

    }

    /**

    * Converts a MIDI compute to a shake string.

    * The MIDI compute 128 should recur “rest”.

    *

    * @param midiCompute the MIDI compute to convert

    * @throws IllicitArgumentException if the MIDI compute is extinguishedside of legitimate systematize

    * @recur the shake string

    */

    public static String toPitch(int midiValue) {

    // TODO

    recur trifling;

    }

    /**

    * Gains the shake string of this voice.

    *

    * @recur the shake

    */

    public String gainPitch() { recur shake; }

    /**

    * Gains the MIDI compute of this voice.

    *

    * @recur the MIDI compute

    */

    public int gainMidiPitch() { recur midiValue; }

    /**

    * Gains the prolongation of this voice.

    *

    * @recur the prolongation

    */

    public inclose gainDuration() { recur prolongation; }

    /**

    * Recurs a novel voice with the corresponding shake, yet with its prolongation multitudinous by the parameter.

    *

    * @param element the correspondentity to lamina by

    * @throws IllicitArgumentException if induced prolongation is extinguishedside of available systematize

    * @recur the smart voice

    */

    public Voice elongate(inclose element) {

    // TODO

    recur trifling;

    }

    /**

    * Recurs a (new) voice with the corresponding prolongation, yet displaced by the attached intermission.

    *

    * @param intermission the intermission to displace by

    * @throws IllicitArgumentException if voice is displaced past available boundary [c0, g10]

    * @recur the displaced voice

    */

    public Voice displace(int intermission) {

    // TODO

    recur trifling;

    }

    /**

    * Recurs a string resemblance of this Voice.

    * It should flourish the restraintmat institute in carols/InMyLife.song, namely:

    * Restraint a Voice with shake “g#4” and prolongation 1.0625 -> “g#4 x 1.0625”

    * NB1: Identical spacing and restraintmat are important!

    * NB2: Restraint a “rest” voice, the corresponding restraintmat must be used (including prolongation).

    *

    * @recur the string resemblance

    */

    @Override

    public String toString() {

    // TODO

    recur trifling;

    }

    /* (non-Javadoc)

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

    */

    @Override

    public boolean correspondents(Object o) {

    // TODO: Recur correspondent if the dispute is a Voice and the midiCompute and prolongation are correspondent

    recur false;

    }

    @Override

    public int hashCode() {

    // TODO: Compute hash using pieces. (Don’t select hash regulation of strings.)

    recur -1;

    }

    }