Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions Create a project called P7 and a class named P7 in a file called P7.java, then follow the instructions below exactly : Write a

Instructions

Create a project called P7 and a class named P7 in a file called P7.java, then follow the instructions below exactly:

Write a method named createIntegers that allocates, initializes, and returns an array of integers with the following entries: 16, 21, 34, 49, 55, 60, 72, 83, 101. The method has no parameters and returns an array of 9 integers.

Write a method named createDoubles that builds an array of floating point values that represent the squares of the numbers from 10.0 to 13.0, in steps of 0.5, inclusive of both boundaries. The method has no parameters and returns an array of doubles. There are exactly 7 numbers in this array.

Write a method named createStrings that takes a String as an input parameter, and returns an array of string with 4 elements. The first element is the original string passed in, the second element is the same string converted to uppercase, the third element is the same string converted to lowercase, and the fourth element is the same string with the first character removed.

Write a method named createChars that extracts the characters from a string and builds an array with them. The method takes a parameter of type String and returns an array of characters. Hint: the size of this array is very easy to determine!

Note:Each of the arrays must be allocated to be exactly the correct size needed for the contents specified above.

Write a method called sumArray that takes an array of integers as a parameter, and returns an integer equal to the sum of all elements in the array.

Write a method called findLargest that takes an array of doubles as a parameter, and returns a double equal to the largest element in the array.

Write a method called charFrequency that takes an array of strings and a single character as parameters. The method should iterate the array, counting instances of the character passed in. For example, if the array is ["Hello", "There"] and we are asked to count the character 'e', the return value will be three. If the character is not found in any of the elements in the array, the return value should be zero.

Write a method called translateChars that takes an array of characters and returns an array of integers with the values that correspond to each element of the character array. For example, the character 'A' will be translated to 65, the character '0' will be translated to 48, and the character '%' will be translated to 37. The integer array returned should be of the same size as the array of characters passed in.

Add a main method with the usual signature that instantiates the P7 class and tests its methods as follows:

 public static void main(String[] args) { // Create arrays int[] integerArray = createIntegers(); System.out.println(Arrays.toString(integerArray)); double[] doubleArray = createDoubles(); System.out.println(Arrays.toString(doubleArray)); String[] stringArray = createStrings("Hello There"); System.out.println(Arrays.toString(stringArray)); char[] charArray = createChars("Java1234!&"); System.out.println(Arrays.toString(charArray)); // Test processing System.out.println("Sum of integer array = " + sumArray(integerArray)); System.out.println("Largest of double array = " + findLargest(doubleArray)); System.out.println("Frequency of 'e' = " + charFrequency(stringArray, 'e')); System.out.println("Translated characters = " + Arrays.toString(translateChars(charArray)));

Testing

Based on the provided test code in the main method, you should see the following output if your methods are correct:

[16, 21, 34, 49, 55, 60, 72, 83, 101] [100.0, 110.25, 121.0, 132.25, 144.0, 156.25, 169.0] [Hello There, HELLO THERE, hello there, ello There] [J, a, v, a, 1, 2, 3, 4, !, &] Sum of integer array = 491 Largest of double array = 169.0 Frequency of 'e' = 9 Translated characters = [74, 97, 118, 97, 49, 50, 51, 52, 33, 38]

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago