You are on page 1of 4

Tamesis, Earvin C.

Object-Oriented Programming
BSIT – 303 07 Hands-on Activity 1

package runanimal;

/**

* @author Earvin

*/

import java.util.Scanner;

public class RunAnimal{

public static void main(String[] args){

Scanner inputUser = new Scanner(System.in);

Animal dog = new Dog();

Animal bird = new Bird();

Animal cat = new Cat();

System.out.print("Choose an animal. Press B for Bird, C for Cat, or D for Dog: ");

String Chosen = inputUser.nextLine();

if(Chosen.equalsIgnoreCase("B")){

bird.eat();

bird.sleep();

bird.makeSound();

else if(Chosen.equalsIgnoreCase("C")){

cat.eat();
cat.sleep();

cat.makeSound();

else if(Chosen.equalsIgnoreCase("D")){

dog.eat();

dog.sleep();

dog.makeSound();

else {

System.out.println("Wrong Input!");

abstract class Animal{

abstract void eat();

abstract void sleep();

abstract void makeSound();

class Bird extends Animal{

void eat() {

System.out.print("Birds love to eat seeds ");

void sleep() {

System.out.println("and sleep for 10 to 12 hours.");

void makeSound() {

System.out.println("Tweet tweet!");
}

class Cat extends Animal{

void eat() {

System.out.print("Cats love to eat friskies ");

void sleep() {

System.out.println("and sleep for 10 to 12 hours.");

void makeSound() {

System.out.println("Meow meow!");

class Dog extends Animal{

void eat() {

System.out.print("Dogs love to eat beefs ");

void sleep() {

System.out.println("and sleep for 10 to 12 hours.");

void makeSound() {

System.out.println("Arf arf!");

}
OUTPUT:

You might also like