SlideShare a Scribd company logo
1 of 11
Download to read offline
In this project you will define some interfaces, abstract classes, and concrete classes, all placed in
a specific package. You will also use the instanceofoperator. Note: if you do not use interfaces,
abstract classes, and/or instanceof, you will not receive full credit.
Project description:
1. Define an interface called Nameable with the following methods:
2. Define an interface called Runner with the following method:
3. Define an interface called Flyer with the following method:
4. Define an abstract class called Animal which must implement the Nameable interface. Add the
representation of:
Animal's name,
Animal's number of legs,
Animal's age, and
Keep count of the instances of the Animal class by using a static variable.
If you believe you should define a variable as static, or final, or even both, do so and briefly
mention the reason as a comment on that variable in javadoc format (see below).
Use suitable qualifiers for all fields in the class.
5. Define a class called Dog, where a Dog is-a subclass of Animal. Also, a Dog can run (i.e. this
class should implement the Runner interface).
6. Define a class called Cat, where a Cat is-a subclass of Animal. Also, a Cat can run (i.e. this
class should implement the Runner interface).
7. Define a class called FlyCat, where a FlyCat is-a (imaginary) subclass of Animal that can fly
(i.e. this class should implement the Flyerinterface).
8. Define a class called Dragon, where a Dragon is-a (imaginary) subclass of Animal that can
both run and fly (i.e. this class should implement both the Runner and Flyer interfaces).
9. Each of the Animal subclasses has one or two capabilities: it can fly, or run, or both. When
one calls fly on an animal that can fly, fly should print [name of the animal] + " is flying".
Similarly run should print [name of the animal] + " is running".
10. Be creative and find more Animal kinds (at least two more). One of these new animal types
(can be imaginary) should be able to both fly and run, and should be a direct subclass of Animal.
11. Create three animals of each type (3 dogs, 3 cats, etc), with different given names and
suitable attribute values. The names can be as simple as Joe1, Joe2, etc.
12. Store the Animal objects (above) in an array of type Animal.
13. Display a menu to the user on the screen (before implementing this part, read the notes
below).
Press 1 to see how many animals are in the system.
Press 2 to see the name and kind of each animal.
Press 3 to see which animals can fly.
Press 4 to see which animals can run.
Press 5 to see which animals can run AND fly.
Press 6 to see a description of each animal.
Press q to terminate the program.
14. Important notes about the menu:
If the user enters anything other than {1, 2, 3, 4, 5, 6, q}, the program should print a proper error
message, and ask the user to enter a number between {1, 2, 3, 4, 5, 6} or 'q' (to quit). In other
words, your program should not continue (or even worse, crash) if the user enters a wrong
choice.
In option 1, the result should be the total number of instances of Animal class created so far (use
the static variable).
For option 2, use instanceof to get kind.
For option 3, use instanceof. The result should contain both name (Joe1, Joe2, etc) and type
(Dog, Cat, etc) of the animal.
For option 4, use instanceof.The result should contain both name and type (Dog, Cat, etc) of the
animal.
For option 5, use instanceof. The result should contain both name and type (Dog, Cat, etc) of the
animal.
Option 6 above could display something like this:
Things to note:
Your program must be in package zoo.
You must provide setters and getters for all instance variables in classes.
Follow good coding style (proper variable names, indentation, etc).
Your design should be reasonably efficient, and in accordance with object oriented design
principles (encapsulation, information hiding, inheritance, etc.).
If you are defining a variable as public or protected, briefly mention the reason for that.
If you are defining a variable as static or final, briefly mention the reason for that, as well.
Write your important comments in a way that is usable by javadoc. You should use appropriate
tags in your comments. Important comments include:
Explanation of what a specific variable is. Such a comment will be used by javadoc only if it is
for a public or protected variable. So if you have provided a comment for a private variable and
it does not show up in the HTML files, that is ok.
Explanation of what a function does, its parameters, its return types, the exceptions it may throw.
Solution
Java Code:
package zoo;
public interface Nameable {
String getName();
void setName(String name);
}
package zoo;
public interface Flyer {
void fly();
}
package zoo;
public interface Runner {
void run();
}
package zoo;
public abstract class Animal implements Nameable {
private String name;
private int numberOfLegs;
private int age;
/**
* Shared variable across all
*/
protected static int ANIMAL_COUNT=0;
/**
* @param name
* @param numberOfLegs
* @param age
*/
public Animal(String name, int numberOfLegs, int age) {
this.name = name;
this.numberOfLegs = numberOfLegs;
this.age = age;
ANIMAL_COUNT++;
}
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name=name;
}
/**
* @return the numberOfLegs
*/
public int getNumberOfLegs() {
return numberOfLegs;
}
/**
* @param numberOfLegs the numberOfLegs to set
*/
public void setNumberOfLegs(int numberOfLegs) {
this.numberOfLegs = numberOfLegs;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
}
/**
*
*/
package zoo;
/**
* @author ramesh
*
*/
public class Cat extends Animal implements Runner {
public Cat(String name, int numberOfLegs, int age) {
super(name, numberOfLegs, age);
}
/* (non-Javadoc)
* @see zoo.Runner#run()
*/
@Override
public void run() {
System.out.println(this.getName()+ "is running");
}
}
package zoo;
public class Dog extends Animal implements Runner {
public Dog(String name, int numberOfLegs, int age) {
super(name, numberOfLegs, age);
}
@Override
public void run() {
System.out.println(this.getName()+ "is running");
}
}
/**
*
*/
package zoo;
/**
* @author ramesh
*
*/
public class Dragon extends Animal implements Flyer, Runner {
public Dragon(String name, int numberOfLegs, int age) {
super(name, numberOfLegs, age);
}
/*
* (non-Javadoc)
*
* @see zoo.Runner#run()
*/
@Override
public void run() {
System.out.println(this.getName()+ "is running");
}
/*
* (non-Javadoc)
*
* @see zoo.Flyer#fly()
*/
@Override
public void fly() {
System.out.println(this.getName()+ "is flying");
}
}
/**
*
*/
package zoo;
/**
* @author ramesh
*
*/
public class FlyCat extends Animal implements Flyer {
public FlyCat(String name, int numberOfLegs, int age) {
super(name, numberOfLegs, age);
}
/* (non-Javadoc)
* @see zoo.Flyer#fly()
*/
@Override
public void fly() {
System.out.println(this.getName()+ "is flying");
}
}
/**
*
*/
package zoo;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* @author ramesh
*
*/
public class ZooDriver {
// AVL Tree test driver
public static void main(String[] args) {
try (Scanner scan = new Scanner(System.in)) {
List animals = new ArrayList();
Animal dog1 = new Dog("Joe1", 4, 8);
Animal dog2 = new Dog("Joe2", 4, 7);
Animal dog3 = new Dog("Joe3", 4, 5);
animals.add(dog1);
animals.add(dog2);
animals.add(dog3);
Animal cat1 = new Cat("cat1", 4, 6);
Animal cat2 = new Cat("cat2", 4, 3);
Animal cat3 = new Cat("cat3", 4, 2);
animals.add(cat1);
animals.add(cat2);
animals.add(cat3);
// Display MANU to user
System.out.println(showManu());
while (true) {
// Get user choice from system console
System.out.println("Enter a number between {1, 2, 3, 4, 5, 6} or 'q' (to quit)");
String choice = scan.next();
if (choice.equals("q"))
break;
switch (choice) {
case "1":
System.out.println(
"The total number of instances of Animal class created so far:" +
Animal.ANIMAL_COUNT);
break;
case "2":
for (Animal animal : animals) {
System.out.print("Name of Animal: " + animal.getName()+", ");
if (animal instanceof Dog) {
System.out.println("Kind of animal: Dog");
} else if (animal instanceof Cat) {
System.out.println("Kind of animal: Cat");
} else if (animal instanceof FlyCat) {
System.out.println("Kind of animal: FlyCat");
} else if (animal instanceof Dragon) {
System.out.println("Kind of animal: Dragon");
}
}
break;
case "3":
for (Animal animal : animals) {
if (animal instanceof FlyCat) {
System.out.println("Name of animal:" + animal.getName() + ", Kind of
animal: FlyCat");
} else if (animal instanceof Dragon) {
System.out.println("Name of animal:" + animal.getName() + ", Kind of
animal: Dragon");
}
}
break;
case "4":
for (Animal animal : animals) {
if (animal instanceof Dog) {
System.out.println("Name of animal:" + animal.getName() + ", Kind of
animal: Dog");
} else if (animal instanceof Cat) {
System.out.println("Name of animal:" + animal.getName() + ", Kind of
animal: Cat");
}
}
break;
case "5":
for (Animal animal : animals) {
if (animal instanceof Dragon) {
System.out.println("Name of animal:" + animal.getName() + ", Kind of
animal: Dragon");
}
}
break;
case "6":
for (Animal animal : animals) {
if (animal instanceof Dog) {
System.out.println(
"I am a " + animal.getAge() + "years old Dog and my name is " +
animal.getName()
+ ". I have " + animal.getNumberOfLegs() + " legs and I can
run.");
} else if (animal instanceof Cat) {
System.out.println(
"I am a " + animal.getAge() + "years old Cat and my name is " +
animal.getName()
+ ". I have " + animal.getNumberOfLegs() + " legs and I can
run.");
} else if (animal instanceof FlyCat) {
System.out.println(
"I am a " + animal.getAge() + "years old FlyCat and my name is " +
animal.getName()
+ ". I have " + animal.getNumberOfLegs() + " legs and I can
fly/run.");
} else if (animal instanceof Dragon) {
System.out.println(
"I am a " + animal.getAge() + "years old Dragon and my name is " +
animal.getName()
+ ". I have " + animal.getNumberOfLegs() + " legs and I can
fly/run.");
}
}
break;
default:
System.out.println("Wrong Entry  ");
break;
}
}
}
}
private static String showManu() {
return "Press 1 to see how many animals are in the system. "
+ "Press 2 to see the name and kind of each animal. " + "Press 3 to see which
animals can fly. "
+ "Press 4 to see which animals can run. " + "Press 5 to see which animals can run
AND fly. "
+ "Press 6 to see a description of each animal. " + "Press q to terminate the
program. ";
}
}

More Related Content

Similar to In this project you will define some interfaces, abstract classes, a.pdf

Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classesFajar Baskoro
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingShivam Singhal
 
Polymorphism.ppt
Polymorphism.pptPolymorphism.ppt
Polymorphism.pptEmanAsem4
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsRasan Samarasinghe
 
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdf
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdfAdapt your code from Assignment 2 to use both a Java API ArrayList a.pdf
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdfalbarefqc
 
14 Defining classes
14 Defining classes14 Defining classes
14 Defining classesmaznabili
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodecamp Romania
 
I need some help creating Psuedocode for a project using Java. Basic.pdf
I need some help creating Psuedocode for a project using Java. Basic.pdfI need some help creating Psuedocode for a project using Java. Basic.pdf
I need some help creating Psuedocode for a project using Java. Basic.pdffashionfootwear1
 
Handout - Introduction to Programming
Handout - Introduction to ProgrammingHandout - Introduction to Programming
Handout - Introduction to ProgrammingCindy Royal
 

Similar to In this project you will define some interfaces, abstract classes, a.pdf (20)

Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Java2
Java2Java2
Java2
 
Polymorphism.ppt
Polymorphism.pptPolymorphism.ppt
Polymorphism.ppt
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basics
 
Java
JavaJava
Java
 
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdf
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdfAdapt your code from Assignment 2 to use both a Java API ArrayList a.pdf
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdf
 
PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
PHP Classes and OOPS Concept
 
chap11.ppt
chap11.pptchap11.ppt
chap11.ppt
 
14 Defining classes
14 Defining classes14 Defining classes
14 Defining classes
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Ppt on java basics1
Ppt on java basics1Ppt on java basics1
Ppt on java basics1
 
Clean Code
Clean CodeClean Code
Clean Code
 
Polymorphism.pptx
Polymorphism.pptxPolymorphism.pptx
Polymorphism.pptx
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
I need some help creating Psuedocode for a project using Java. Basic.pdf
I need some help creating Psuedocode for a project using Java. Basic.pdfI need some help creating Psuedocode for a project using Java. Basic.pdf
I need some help creating Psuedocode for a project using Java. Basic.pdf
 
Handout - Introduction to Programming
Handout - Introduction to ProgrammingHandout - Introduction to Programming
Handout - Introduction to Programming
 

More from fathimaoptical

Define a knowledge-based agent, and describe its major components. W.pdf
Define a knowledge-based agent, and describe its major components. W.pdfDefine a knowledge-based agent, and describe its major components. W.pdf
Define a knowledge-based agent, and describe its major components. W.pdffathimaoptical
 
Create a function mean comp that compares the mean value of the odd n.pdf
Create a function mean comp that compares the mean value of the odd n.pdfCreate a function mean comp that compares the mean value of the odd n.pdf
Create a function mean comp that compares the mean value of the odd n.pdffathimaoptical
 
Compare naive, effector, and memory T & B cells (survival time, Ig &.pdf
Compare naive, effector, and memory T & B cells (survival time, Ig &.pdfCompare naive, effector, and memory T & B cells (survival time, Ig &.pdf
Compare naive, effector, and memory T & B cells (survival time, Ig &.pdffathimaoptical
 
Consider the titration of50.0 mL of 0.217 M hydrazoic acid (HN3, Ka=.pdf
Consider the titration of50.0 mL of 0.217 M hydrazoic acid (HN3, Ka=.pdfConsider the titration of50.0 mL of 0.217 M hydrazoic acid (HN3, Ka=.pdf
Consider the titration of50.0 mL of 0.217 M hydrazoic acid (HN3, Ka=.pdffathimaoptical
 
Choose one of the evolutions of CIT and discuss how it may have made.pdf
Choose one of the evolutions of CIT and discuss how it may have made.pdfChoose one of the evolutions of CIT and discuss how it may have made.pdf
Choose one of the evolutions of CIT and discuss how it may have made.pdffathimaoptical
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdffathimaoptical
 
Without the effects of cyanobacteria or algae on lichen metabolism, .pdf
Without the effects of cyanobacteria or algae on lichen metabolism, .pdfWithout the effects of cyanobacteria or algae on lichen metabolism, .pdf
Without the effects of cyanobacteria or algae on lichen metabolism, .pdffathimaoptical
 
What is this image trying to tell you about the American West.pdf
What is this image trying to tell you about the American West.pdfWhat is this image trying to tell you about the American West.pdf
What is this image trying to tell you about the American West.pdffathimaoptical
 
What is the difference between a defined-benefit and a defined-contr.pdf
What is the difference between a defined-benefit and a defined-contr.pdfWhat is the difference between a defined-benefit and a defined-contr.pdf
What is the difference between a defined-benefit and a defined-contr.pdffathimaoptical
 
This is question about excel cuers.How would you use Financial Fun.pdf
This is question about excel cuers.How would you use Financial Fun.pdfThis is question about excel cuers.How would you use Financial Fun.pdf
This is question about excel cuers.How would you use Financial Fun.pdffathimaoptical
 
The surface area to volume ration is least improtant in thea. sink.pdf
The surface area to volume ration is least improtant in thea. sink.pdfThe surface area to volume ration is least improtant in thea. sink.pdf
The surface area to volume ration is least improtant in thea. sink.pdffathimaoptical
 
The Martian calendar has sixteen months instead of twelve. What is t.pdf
The Martian calendar has sixteen months instead of twelve. What is t.pdfThe Martian calendar has sixteen months instead of twelve. What is t.pdf
The Martian calendar has sixteen months instead of twelve. What is t.pdffathimaoptical
 
Baby names and birth weights”IntroductionBabies are weighed soon.pdf
Baby names and birth weights”IntroductionBabies are weighed soon.pdfBaby names and birth weights”IntroductionBabies are weighed soon.pdf
Baby names and birth weights”IntroductionBabies are weighed soon.pdffathimaoptical
 
Question How can I called this method in the main, and how can I .pdf
Question How can I called this method in the main, and how can I .pdfQuestion How can I called this method in the main, and how can I .pdf
Question How can I called this method in the main, and how can I .pdffathimaoptical
 
Question 1. List and describe three rules of natural justice, provid.pdf
Question 1. List and describe three rules of natural justice, provid.pdfQuestion 1. List and describe three rules of natural justice, provid.pdf
Question 1. List and describe three rules of natural justice, provid.pdffathimaoptical
 
Postal ClerkAssistant. Why do the five steps of the recruitment pro.pdf
Postal ClerkAssistant. Why do the five steps of the recruitment pro.pdfPostal ClerkAssistant. Why do the five steps of the recruitment pro.pdf
Postal ClerkAssistant. Why do the five steps of the recruitment pro.pdffathimaoptical
 
OverviewWe will be adding some validation to our Contact classes t.pdf
OverviewWe will be adding some validation to our Contact classes t.pdfOverviewWe will be adding some validation to our Contact classes t.pdf
OverviewWe will be adding some validation to our Contact classes t.pdffathimaoptical
 
Negotiation - Porto (Porto case).note this is a case study so the.pdf
Negotiation - Porto (Porto case).note this is a case study so the.pdfNegotiation - Porto (Porto case).note this is a case study so the.pdf
Negotiation - Porto (Porto case).note this is a case study so the.pdffathimaoptical
 
need help with my computer science lab assignemnt. this assignment i.pdf
need help with my computer science lab assignemnt. this assignment i.pdfneed help with my computer science lab assignemnt. this assignment i.pdf
need help with my computer science lab assignemnt. this assignment i.pdffathimaoptical
 
Name a protein that contacts the insulin receptor inside the cell.pdf
Name a protein that contacts the insulin receptor inside the cell.pdfName a protein that contacts the insulin receptor inside the cell.pdf
Name a protein that contacts the insulin receptor inside the cell.pdffathimaoptical
 

More from fathimaoptical (20)

Define a knowledge-based agent, and describe its major components. W.pdf
Define a knowledge-based agent, and describe its major components. W.pdfDefine a knowledge-based agent, and describe its major components. W.pdf
Define a knowledge-based agent, and describe its major components. W.pdf
 
Create a function mean comp that compares the mean value of the odd n.pdf
Create a function mean comp that compares the mean value of the odd n.pdfCreate a function mean comp that compares the mean value of the odd n.pdf
Create a function mean comp that compares the mean value of the odd n.pdf
 
Compare naive, effector, and memory T & B cells (survival time, Ig &.pdf
Compare naive, effector, and memory T & B cells (survival time, Ig &.pdfCompare naive, effector, and memory T & B cells (survival time, Ig &.pdf
Compare naive, effector, and memory T & B cells (survival time, Ig &.pdf
 
Consider the titration of50.0 mL of 0.217 M hydrazoic acid (HN3, Ka=.pdf
Consider the titration of50.0 mL of 0.217 M hydrazoic acid (HN3, Ka=.pdfConsider the titration of50.0 mL of 0.217 M hydrazoic acid (HN3, Ka=.pdf
Consider the titration of50.0 mL of 0.217 M hydrazoic acid (HN3, Ka=.pdf
 
Choose one of the evolutions of CIT and discuss how it may have made.pdf
Choose one of the evolutions of CIT and discuss how it may have made.pdfChoose one of the evolutions of CIT and discuss how it may have made.pdf
Choose one of the evolutions of CIT and discuss how it may have made.pdf
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdf
 
Without the effects of cyanobacteria or algae on lichen metabolism, .pdf
Without the effects of cyanobacteria or algae on lichen metabolism, .pdfWithout the effects of cyanobacteria or algae on lichen metabolism, .pdf
Without the effects of cyanobacteria or algae on lichen metabolism, .pdf
 
What is this image trying to tell you about the American West.pdf
What is this image trying to tell you about the American West.pdfWhat is this image trying to tell you about the American West.pdf
What is this image trying to tell you about the American West.pdf
 
What is the difference between a defined-benefit and a defined-contr.pdf
What is the difference between a defined-benefit and a defined-contr.pdfWhat is the difference between a defined-benefit and a defined-contr.pdf
What is the difference between a defined-benefit and a defined-contr.pdf
 
This is question about excel cuers.How would you use Financial Fun.pdf
This is question about excel cuers.How would you use Financial Fun.pdfThis is question about excel cuers.How would you use Financial Fun.pdf
This is question about excel cuers.How would you use Financial Fun.pdf
 
The surface area to volume ration is least improtant in thea. sink.pdf
The surface area to volume ration is least improtant in thea. sink.pdfThe surface area to volume ration is least improtant in thea. sink.pdf
The surface area to volume ration is least improtant in thea. sink.pdf
 
The Martian calendar has sixteen months instead of twelve. What is t.pdf
The Martian calendar has sixteen months instead of twelve. What is t.pdfThe Martian calendar has sixteen months instead of twelve. What is t.pdf
The Martian calendar has sixteen months instead of twelve. What is t.pdf
 
Baby names and birth weights”IntroductionBabies are weighed soon.pdf
Baby names and birth weights”IntroductionBabies are weighed soon.pdfBaby names and birth weights”IntroductionBabies are weighed soon.pdf
Baby names and birth weights”IntroductionBabies are weighed soon.pdf
 
Question How can I called this method in the main, and how can I .pdf
Question How can I called this method in the main, and how can I .pdfQuestion How can I called this method in the main, and how can I .pdf
Question How can I called this method in the main, and how can I .pdf
 
Question 1. List and describe three rules of natural justice, provid.pdf
Question 1. List and describe three rules of natural justice, provid.pdfQuestion 1. List and describe three rules of natural justice, provid.pdf
Question 1. List and describe three rules of natural justice, provid.pdf
 
Postal ClerkAssistant. Why do the five steps of the recruitment pro.pdf
Postal ClerkAssistant. Why do the five steps of the recruitment pro.pdfPostal ClerkAssistant. Why do the five steps of the recruitment pro.pdf
Postal ClerkAssistant. Why do the five steps of the recruitment pro.pdf
 
OverviewWe will be adding some validation to our Contact classes t.pdf
OverviewWe will be adding some validation to our Contact classes t.pdfOverviewWe will be adding some validation to our Contact classes t.pdf
OverviewWe will be adding some validation to our Contact classes t.pdf
 
Negotiation - Porto (Porto case).note this is a case study so the.pdf
Negotiation - Porto (Porto case).note this is a case study so the.pdfNegotiation - Porto (Porto case).note this is a case study so the.pdf
Negotiation - Porto (Porto case).note this is a case study so the.pdf
 
need help with my computer science lab assignemnt. this assignment i.pdf
need help with my computer science lab assignemnt. this assignment i.pdfneed help with my computer science lab assignemnt. this assignment i.pdf
need help with my computer science lab assignemnt. this assignment i.pdf
 
Name a protein that contacts the insulin receptor inside the cell.pdf
Name a protein that contacts the insulin receptor inside the cell.pdfName a protein that contacts the insulin receptor inside the cell.pdf
Name a protein that contacts the insulin receptor inside the cell.pdf
 

Recently uploaded

Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 

Recently uploaded (20)

Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 

In this project you will define some interfaces, abstract classes, a.pdf

  • 1. In this project you will define some interfaces, abstract classes, and concrete classes, all placed in a specific package. You will also use the instanceofoperator. Note: if you do not use interfaces, abstract classes, and/or instanceof, you will not receive full credit. Project description: 1. Define an interface called Nameable with the following methods: 2. Define an interface called Runner with the following method: 3. Define an interface called Flyer with the following method: 4. Define an abstract class called Animal which must implement the Nameable interface. Add the representation of: Animal's name, Animal's number of legs, Animal's age, and Keep count of the instances of the Animal class by using a static variable. If you believe you should define a variable as static, or final, or even both, do so and briefly mention the reason as a comment on that variable in javadoc format (see below). Use suitable qualifiers for all fields in the class. 5. Define a class called Dog, where a Dog is-a subclass of Animal. Also, a Dog can run (i.e. this class should implement the Runner interface). 6. Define a class called Cat, where a Cat is-a subclass of Animal. Also, a Cat can run (i.e. this class should implement the Runner interface). 7. Define a class called FlyCat, where a FlyCat is-a (imaginary) subclass of Animal that can fly (i.e. this class should implement the Flyerinterface). 8. Define a class called Dragon, where a Dragon is-a (imaginary) subclass of Animal that can both run and fly (i.e. this class should implement both the Runner and Flyer interfaces). 9. Each of the Animal subclasses has one or two capabilities: it can fly, or run, or both. When one calls fly on an animal that can fly, fly should print [name of the animal] + " is flying". Similarly run should print [name of the animal] + " is running". 10. Be creative and find more Animal kinds (at least two more). One of these new animal types (can be imaginary) should be able to both fly and run, and should be a direct subclass of Animal. 11. Create three animals of each type (3 dogs, 3 cats, etc), with different given names and suitable attribute values. The names can be as simple as Joe1, Joe2, etc. 12. Store the Animal objects (above) in an array of type Animal. 13. Display a menu to the user on the screen (before implementing this part, read the notes below). Press 1 to see how many animals are in the system.
  • 2. Press 2 to see the name and kind of each animal. Press 3 to see which animals can fly. Press 4 to see which animals can run. Press 5 to see which animals can run AND fly. Press 6 to see a description of each animal. Press q to terminate the program. 14. Important notes about the menu: If the user enters anything other than {1, 2, 3, 4, 5, 6, q}, the program should print a proper error message, and ask the user to enter a number between {1, 2, 3, 4, 5, 6} or 'q' (to quit). In other words, your program should not continue (or even worse, crash) if the user enters a wrong choice. In option 1, the result should be the total number of instances of Animal class created so far (use the static variable). For option 2, use instanceof to get kind. For option 3, use instanceof. The result should contain both name (Joe1, Joe2, etc) and type (Dog, Cat, etc) of the animal. For option 4, use instanceof.The result should contain both name and type (Dog, Cat, etc) of the animal. For option 5, use instanceof. The result should contain both name and type (Dog, Cat, etc) of the animal. Option 6 above could display something like this: Things to note: Your program must be in package zoo. You must provide setters and getters for all instance variables in classes. Follow good coding style (proper variable names, indentation, etc). Your design should be reasonably efficient, and in accordance with object oriented design principles (encapsulation, information hiding, inheritance, etc.). If you are defining a variable as public or protected, briefly mention the reason for that. If you are defining a variable as static or final, briefly mention the reason for that, as well. Write your important comments in a way that is usable by javadoc. You should use appropriate tags in your comments. Important comments include: Explanation of what a specific variable is. Such a comment will be used by javadoc only if it is for a public or protected variable. So if you have provided a comment for a private variable and it does not show up in the HTML files, that is ok. Explanation of what a function does, its parameters, its return types, the exceptions it may throw.
  • 3. Solution Java Code: package zoo; public interface Nameable { String getName(); void setName(String name); } package zoo; public interface Flyer { void fly(); } package zoo; public interface Runner { void run(); } package zoo; public abstract class Animal implements Nameable { private String name; private int numberOfLegs; private int age; /** * Shared variable across all */ protected static int ANIMAL_COUNT=0; /** * @param name * @param numberOfLegs * @param age */ public Animal(String name, int numberOfLegs, int age) { this.name = name;
  • 4. this.numberOfLegs = numberOfLegs; this.age = age; ANIMAL_COUNT++; } @Override public String getName() { return name; } @Override public void setName(String name) { this.name=name; } /** * @return the numberOfLegs */ public int getNumberOfLegs() { return numberOfLegs; } /** * @param numberOfLegs the numberOfLegs to set */ public void setNumberOfLegs(int numberOfLegs) { this.numberOfLegs = numberOfLegs; } /** * @return the age */ public int getAge() { return age; } /** * @param age the age to set */ public void setAge(int age) { this.age = age; }
  • 5. } /** * */ package zoo; /** * @author ramesh * */ public class Cat extends Animal implements Runner { public Cat(String name, int numberOfLegs, int age) { super(name, numberOfLegs, age); } /* (non-Javadoc) * @see zoo.Runner#run() */ @Override public void run() { System.out.println(this.getName()+ "is running"); } } package zoo; public class Dog extends Animal implements Runner { public Dog(String name, int numberOfLegs, int age) { super(name, numberOfLegs, age); } @Override public void run() { System.out.println(this.getName()+ "is running"); } } /** * */ package zoo;
  • 6. /** * @author ramesh * */ public class Dragon extends Animal implements Flyer, Runner { public Dragon(String name, int numberOfLegs, int age) { super(name, numberOfLegs, age); } /* * (non-Javadoc) * * @see zoo.Runner#run() */ @Override public void run() { System.out.println(this.getName()+ "is running"); } /* * (non-Javadoc) * * @see zoo.Flyer#fly() */ @Override public void fly() { System.out.println(this.getName()+ "is flying"); } } /** * */ package zoo; /** * @author ramesh * */ public class FlyCat extends Animal implements Flyer {
  • 7. public FlyCat(String name, int numberOfLegs, int age) { super(name, numberOfLegs, age); } /* (non-Javadoc) * @see zoo.Flyer#fly() */ @Override public void fly() { System.out.println(this.getName()+ "is flying"); } } /** * */ package zoo; import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * @author ramesh * */ public class ZooDriver { // AVL Tree test driver public static void main(String[] args) { try (Scanner scan = new Scanner(System.in)) { List animals = new ArrayList(); Animal dog1 = new Dog("Joe1", 4, 8); Animal dog2 = new Dog("Joe2", 4, 7); Animal dog3 = new Dog("Joe3", 4, 5); animals.add(dog1); animals.add(dog2); animals.add(dog3); Animal cat1 = new Cat("cat1", 4, 6); Animal cat2 = new Cat("cat2", 4, 3); Animal cat3 = new Cat("cat3", 4, 2);
  • 8. animals.add(cat1); animals.add(cat2); animals.add(cat3); // Display MANU to user System.out.println(showManu()); while (true) { // Get user choice from system console System.out.println("Enter a number between {1, 2, 3, 4, 5, 6} or 'q' (to quit)"); String choice = scan.next(); if (choice.equals("q")) break; switch (choice) { case "1": System.out.println( "The total number of instances of Animal class created so far:" + Animal.ANIMAL_COUNT); break; case "2": for (Animal animal : animals) { System.out.print("Name of Animal: " + animal.getName()+", "); if (animal instanceof Dog) { System.out.println("Kind of animal: Dog"); } else if (animal instanceof Cat) { System.out.println("Kind of animal: Cat"); } else if (animal instanceof FlyCat) { System.out.println("Kind of animal: FlyCat"); } else if (animal instanceof Dragon) { System.out.println("Kind of animal: Dragon"); } } break; case "3": for (Animal animal : animals) { if (animal instanceof FlyCat) {
  • 9. System.out.println("Name of animal:" + animal.getName() + ", Kind of animal: FlyCat"); } else if (animal instanceof Dragon) { System.out.println("Name of animal:" + animal.getName() + ", Kind of animal: Dragon"); } } break; case "4": for (Animal animal : animals) { if (animal instanceof Dog) { System.out.println("Name of animal:" + animal.getName() + ", Kind of animal: Dog"); } else if (animal instanceof Cat) { System.out.println("Name of animal:" + animal.getName() + ", Kind of animal: Cat"); } } break; case "5": for (Animal animal : animals) { if (animal instanceof Dragon) { System.out.println("Name of animal:" + animal.getName() + ", Kind of animal: Dragon"); } } break; case "6": for (Animal animal : animals) { if (animal instanceof Dog) { System.out.println( "I am a " + animal.getAge() + "years old Dog and my name is " + animal.getName() + ". I have " + animal.getNumberOfLegs() + " legs and I can run."); } else if (animal instanceof Cat) {
  • 10. System.out.println( "I am a " + animal.getAge() + "years old Cat and my name is " + animal.getName() + ". I have " + animal.getNumberOfLegs() + " legs and I can run."); } else if (animal instanceof FlyCat) { System.out.println( "I am a " + animal.getAge() + "years old FlyCat and my name is " + animal.getName() + ". I have " + animal.getNumberOfLegs() + " legs and I can fly/run."); } else if (animal instanceof Dragon) { System.out.println( "I am a " + animal.getAge() + "years old Dragon and my name is " + animal.getName() + ". I have " + animal.getNumberOfLegs() + " legs and I can fly/run."); } } break; default: System.out.println("Wrong Entry "); break; } } } } private static String showManu() { return "Press 1 to see how many animals are in the system. " + "Press 2 to see the name and kind of each animal. " + "Press 3 to see which animals can fly. " + "Press 4 to see which animals can run. " + "Press 5 to see which animals can run AND fly. " + "Press 6 to see a description of each animal. " + "Press q to terminate the program. "; }
  • 11. }