Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey I need help in this program. short of time 17. For this problem you must define a simple generic interface PairInterface, and two implementations

Hey I need help in this program. short of time

image text in transcribed

17. For this problem you must define a simple generic interface PairInterface, and two implementations of the interface, BasicPair and ArrayPair. a. Define a Java interface named PairInterface. A class that implements this interface allows creation of an object that holds a "pair" of objects of a speci- fied typethese are referred to as the "first" object and the "second" object of the pair. We assume that classes implementing PairInterface provide constructors that accept as arguments the values of the pair of objects. The PairInterface interface should require both setters and getters for the first and second objects. The actual type of the objects in the pair is specified when the PairInterface object is instantiated. Therefore, both the PairInter- face interface and the classes that implement it should be generic. Suppose a class named BasicPair implements the PairInterface interface. A simple sample application that uses Basic Pair is shown here. Its output would be "apple orange." public class Sample public static void main (String[] args) PairInterface my Pair - new BasicPair ("apple", "peach"); System.out.print(my Pair.getFirst() + " "); my Pair.setSecond ("orange"); System.out.println(my Pair.getSecond()); C. Create a class called ArrayPair that implements the PairInterface inter- face. This class should use an array10 of size 2 to represent the two objects of the pair. Create a test driver application that demonstrates that the Array Pair class works correctly

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

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions