Question: This assignment is to work with new objects associated with mammals. You are provided classes & sub classes to begin with, attached to the assignment

This assignment is to work with new objects associated with mammals. You are provided classes & sub classes to begin with, attached to the assignment (MainWeek5.java, Mammal.java, Cat.java, and Dog.java.

Create the following Mammal sub-classes (in the package week5):

-Cow (in a file called Cow.java)

-Sheep (in a file called Sheep.java)

-Fox (in a file called Fox.java)

Also, create a sub-class from Dog, called

-Chihuahua (in a file called Chihuahua.java)

There is also a method called trySwimming in the main method to complete.

When these particular mammals speak, they say the following:

Cow: Moo

Sheep: Baa

Chihuahua: Yip

Now, since we all want to know what the fox says, make the Speak method for the fox take user input after prompted. Prompt the user What does the fox say?, and output whatever they type, followed by an exclamation point (!).

Also, for the Cow class, create a special method called Milk, which returns a random integer between 2 and 5. This number will be used to represent the number of gallons of milk a Cow can produce.

The Main class also includes a private method called trySwimming. trySwimming takes a Mammal object as an input parameter. For the trySwimming method:

-If the Mammal is a Dog (could be a Chihuahua) or Fox, then output the term Splash, paddle paddle then Speak once.

- If the Mammal is a Cat, output hiss (not Speak).

-If the Mammal is a Cow or Sheep, then simply call Speak once.

The code for Mammal.java, Cat.java, Dog.java, and starting code for MainWeek5.java are provided. Note. MainWeek5 code will not work until the new classes are added:

package week5;

public abstract class Mammal{

public abstract void Speak();

}

package week5;

public class Cat extends Mammal{

public void Speak(){

System.out.println("Meow");

}

}

package week5;

public class Dog extends Mammal{

public void Speak(){

System.out.println("Woof");

}

}

package week5;

public class MainWeek5{

public static void main(String[] args){

//Main Method... DO NOT CHANGE THIS METHOD

Cat kitty = new Cat();

Dog puppy = new Dog();

Chihuahua buffy = new Chihuahua();

Cow bessie = new Cow();

Sheep aSheep = new Sheep();

Fox littleFox = new Fox();

kitty.Speak();

puppy.Speak();

buffy.Speak();

bessie.Speak();

aSheep.Speak();

littleFox.Speak();

System.out.println("The cow produces " + bessie.Milk() + " Gallons today.");

trySwimming(puppy);

trySwimming(buffy);

trySwimming(kitty);

trySwimming(bessie);

trySwimming(aSheep);

trySwimming(littleFox);

}

private static void trySwimming(Mammal currentMammal){

//Insert swimming code here.

}

}

After completing the requirements, the output when running MainWeek5 should look like this (assuming user input prompt responses are the same):

Meow

Woof

Yip

Moo

Baa

What does the fox say? Ring-ding-ding-ding-dingeringeding

Ring-ding-ding-ding-dingeringeding!

The cow produces 3 Gallons today.

Splash, paddle paddle Woof

Splash, paddle paddle Yip

hiss

Moo

Baa

Splash, paddle paddle What does the fox say? Wa-pa-pa-pa-pa-pa-pow

Wa-pa-pa-pa-pa-pa-pow!

Press any key to continue . . .

Submit in the usual manner, ONLY the following code files:

Cow.java

Sheep.java

Chihuahua.java

Fox.java

Updated MainWeek5.java code with trySwimming method code

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!