subject

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.

Please correct so code works:

Couplet. java

public class Couplet
{
private final static int LINES = 2;
public Couplet(String poemName)
{
super(poemName, LINES);
}
}

Haiku. java

public class Haiku extends Poem
{
private static int LINES = 3;
public Haiku(String poemName)
{
super(poemName, LINES);
}
}

Limerick. java

public class Limerick
{
private static int LINES = 5;
public Limerick(String poemName)
{
super(poemName, LINES);
}
}

Poem. java

public class Poem
{
private String poemName;
private int lines;

public Poem(String poemName, int lines)
{
this. poemName = poemName;
this. lines = lines;
}

public String getPoemName()
{
return poemName;
}

public int getLines()
{
return lines;
}
}

DemoPoem. java

import java. util.*;
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());
}
}

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:30, kieraweems2034
Communication is the exchange of information. true false
Answers: 2
image
Computers and Technology, 23.06.2019 13:30, mads000
Drag the tiles to the correct boxes to complete the pairs. match the errors with their definitions. #name #value #ref when a formula produces output that is too lengthy to fit in the spreadsheet cell arrowright when you enter an invalid cell reference in a formula arrowright when you type text in cells that accept numeric data arrowright when you type in a cell reference that doesn’t exist arrowright reset next
Answers: 1
image
Computers and Technology, 23.06.2019 14:00, savannnab1890
Select the correct answer. andre was recently hired by an organization to check for system vulnerabilities. he is supposed to exploit these vulnerabilities and create a report on the extent of damage to which the system was susceptible. what position does andre hold in this organization? a. information security analyst b. information assurance manager c. penetration tester d. network security engineer e. chief information security officer
Answers: 2
image
Computers and Technology, 23.06.2019 20:00, shadow6728g
How much current flows through the alternator brushes? a. 2–5 a b. 25–35 a, depending on the vehicle c. 5–10 a d. 10–15 a
Answers: 2
You know the right answer?
Create a class named Poem that contains the following fields: title - the name of the poem (of type...

Questions in other subjects:

Konu
Mathematics, 30.06.2019 22:00
Konu
Mathematics, 30.06.2019 22:00