

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Class: Intermediate Java Programming; Subject: Computer Programming; University: Florida International University; Term: Summer 2007;
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!


th
public abstract class Animal { private String id;
public Animal ( ){ id = ""; }
public Animal ( String id ){ this.id = id; }
public void setId ( String id ){ this.id = id; }
public String getId ( ){ return id; }
public abstract void eat ( );
public abstract void whoAmI ( ); }
public interface Whistler { int LOUD = 10; int LOW = 0;
void whistle ( ); }
public interface Flyable {
void fly ( );
void canFly ( boolean can );
boolean isAbleToFly ( ); }
public class Parrot extends Animal implements Whistler , Flyable { private int intensity; private boolean flies; public Parrot ( ){ intensity = LOW; flies = true; } public Parrot ( int intensity, String id ){ super(id); this.intensity = intensity; flies = true; } public Parrot ( boolean flies, int intensity, String id ){ super(id); this.intensity = intensity; this.flies = flies; } public void setIntensity ( int intensity ){ this.intensity = intensity; } public int getIntensity ( ){ return intensity; } public void eat ( ){ System.out.println( "Parrot " +getId()+ " eating." ); } public void whoAmI ( ){ System.out.println( "I'm parrot " +getId()+ "." ); } public void whistle ( ){ String intStr = "loudly" ; if ( intensity < LOUD ) intStr = "lowly" ; System.out.println( "Parrot " +getId()+ " whistling " +intStr+ "." ); } public void fly ( ){ if ( isAbleToFly() ) System.out.println( "Parrot " +getId()+ " is flying." ); else System.out.println( "Parrot " +getId()+ " wished it could fly." ); } public void canFly ( boolean can ){ flies = can; } public boolean isAbleToFly ( ){ return flies; } }