Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java programming please. Array Methods In a file called ArrayExamples. java, write the following methods in a class called ArrayExamples. For each, write at

In java programming please.

image text in transcribed

Array Methods In a file called ArrayExamples. java, write the following methods in a class called ArrayExamples. For each, write at least three tests (a test is a use of checkExpect) where each of the three has a different length of array used in the input. - Write a method called joinWith that takes an array of string and a string separator, and returns a new String that contains the strings from the array separated by that separator. For example, for an array containing " a ", "b", and " c " with separator ": ", the result would be " a:b:c " (note that there's no colon at the end, just in between the elements). If the input array is empty, the method should return the empty string. If the input array contains only one string, the method should return that string. - Write a method called allTrue that takes an array of boolean and returns true if all the elements in the array are true. If the array is empty, the method produces true. - Write a method called allwithinRange that takes an array of double and two other doubles called low and high, and returns true if all of the numbers in the array are between low and high (inclusive). If the array is empty, this should produce true. You can assume that low high. - Write a class called Pair with two int fields, a and b, and include a constructor. (Add Pair at the top level, outside the ArrayExamples class). Then write a method (in Arrayexamples, not in Pair) called maxmin that takes an array of int and returns a Pair where the a field is set to the smallest integer in the array and the b is set to the largest. Assume the array has at least one element. - Write a method called earliest that takes an array of Strings and returns the String that is the earliest alphabetically (Computer scientists have a fancy name for alphabetical: lexicographic. You will need the compareTo method on Strings here. Try it out on a few examples if you're not sure what it will do!). You can assume that the array has at least one element. - Write a method called lookup that takes an array of string called keys, an array of int called values, and a String called key (three total parameters). It should find the index in keys where the argument key appears, and then return the int stored in values at that index (Hint: you may want to use . equals or . compareTo for string comparison instead of ==). If the key is not found, the method should return -1 . You can assume that lookup will always be given two arrays of the same length, and that there are no duplicate strings in keys. Example: keys contains "UCSD", "UCLA", "UCI" and values contains 36000,44900 , and 33467 . For key "UCI", it should return 33467. For key "Stanford", it should return -1. Array Methods In a file called ArrayExamples. java, write the following methods in a class called ArrayExamples. For each, write at least three tests (a test is a use of checkExpect) where each of the three has a different length of array used in the input. - Write a method called joinWith that takes an array of string and a string separator, and returns a new String that contains the strings from the array separated by that separator. For example, for an array containing " a ", "b", and " c " with separator ": ", the result would be " a:b:c " (note that there's no colon at the end, just in between the elements). If the input array is empty, the method should return the empty string. If the input array contains only one string, the method should return that string. - Write a method called allTrue that takes an array of boolean and returns true if all the elements in the array are true. If the array is empty, the method produces true. - Write a method called allwithinRange that takes an array of double and two other doubles called low and high, and returns true if all of the numbers in the array are between low and high (inclusive). If the array is empty, this should produce true. You can assume that low high. - Write a class called Pair with two int fields, a and b, and include a constructor. (Add Pair at the top level, outside the ArrayExamples class). Then write a method (in Arrayexamples, not in Pair) called maxmin that takes an array of int and returns a Pair where the a field is set to the smallest integer in the array and the b is set to the largest. Assume the array has at least one element. - Write a method called earliest that takes an array of Strings and returns the String that is the earliest alphabetically (Computer scientists have a fancy name for alphabetical: lexicographic. You will need the compareTo method on Strings here. Try it out on a few examples if you're not sure what it will do!). You can assume that the array has at least one element. - Write a method called lookup that takes an array of string called keys, an array of int called values, and a String called key (three total parameters). It should find the index in keys where the argument key appears, and then return the int stored in values at that index (Hint: you may want to use . equals or . compareTo for string comparison instead of ==). If the key is not found, the method should return -1 . You can assume that lookup will always be given two arrays of the same length, and that there are no duplicate strings in keys. Example: keys contains "UCSD", "UCLA", "UCI" and values contains 36000,44900 , and 33467 . For key "UCI", it should return 33467. For key "Stanford", it should return -1

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

10. Microsoft Corporation

Answered: 1 week ago

Question

Define the term Working Capital Gap.

Answered: 1 week ago