- Explore the structure of the
srcdirectory - All your classes will live within the
javadirectory
-
In the AssessmentReview class inside the
javadirectory.- Write a public static method named
cubedthat accepts an integer as an argument and returns that integer to the third power. - Write a public static method named
differencethat accepts two arguments and that works with both integers and doubles (use method overloading). Both variations of the method should return the result of subtracting the second argument from the first argument. - Write a public static method named
medianthat receives an array ofints (please use an array, not aCollection) and returns the median as adouble.- (Hint: there are examples of how to find median of an array in Java all over the internet)
- (Hint: the sort method on the Arrays class may be very helpful here)
- (Hint: make sure the median of
[1, 3, 4, 2, 6, 5, 8, 7]is4.5)
- Write a public static method named
-
Create a class named Pet inside of
java.- The class should define three fields. One of type
intnamedage, one of typebooleannamedisRescue, and one of typeStringnamedname. These fields should not be accessible outside the Pet class. - Add a constructor method that has three parameters of the types above and sets
age,isRescue, andnameproperties based on the respective parameters. - If the passed
nameargument isnull, the constructor should throw anIllegalArgumentException. - Write getters and setters for all three fields.
- The class should define three fields. One of type
-
Create a class named Cat inside of
javathat inherits from Pet.- Add a private field named
colorthat is a String. This field represents the color of each instance of Cat. - Write the constructor on Cat that has 4 parameters: the age of the cat, a boolean indicating whether the cat is a rescue, what the cat's name is, and the color of the cat. The corresponding fields of the object should be set based on the arguments passed to the constructor. (Hint: use of the super constructor may be useful here)
- Write a getter and setter on the Cat class for the
colorfield.
- Add a private field named
-
Create a class named Dog inside of
javathat also inherits from Pet.- Add a private field named
breedthat is a String. This field represents the breed of each instance of Dog. - Write the constructor on Dog that has 4 parameters: the age of the dog, a boolean indicating whether the dog is a rescue, what the dog's name is, and the breed of the dog. The corresponding fields of the object should be set based on the arguments passed to the constructor. (Hint: use of the super constructor may be useful here)
- Write a getter and setter on the Dog class for the
breedproperty.
- Add a private field named
-
Create an interface named Meowable inside of
java.- The Meowable interface should specify a public abstract method named
meowthat accepts no arguments and returns nothing. - Change your Cat class so that it implements the Meowable interface.
- The implementation of the
meowmethod on Cat class should print the following message:This is a meow!
- The Meowable interface should specify a public abstract method named
-
Create an interface named Barkable inside of
java.- The Barkable interface should specify a public abstract method named
barkthat accepts no arguments and returns nothing. - Change your Dog class so that it implements the Barkable interface.
- The implementation of the
barkmethod on the Dog class should print the following message:Bork bork!
- The Barkable interface should specify a public abstract method named
-
On your AssessmentReview class create a static method named
uppercaseCatColor.This method should:
- Receive an
ArrayListof Cat objects as a parameter. - The method should return an
ArrayListof Cat objects, where each Cat object'scolorfield is in uppercase.
Sample Input
a Cat object with a color of "black" a Cat object with a color of "orange" a Cat object with a color of "white"Sample Output
a Cat object with a color of "BLACK" a Cat object with a color of "ORANGE" a Cat object with a color of "WHITE"Hints
- Check to make sure that each Cat's
colorfield is already uppercase - If the
colorfield is not already uppercase, USE THE SETTER to change thecolorfield to uppercase.
- Receive an
-
In your Cat class create a method named
getVowelCountInColor.This method should:
- Have no parameters.
- The method returns an
intthat is the number of vowels in the cat's color. Valid vowels are a, e, i, o, and u.
Sample Input
System.out.println(cat1.getVowelCountInColor()); // cat1's color is black System.out.println(cat2.getVowelCountInColor()); // cat2's color is ORaNGE System.out.println(cat3.getVowelCountInColor()); // cat3's color is whIteSample Output
1 3 2
You can (and are encouraged to) use the classes in the test-methods package to test the code that you have written. You will need to uncomment the code in the main method of each class and run it. Make sure the output matches the example output in comments. DO NOT UNCOMMENT THE OUTPUT PORTION