Respuesta :
Answer:
Couplet.java
public class Couplet extends Poem
{
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 extends Poem
{
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.getPoemName() +
" Lines: " + p.getLines());
}
}
Explanation:
The Couplet and Limerick classes should also be extended from Poem class. Also, in display method, you call getTitle(), however, it's written as getPoemName() in the Poem class. You need to change the name.
In this exercise we have to use the knowledge in computational language in JAVA to describe a code that best suits, so we have:
The code can be found in the attached image.
To make it simpler we can write this code as:
Couplet.java
public class Couplet extends Poem
{
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 extends Poem
{
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.getPoemName() +
" Lines: " + p.getLines());
}
}
See more about JAVA at brainly.com/question/19705654

