Question

In: Computer Science

Create a linked list of Poem objects using the Poem.java file provided. You may create Poem...

Create a linked list of Poem objects using the Poem.java file provided. You may create Poem objects by hard coding (minimum 4), reading from a file, or getting user input.

Print the list using ListIterator.

Here is Poem.Java:

public class Poem
{

   private String title;
   private String poet;

   /**
   * No arg constructor
   */
   public Poem()
   {
       title = "not set";
       poet = "not set";
   }

   /**
   * @param title
   * @param poet
   */
   public Poem(String title, String poet)
   {
       super();
       setTitle(title);
       setPoet(poet);
   }

   /**
   * @return the title
   */
   public String getTitle()
   {
       return title;
   }

   /**
   * @param title the title to set
   */
   public void setTitle(String title)
   {
       if (title.length() > 0)
       {
           this.title = title;
       } else
       {
           this.title = "not set";
       }
   }

   /**
   * @return the poet
   */
   public String getPoet()
   {
       return poet;
   }

   /**
   * @param poet the poet to set
   */
   public void setPoet(String poet)
   {
       if (poet.length() > 0)
       {
           this.poet = poet;

       } else
       {
           this.poet = "not set";
       }
   }

   @Override
   public String toString()
   {
       return "Poem [title=" + title + ", poet=" + poet + "]";
   }

}

Solutions

Expert Solution

//The code and output both have been provided in case of any doubts please do comment..

import java.util.LinkedList;
import java.util.ListIterator;

public class Poems {

    public static void main(String[] args) {
        //Initializing a Linked List of Poem Object
        LinkedList<Poem> poems = new LinkedList<Poem>();

        //Adding the various Poems to poems Linked List
        poems.add(new Poem("The Good Life", "Tracy K. Smith"));
        poems.add(new Poem("How Bright It Is", "Brian Turner"));
        poems.add(new Poem("Numbers", "Mary Cornish"));
        poems.add(new Poem("The Road Not Taken", "Robert Frost"));
        poems.add(new Poem("Daffodils", "William Wordsworth"));
        poems.add(new Poem("Sonnet 18", "William Shakespeare"));
        poems.add(new Poem("A Psalm Of Life", "Henry Wadsworth Longfellow"));

        //Declaration and initialization of list iterator to iterate over poems
        ListIterator<Poem> iterator = poems.listIterator();
        System.out.println("=========================");
        //It iterates until next is not null
        while (iterator.hasNext()){
            //Store current poem index in current Poem and iterate to next poem
            Poem currentPoem = iterator.next();
            System.out.println("The current poem is \"" + currentPoem.getTitle() + "\" and its author is \"" + currentPoem.getPoet() + "\"");
        }
        System.out.println("=========================");

    }


}


Related Solutions

Can you make this singular linked list to doubly linked list Create a Doubly Linked List....
Can you make this singular linked list to doubly linked list Create a Doubly Linked List. Use this to create a Sorted Linked List, Use this to create a prioritized list by use. Bring to front those links recently queried. -----link.h------ #ifndef LINK_H #define LINK_H struct Link{ int data; Link *lnkNxt; }; #endif /* LINK_H */ ----main.cpp---- //System Level Libraries #include <iostream> //I/O Library using namespace std; //Libraries compiled under std #include"Link.h" //Global Constants - Science/Math Related //Conversions, Higher Dimensions...
Introduction: In this project you will create a generic linked list using Java Generics. Description: Create...
Introduction: In this project you will create a generic linked list using Java Generics. Description: Create a generic class called GenLinkedList. GenLinkedList will use nodes that store a value of the generic type to store its contents. It should have the following methods. The methods should all operate on the object making the call (none are static). Perform checking of the parameters and throw exceptions where appropriate. The linked list should be singly-linked. It should not use sentinel nodes (empty...
Using C++, Create a singly Linked List of patients list so that you can sort and...
Using C++, Create a singly Linked List of patients list so that you can sort and search the list by last 4 digits of the patient's Social Security number. Implement Node insertion, deletion, update and display functionality in the Linked List. Each patient's record or node should have the following data: Patient Name: Age: Last 4 digits of Social Security Number: The program should first display a menu that gives the user the option to: 1) Add a Patient's record...
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header file...
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header file is also given. The given testfile listmain.cpp is given for demonstration of unsorted list functionality. The functions header file is also given. Complete the functions of the header file linked_list.h below. ========================================================= // listmain.cpp #include "Linked_List.h" int main(int argc, char **argv) {      float           f;      Linked_List *theList;      cout << "Simple List Demonstration\n";      cout << "(List implemented as an Array - Do...
1.List the four objects provided by the WSH to interact with the computer system using a...
1.List the four objects provided by the WSH to interact with the computer system using a scripting language: 2.What does the following instruction do? at 22:00 /every:monday dfrgui.exe 3. What does the following command line statement do? schtasks /create /? 4.What does the following command line statement do? schtasks /create /sc daily /tn t1 /tr chkdsk.exe /st 23:45:00 5.What does the following instruction do? schtasks /delete /tn task3 6. What does the following command prompt instruction do? move .\*.txt D:\files...
First, create a project that creates an ordered linked list class (use the code provided, make...
First, create a project that creates an ordered linked list class (use the code provided, make sure to update the insert function so that it maintains an ordered list). To this class, add a function that prints the list in REVERSE order. Making use of recursion is the easiest and best way to do this, but certainly not the only way. Submit a .zip of your entire project.
Using Java Summary Create a Loan class, instantiate and write several Loan objects to a file,...
Using Java Summary Create a Loan class, instantiate and write several Loan objects to a file, read them back in, and format a report. Project Description You’ll read and write files containing objects of the Loan class. Here are the details of that class: Instance Variables: customer name (String) annual interest percentage (double) number of years (int) loan amount (double) loan date (String) monthly payment (double) total payments (double) Methods: getters for all instance variables setters for all instance variables...
In python I want to create a function that takes in a linked list. Using recursion...
In python I want to create a function that takes in a linked list. Using recursion only, I want to check if the linked list is sorted. How do i do this?
Using the singly linked list code as a base, create a class that implements a doubly...
Using the singly linked list code as a base, create a class that implements a doubly linked list. A doubly linked list has a Previous link so you can move backwards in the list. Be sure the class is a template class so the user can create a list with any data type. Be sure to test all the member functions in your test program. c++
Using the template provided in DocSharing (using this form is required), create a list of ten...
Using the template provided in DocSharing (using this form is required), create a list of ten (10) structured interview questions and submit it to your Dropbox by the end of Week 5 using the following guidelines: Your original questions (e.g. written by you) should only contain legally allowable, job related inquiries. Act as if the organization you are working for is obligated under Title VII and the other major, federal employment laws when writing these questions. A brief rationale for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT