Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Using JAVA and one single java file please DESCRIPTION Write programs for challenges 1 and 2 at the end of the chapter on Generics.

Program Using JAVA and one single java file please

image text in transcribed

image text in transcribed

DESCRIPTION Write programs for challenges 1 and 2 at the end of the chapter on Generics. PARTI 1) Write a generic class named MyList, with a type parameter T. The type parameter I should be constrained to an upper bound: the Number class. The class should have as a field an ArrayList of T. Write a public method named add, which accepts a parameter of type T. When an argument is passed to the method, it is added to the ArrayList. Write two other methods, largest and smallest, which return the largest and smallest values in the ArrayList. Create two isntances of the above class like shown below and insert bunch of Number into MyList of type Number and bunch of Double into Mylist of type Double. Then call largest() and smallest() methods in each of the above class. You can insert the following integer numbers into the list 2 5 -13 11 12 And insert the following double numbers: 27.3 5.7 -23.9 1.11 5.12 PART 2 2] Modify the MyList class that you wrote for Programming challenge l(above) so the type parameter T should accept any type that implements the Comparable interface. Test the class in a program that creates one instance of MyList to store Integers, and another instance to store Strings. Input two numbers from the user and insert them into the first instance of Modified MyList. Input name and City and insert the two strings into the second instance of modified MyList class. Then display the contents of the the two instances. Here is the sameple Input/output The Java file must be named as : Genericsl.java PART 1 The Integer largest 12 The Integer smallest: -13 The Double largest: 27.3 The Double smallest: -23.9 PART 2 Please enter a number: 20 Please another number: 30 Please enter your name: John Please enter your City: Los Angeles First number is 20 First number is 30 Name is: John City is: Los Angeles

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago