0% found this document useful (0 votes)
26 views8 pages

Practical Macasaet

Uploaded by

Kevin Macasaet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views8 pages

Practical Macasaet

Uploaded by

Kevin Macasaet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

PRACTICAL MIDTERM EXAM

SOURCE CODES:

class Animal

protected int age;

protected boolean gender;

protected boolean mammal;

public Animal()

age=0;

gender=false;

mammal=false;

public void SetAge( int n) { age = n; }


public void SetGenderMale() { gender=false; }

public void SetGenderFemale() { gender=true; }

public void SetMammal() { mammal = true; }

public void NotMammal() { mammal = false; }

public int GetAge() { return(age); }

public boolean GetGender() { return(gender); }

public boolean IsMale() { return(gender==false); }

public boolean IsFemale() { return(gender==true); }

public boolean IsMammal() { return(mammal==true); }

}
class Duck extends Animal

protected String beakColor;

public Duck()

beakColor="yellow";

public void SetBeakColor(String colorStr)

beakColor = new String(colorStr);

public void swim()

System.out.println("Duck is swimming...");

}
public void Quack()

System.out.println("Quack quack...\n");

class Fish extends Animal

protected int size;

protected boolean canEat;

public void SetSize(int n) { size=n; }

public void SetCanEat() { canEat=true; }

public void SetCannotEat() { canEat=false; }


public int GetSize() { return(size); }

public boolean CanEat() { return(canEat==true); }

public void swim()

System.out.println("Fish is swimming...\n ");

class Zebra extends Animal

protected boolean is_wild;


public void SetWild() { is_wild=true; }

public void SetTame() { is_wild=false; }

public boolean IsWild() { return(is_wild==true); }

public void run()

System.out.println("Zebra is running...\n");

class MyZoo

{
public static void main(String args[])

Duck duck = new Duck();

Zebra zebra = new Zebra();

Fish fish = new Fish();

duck.swim();

duck.Quack();

zebra.run();

fish.swim();

duck.SetAge(1);

fish.SetAge(2);

zebra.SetAge(4);
System.out.println("\nDuck age = " + duck.GetAge() + "\nFish age: "+ fish.GetAge() + " \nZebra age =
" + zebra.GetAge());

You might also like