Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Imagine your project team is developing a Java application that will serve as an

ID: 3680940 • Letter: I

Question

Imagine your project team is developing a Java application that will serve as an educational tool to help children learn about various concepts such as vehicles, animals, sounds, etc. The application will have a need to draw various objects (e.g., animals, vehicles) on the video display as well as to rotate objects, resize objects, and play sounds that are associated with the objects. Your project manager has specified that all objects in the application should use a common interface for drawing, rotating, resizing, and playing sounds, and that these interfaces should be reusable for other application projects as well. Some future applications will need to make sounds, some will need drawing capability, some will need rotating capability, some will need resizing capability, and some will need all capabilities. A method called drawObject() will be used for drawing objects, a method called rotateObject() will be used for rotating objects, a method called resizeObject() will be used for resizing objects, and a playSound() method will be used for playing sounds.

1. Design the interface classes Drawable, Rotatable, Resizable and Sounds.

2. Develop a program called ManipulateAnimals that does the following: An Animal class will be used to model some basic characteristics of animals for the application. An animal will have a name attribute and methods to set the name and get the name. Animals can make sounds and are drawable, rotatable, and resizable. A Vehicle class will be used to model some basic characteristics of vehicles. A vehicle will have a name and an age, and methods to get/set these attributes. Vehicles can also make sounds and are drawable, rotatable, and resizable. Create a collection of 2 vehicles and 2 animals stored in the same array. Loop through the array and execute the drawObject(), rotateObject(), resizeObject(), and playSound() methods polymorphically for each element in the array. The drawObject() method should simply display the message “Drawing a Vehicle” or “Drawing an Animal”; the rotateObject() method should display the message “Rotating a Vehicle” or “Rotating an Animal”; and the playSound() method should display the message “Animal sound” or “Vehicle sound”, depending upon the type of element that is in the array. The resizeObject() method should display “Resizing a Vehicle” or “Resizing an Animal”.

Explanation / Answer

ManipulateAnimals.java


//Test program for an array with 2 Vehicles and 2 Animals
public class ManipulateAnimals
{
   public static void main(String[]args)
   {
       All[]objects = {new Vehicle("Honda",16), new Animal("Cat"), new Vehicle("Toyota",9), new Animal("Dog")};
       for(All object: objects)
       {
           object.drawObjects();
           object.playSound();
           object.resizeObject();
           object.rotateObject();
       }
   }
}

All.java
//Universal class for all interfaces
public abstract class All implements Drawable, Resizeable, Rotatable, Sounds
{
  
}

Animal.java
//Animal extending all
public class Animal extends All
{
   //Instance variable name
   private String name;
   //Constructor
   public Animal(String name)
   {
       this.name = name;
   }
   //Setters and getters
   public String getName()
   {
       return name;
   }
   public void setName(String name)
   {
       this.name = name;
   }
   //Implemented methods from All
   public void resizeObject()
   {
       System.out.println("Resizing an Animal");
   }
   public void playSound()
   {
       System.out.println("Animal sound");
   }
   public void rotateObject()
   {
       System.out.println("Rotating an Animal");
   }
   public void drawObjects()
   {
       System.out.println("Drawing an Animal");
   }
}


Drawable.java

public interface Drawable
{
   void drawObjects();
}


Resizeable.java

public interface Resizeable
{
   void resizeObject();
}

Rotatable.java

public interface Rotatable
{
   void rotateObject();
}

Sounds.java

public interface Sounds
{
   void playSound();
}

Vehicle.java
//Vehicle extending all
public class Vehicle extends All
{
   //instance variables name and age
   private String name;
   private int age;
   //Constructor
   public Vehicle(String name, int age)
   {
       this.name = name;
       this.age = age;
   }
   //Setters and getters
   public String getName()
   {
       return name;
   }
   public void setName(String name)
   {
       this.name = name;
   }
   public int getAge()
   {
       return age;
   }
   public void setAge(int age)
   {
       this.age = age;
   }
   //Implemented methods from All
   public void resizeObject()
   {
       System.out.println("Resizing an Vehicle");
   }
   public void playSound()
   {
       System.out.println("Vehicle sound");
   }
   public void rotateObject()
   {
       System.out.println("Rotating an Vehicle");
   }
   public void drawObjects()
   {
       System.out.println("Drawing an Vehicle");
   }
}


sample output

Compile and Execute Java-8 Online
Drawing an Vehicle
Vehicle sound                                                                                                                                               
Resizing an Vehicle                                                                                                                                         
Rotating an Vehicle                                                                                                                                         
Drawing an Animal                                                                                                                                           
Animal sound                                                                                                                                                
Resizing an Animal                                                                                                                                          
Rotating an Animal                                                                                                                                          
Drawing an Vehicle                                                                                                                                          
Vehicle sound                                                                                                                                               
Resizing an Vehicle                                                                                                                                         
Rotating an Vehicle                                                                                                                                         
Drawing an Animal                                                                                                                                           
Animal sound                                                                                                                                                
Resizing an Animal                                                                                                                                          
Rotating an Animal                                                                                                                                          

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote