Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Answer this worksheet, This is for an Advaned Java Course! Lesson Objectives: Create a custom generic class Use the type interface diamond to create

Please Answer this worksheet, This is for an Advaned Java Course!

Lesson Objectives: Create a custom generic class Use the type interface diamond to create an object Use generic methods Use wildcards Use enumerated types

Vocabulary: Identify the vocabulary word for each definition below.

This is a special type of class that associates one or more non-specified Java types.----------
A type interface diamond is what 2 characters----------
A datatype that contains a fixed set of constants---------

Try It/Solve It: 1. Create a generic class called Cuboid that will store the three dimensions of a cuboid. Add methods to set and get the length, breadth and Height. Add a method public String toString() that will return all of the dimensions. The type of the dimensions will be decided at construction of the cuboid instance. Example: Cuboid c1 = new Cuboid<>(); Cuboid c1 = new Cuboid<>();

2. Modify your generic class Cuboid so that it only accepts Numbers. Add a method with the following definition and complete its body. Hint: Look at the method doubleValue() in the Number class. public double getVolume(){ }

3. A calendar expert, Mr. Dayes, wishes to make a class that will be used to initialize and store the days of the week. Would it be useful for him to use an enum type? Why or why not? 4. Create a generic class that stores a Key and a Value and call it Map. This will have one method called toString that will return a string that shows the key and the value. The key and the value can be of any type. Test your class by adding the following three years and an associated iconic car to a separate instance of each. You will end up with three instances of Map storing the following data:

Year Car
1989 GT-R
1969 Capri
1953 Corvette C1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions