Question: Needing Help to Complete This Code Tester public class Tester { public static void main( String[] args ) { Dog d = new Dog ()

Needing Help to Complete This CodeNeeding Help to Complete This Code Tester public class Tester { public

Tester

public class Tester

{

public static void main( String[] args )

{

Dog d = new Dog () ;

Cat c = new Cat () ;

Bird b = new Bird() ;

Fish f = new Fish() ;

Fox x = new Fox () ;

//Dog

if( d.hasLegs() )

{

System.out.println( "Dogs have " + d.numberOfLegs() + " legs." ) ;

}

if( d.hasWings() )

{

System.out.println( "Dogs have " + d.numberOfWings() + " wings." ) ;

}

if( d.hasGills() )

{

d.breatheUnderwater() ;

System.out.println( "Dogs can breathe under water." ) ;

}

//Cat

if( c.hasLegs() )

{

System.out.println( "Cats have " + c.numberOfLegs() + " legs." ) ;

}

if( d.hasWings() )

{

System.out.println( "Cats have " + c.numberOfWings() + " wings." ) ;

}

if( c.hasGills() )

{

c.breatheUnderwater() ;

System.out.println( "Cats can breathe under water." ) ;

}

//Bird

if( b.hasLegs() )

{

System.out.println( "Birds have " + b.numberOfLegs() + " legs." ) ;

}

if( b.hasWings() )

{

System.out.println( "Birds have " + b.numberOfWings() + " wings." ) ;

}

if( b.hasGills() )

{

b.breatheUnderwater() ;

System.out.println( "Birds can breathe under water." ) ;

}

//Fish

if( f.hasLegs() )

{

System.out.println( "Fish have " + f.numberOfLegs() + " legs." ) ;

}

if( f.hasWings() )

{

System.out.println( "Fish have " + f.numberOfWings() + " wings." ) ;

}

if( f.hasGills() )

{

f.breatheUnderwater() ;

System.out.println( "Fish can breathe under water." ) ;

}

//Fox

if( x.hasLegs() )

{

System.out.println( "Foxes have " + x.numberOfLegs() + " legs." ) ;

}

if( x.hasWings() )

{

System.out.println( "Foxes have " + x.numberOfWings() + " wings." ) ;

}

if( x.hasGills() )

{

x.breatheUnderwater() ;

System.out.println( "Foxes can breathe under water." ) ;

}

System.out.println() ;

System.out.println( "Attempting things we shouldn't..." ) ;

try

{

d.numberOfWings() ;

}

catch( RuntimeException e )

{

System.out.println( e.getMessage() ) ;

}

try

{

d.breatheUnderwater() ;

}

catch( RuntimeException e )

{

System.out.println( e.getMessage() ) ;

}

try

{

c.numberOfWings() ;

}

catch( RuntimeException e )

{

System.out.println( e.getMessage() ) ;

}

try

{

c.breatheUnderwater() ;

}

catch( RuntimeException e )

{

System.out.println( e.getMessage() ) ;

}

try

{

b.breatheUnderwater() ;

}

catch( RuntimeException e )

{

System.out.println( e.getMessage() ) ;

}

try

{

f.numberOfLegs() ;

}

catch( RuntimeException e )

{

System.out.println( e.getMessage() ) ;

}

try

{

f.numberOfWings() ;

}

catch( RuntimeException e )

{

System.out.println( e.getMessage() ) ;

}

try

{

x.numberOfWings() ;

}

catch( RuntimeException e )

{

System.out.println( e.getMessage() ) ;

}

try

{

x.breatheUnderwater() ;

}

catch( RuntimeException e )

{

System.out.println( e.getMessage() ) ;

}

System.out.println() ;

System.out.println( "Dog goes " + d.getSoundMade() ) ;

System.out.println( "Cat goes " + c.getSoundMade() ) ;

System.out.println( "Bird goes " + b.getSoundMade() ) ;

System.out.println( "Fish goes " + f.getSoundMade() ) ;

System.out.println( "What does the fox say? " + x.getSoundMade() ) ;

}

}

Animal

public class Animal

{

//TODO: private member variables

public Animal( String soundMade, boolean hasLegs, boolean hasWings, boolean hasGills )

{

//TODO: copy the input parameters to private member variables

}

public String getSoundMade()

{

//TODO: return the value of the corresponding private member variable

}

public boolean hasLegs()

{

//TODO: return the value of the corresponding private member variable

}

public boolean hasWings()

{

//TODO: return the value of the corresponding private member variable

}

public boolean hasGills()

{

//TODO: return the value of the corresponding private member variable

}

public int numberOfLegs()

{

//TODO: throw a RuntimeException indicating that we don't know

}

public int numberOfWings()

{

//TODO: throw a RuntimeException indicating that we don't know

}

public void breatheUnderwater()

{

//TODO: throw a RuntimeException indicating that we don't know if the animal can

}

}

In this lab, we won't be doing any math! Our goal is to learn about inheritance, so we will create 6 classes (in addition to the provided tester class) Animal-skeleton provided Dog Cat Bird * Fish Fox Finish the Animal class as indicated in the /ITODO: comments For each of the other classes: Extend from Animal * Override the following methods: numberOfLegs, numberOfWings, and breatheUnderwater. For each animal determine if the method makes sense and if it doesn't, throw a runtime exception explaining that a cat doesn't have wings or that a dog can't breathe underwater. Since breatheUnderwater has a void retum type, for any animal that can breathe under water, you don't have to do anything in that method. * Note that in Dog, Cat, Bird, Fish, and Fox there should not be any of the following methods getSoundMade, hasLegs, hasWings, or hasGills. We want to inherit this functionality from the Animal class Once you have implemented your code correctly, running the tester class should produce this exact output Dogs have 4 leg:s Cats have 4 leg:s Birds have 2 legs. Birds have 2 wings. Fish can breatheunder water. Foxes have 4 legs. Attempting things we shouldn't... Dogs don't have wings! Dogs can't breathe under water! Cats don't have wings! Cats can't breathe under water! Birds can't breathe under water! Fish don't have legs! Fish don't have wings! Foxes don't have wings! Foxes can't breathe under water! Dog goes woof Cat goes meow Bird goes tweet Fish goes blub What does the fox say? Ring-ding-ding-ding-dingeringeding

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!