1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rudiy27
3 years ago
14

Create a class named Poem that contains the following fields: title - the name of the poem (of type String) lines - the number o

f 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());
}
}
Computers and Technology
1 answer:
denpristay [2]3 years ago
7 0

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 <u>extended from Poem class</u>. Also, in display method, you call getTitle(), however, it's written as getPoemName() in the <em>Poem</em> class. You need to change the name.

You might be interested in
Briley has all the hardware she needs to construct a fully functional personal computer. She connects the various components and
ikadub [295]

Answer:

System software.      

Explanation:

The system software is the software which has system need to running Without the system software the computer system will not start and work simply means to interact with the computer system we need system software.  

  • Briley needs system software to connects the different parts and input-output devices, and it provides the ensuring that the computer system has a power supply available.
  • So without the System software, Briley will not interact with the computer system.
6 0
2 years ago
is a private connection of LANs and WANs that belongs to an organization, and is designed to be accessible only by the members a
Sedaia [141]

Answer:

Intranet.

Explanation:

The intranet will provide the sharing of information within the organization. It does not provide the accessibility of the network or the sharing of information outside the organization. The main advantage of the Intranet is to improve communication between the employees.

The intranet is a private connection of LAN and WAN which are belongs to an organization it means this network is authorized by the employee within organization not outside the organization .

7 0
2 years ago
Consider the classes below, declared in the same file: class A { int a; public A() { ​ a = 7; } } class B extends A { int b; pub
DiKsa [7]

Answer:

2. <em>A reference of type A can be treated as a reference of type B</em> - False

Base class or its objects are not related to their derived class (or its objects).

Explanation:

class A {

   int a;

   public A() {

       a = 7;

   }

}

class B extends A {

   int b;

   public B() {

       b = 8;

   }

}

///////////////////////////////////////////////////////////////////////////////////////////////////////

1. <em>After the constructor for class B executes, the variable a will have the value 7 </em>- True.

When an object of a derived class is declared, the constructor of base class is called before the constructor of derived class (is called).

3. <em>Both variables a and b are instance variables </em>- True.

Classes can have instance, or member, variables and methods.

4.<em> After the constructor for class B executes, the variable b will have the value 8</em> - True.

When object of class B is declared, its constructor was called, which initialized variable b to 8.

4 0
3 years ago
You have been tracking your exercise routine, which involves running, lifting weights, yoga, and stretching. You want to see wha
Harrizon [31]

The best chart to see the data distribution for the exercise routine would be a pie chart. Using Microsoft Excel, you can input each data point you have for all you exercise routine category, and generate a pie chart which will show you the percentage for each category in comparison to the total.


5 0
3 years ago
Read 2 more answers
To define constructors and member functions outside of a class's original scope, the operator can be used.
Artyom0805 [142]

Answer: Scope resolution operator(::)

Explanation: A member function and the constructor can be called within the function easily but for the execution of the these components outside the class , a special operator is required to call the functions. The scope resolution operator(::) preceding with the name of class is thus used for defining of the function outside class.This operator maintains the cope of the function and constructor outside the class.

8 0
2 years ago
Other questions:
  • Is a software program that allows users to access the world wide web
    10·1 answer
  • On laptops with a smart card reader installed, where is the smart card reader usually located?
    13·1 answer
  • Gabriel needs to create a formula that does not change when it is copied to cell b2. which formula should he create?
    14·1 answer
  • Project using simple formulas
    15·1 answer
  • Identify which statement explains why a programmer would break a logic problem into steps.
    13·2 answers
  • Look at the following program and answer the question that follows it. 1 // This program displays my gross wages. 2 // I worked
    8·1 answer
  • Can someone help me i need to write something for cyber bullying
    11·2 answers
  • Free 35 points!!!
    11·2 answers
  • Explains why we use tables in documents; and is at least three sentences long in word office 360​
    15·1 answer
  • What is good work ethic?​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!