Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pleazzzzzzzzze do it fast. 1. Get familiar with generic types Given the following class public class MyPair public final Ist; public final u Snd: public

Pleazzzzzzzzze do it fast.

image text in transcribed

1. Get familiar with generic types Given the following class public class MyPair public final Ist; public final u Snd: public MyPair (T Est, U snd) this.Est - f3t; this. Snd = sna: } pubiie String toString() { return" (" + Ft + " 1 + Snd+")"; a. In a new source file, write a Java program that includes this declaration and a class with an empty Main method. Compile it to check that the program is well-formed b. Declare a variable of type MyPair and create some values, for instance new MyPair ("Anders", 13), and assign them to the variable. c Declare a variable of type MyPair. Create a value such as new MyPair("Phoenix", 39.7) and assign it to the variable d. Can you assign a value of type MyPair to a variable of type MyPair? Should this be allowed? e Declare a variable grades of type MyPair[). create an array of length 5 with element type Mypair and assign it to the variable. Create a few MyPairs and store them into grades[0]. Erades[1] and grades[21 f. Use the foreach statement to iterate over grades and print all its elements. What are the values of those array elements you did not assign anything to? & Declare a variable appointment of type MyPair, String> and create a value of this type and assign it to the variable. What is the type of appointment.Fot. Sna? This shows that a type-argument may itself be a constructed type. h. Declare a method Swap() in MyPair that returns a new value of type MyPair in which the components have been swapped

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

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Explain in detail how the Mughal Empire was established in India

Answered: 1 week ago

Question

Problem: Evaluate the integral: I - -[ze dx

Answered: 1 week ago

Question

Problem: Evaluate the integral: I = 1- 1 dx 9

Answered: 1 week ago