Question: I need help with a Java assignment: Create a class named Poem that contains the following fields: title - the name of the poem (of

I need help with a Java assignment:

Create a class named Poem that contains the following fields:

  • title - the name of the poem (of type String)
  • lines - the number of lines in the poem (of type int)

Include a constructor that requires values for both fields. Also include get methods to retrieve field values. Create three subclasses: Couplet, Limerick, and Haiku. The constructor for each subclass requires only a title; the lines field is set using a constant value. A couplet has two lines, a limerick has five lines, and a haiku has three lines.

This is the only information I was given to start with for the DemoPoems.java;

public class DemoPoems { public static void main(String[] args) { Poem poem1 = new Poem("The Raven", 84); Couplet poem2 = new Couplet("True Wit"); Limerick poem3 = new Limerick("There was an Old Man with a Beard"); Haiku poem4 = new Haiku("The Wren"); display(poem1); display(poem2); display(poem3); display(poem4); }

public static void display(Poem p) { System.out.println("Poem: " + p.getTitle() + " Lines: " + p.getLines()); } }

I need help with a Java assignment: Create a class named Poem

Programming Exercise 10-4 FILETREE | Couplet.java DemoPoem.-. | Haiku.java 1 public class DemoPoens 3 public static void main (String] args) Instructions x Limerick.java Poem.java root/sandbox Couplet.java Create a class named Poem that contains the following fields: sti Haiku.java Limerick.java Poem,java title-the name of the poem (of type String) 1ines- the number of lines in the poem (of type tnt ) Include a constructor that requires values for both fields. Also include get methods to retrieve field values. Create three subclasses: Couplet, Linerick, and Haiku . The constructor for each subclass requires only a title; the ltnes field is set using a constant value. A couplet has two lines, a limerick has five lines, and a haiku has three ines Poen poennew Poen("The Raven", 84); Couplet poem2 new Couplet( True Wit"): Lurerck poem3 new Lumerick( "There was an Old Man with a Beard"); Haiku poem4 new Haiku( The Wren display (poen1): display (poem2): display(poem3); display(poen4) s/p 18 12 13 14 15 public static vold display(Poem p) 16 17 18 19 28 21 Grading Write your Java code in the area on the right. Use the Run button to compile and run the code. Clicking the Run Checks button will run pre-configured tests against your code to calculate a grade. Systen.out.printIn("Poen: + .getTitle() + "Ltnes: "p.getLtnesO) e you are happy with your results, click the Submit button to record your score Onc

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!