Poem.java
package demopoems;
public class Poem {
private String name;
private int number_of_lines;
Poem(){
}
Poem(String s, int n){
name = s;
number_of_lines = n;
}
String getName(){
return name;
}
int getNumber(){
return number_of_lines;
}
}
Couplet.java
package demopoems;
public class Couplet extends Poem {
private String title;
private int lines;
Couplet(String t){
super(t,2);
}
void display(){
System.out.printf("Name: %s\nNumber of lines: %d\n",getName(), getNumber());
}
}
Limerick.java
package demopoems;
public class Limerick extends Poem{
private String title;
private int lines;
Limerick(String t){
super(t, 5);
}
void display(){
System.out.printf("Name: %s\nNumber of lines: %d\n",getName(), getNumber());
}
}
DemoPoems.java
package demopoems;
public class DemoPoems {
public static void main(String[] args) {
Haiku h = new Haiku("Testing Haiku");
Couplet c = new Couplet("Testing Couplet");
Limerick l = new Limerick("Testing Limeric");
h.display();
c.display();
l.display();
}
}
Comments
Leave a comment