1. Find the error in the following class: public class FindTheError { public int square(int number) { return number * number; } public double square(int number) { return number * number; } }...


1. Find the error in the following class:


public class FindTheError


{



public int square(int number)



{



return number * number;



}



public double square(int number)



{



return number * number;



}


}


2. Design a class named Pet, which should have the following fields:


• name. The name field holds the name of a pet.


• animal. The animal field holds the type of animal that a pet is. Example values are “Dog”, “Cat”, and “Bird”.


• age. The age field holds the pet’s age.



The Pet class should also have the following methods:


• setName. The setName method stores a value in the name field.


• setAnimal. The setAnimal method stores a value in the animal field.


• setAge. The setAge method stores a value in the age field.


• getName. The getName method returns the value of the name field.


• getAnimal. The getAnimal method returns the value of the animal field.


•getAge. The getAge method returns the value of the age field.


a. Draw a UML diagram of the class. Be sure to include notation showing each field


and method’s access specification and data type. Also include notation showing any method parameters and their data types.


b. Write the Java code for the Pet class.



Dec 11, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here