Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1: Overloading Methods with Arrays Assignment: Using your knowledge of the String and Array objects, you will design and implement overloaded versions of methods

image text in transcribedimage text in transcribed
Part 1: Overloading Methods with Arrays Assignment: Using your knowledge of the String and Array objects, you will design and implement overloaded versions of methods found in the String class to apply them to other array types. Your program should include a main method that demonstrates the functionality of both versions of all overloaded methods. This code can be relatively simple, as long as it invokes every single method in a meaningful way. 1. equals(): When used with Strings, equalsO returns a hoolean (true or false) if and only if the two strings in question are exactly equal. To implement and overload this method to function for arrays, the functionality will be similar. For any array type, you should rst check that the length of listl and list2 are equal, then check that each element of listl matches the corresponding element (at the same index) in list2. You should create two versions of equals () : one to accept and compare two integer arrays, the other to accept and compare two two-dimensional integer arrays. Suggested method headers are included here: 1. public static boolean equals (int listl, int list2) 2. public static boolean equals (int listl, int list-.2) 2. join(): This method will be based on concat ()within the String Class. The concatO method returns either a character or integer (list3) that is simply listl with list2 appended to the end of it. To implement and overload this method to function for arrays, the functionality will be similar. For either array type, you should create a list to return that is the same type as the parameters (list3). You should create two versions of j oin () : one to join two integer arrays, and the other to join two two-dimensional integer arrays. Return types must match parameter types. When joining twodimensional arrays, you will append the arrays at each row from 1ist2 to the end of listl. Suggested method headers are included here: 1. public static int join (int listl, int listZ) 2. public static int join (int [1 [1 listl, int [1 [1 list2) 3. Notes: indexOf () : When used with Strings, indexOf () takes in character value and a String object and returns the index of the rst occurrence of value in the String (if it is there). If value is not found in the String, then indexOf () returns 1. You should overload indexOf () to search arrays of integers list as well as a two-dimensional array of integers. For the one-dimensional arrays, indexOf () will return an int. For the two-dimensional arrays, indexOf () will return an array of length 2, where each element corresponds to the row and column index values where value was found (if it was found) 1. public static int indexOf (int list, int value) 2. public static int indexOf (int list, int value) elementAt () : This method is based off of the charAt () method in String. When called, this method returns the integer found at the index passed in as a parameter. To overload this function for different types of arrays, you will create elementAt () to accept either a one- or two-dimensional array of ints as well as the index. 1. public static int elementAt (int list, int index) 2. public static int elementAt (int [1 list, int index) Be sure to follow good programming practices (incl. methods) Your main method for this code should be simple enough to test each version of your methods (and that is it). There is no requirement to get user input here at all

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions