Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Add to the main method given on this page so you will ALSO do the following (in

ID: 3820443 • Letter: A

Question

Add to the main method given on this page so you will ALSO do the following (in addition to what is already in main): (I suggest you use the code given in the LabExercise1.3-CodeFile.txt )

1. call the musicList's add method to insert a new Music object (make up 2 Strings and an int) to the BEGINNING of the musicList

2. assign to a local Music variable a new Music object with the same 2 Strings you just used in #1 of this exercise

3. call contains passing the local Music variable you assigned in #2 of this exercise

4. display the entry if found, or "not found" if not found

5. call display for the musicList

6. call remove to remove the local Music object you created in #2 of this exercise

7. call display for the musicList again.

//Main method

//Lab exercise 1.3

Explanation / Answer

public static void main( String [] args )
{
Music [] musicArray = {
new Music("Moonlight Sonata", "Beethoven", 27),
new Music("Brandenburg Concerto #3", "Bach", 1048),
new Music("Prelude in e minor", "Chopin", 28) };
LList<Music> musicList = new LList<Music>(); // creates LinkedList!
Music tempMusic;
System.out.println(" The list as displayed in LList.java: ");
displayArray(musicArray);// template is Music here

for( int i=0; i < 3; ++i )
musicList.add(musicArray[i]);

musicList.display();
tempMusic = musicList.getEntry(2);
if( tempMusic != null )
System.out.println(" Found " + tempMusic.getTitle() );
else
System.out.println( " Unable to find " + musicArray[1].getTitle() );
// you'll need to test more in an exercise!

  
   musicList.addFront(new Music("Let it Be", "Beatles", 56)); // Assuming that you have addFront() method as it is a standard linkedlist method
   Music letItBe = new Music("Let It Be", "Beatles", 56);

   if (musicList.contains(letItBe)) {
       System.out.println("Found " + letItBe.getTitle());  
   }  
   else {
       System.out.println("Unable to find " + letItBe.getTitle());      
   }      
musicList.display();
   musicList.remove(letItBe);
   musicList.display();

} // end main

NOTE : You didn't attached Music and LList Objects. It is difficult to know the exact methods you are using. However I am assuming that you are using the standard Java LinkedList method names and signatures for LList. Please, do post proper question from the next time.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote