Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1... Write a Java method with a one-character parameter that returns the paramet

ID: 3605848 • Letter: 1

Question

1... Write a Java method with a one-character parameter that returns the parameter shifted one letter to the right ('A' becomes 'B', 'B' becomes 'C', etc.) if it is a capital letter; otherwise it returns the original parameter value.

2... Write a Java method that has a single parameter for an array of doubles and returns another array of doubles with the same length and has each element divided by 2.0.

3... Write a Java method that will search the array d for the value in the variable t. Use d and t as parameters. If the value of t is not found, the method returns -1. If the value of t is found, the method returns the first value of the subscript, sub, such that d[sub] has the same value as t. Data types:

char [] d; int sub; char t;

Explanation / Answer

MethodsCheck.java

import java.util.Arrays;

public class MethodsCheck {

public static void main(String[] args) {

System.out.println(nextChar('A'));

System.out.println(Arrays.toString(halfArray(new double[]{1,2,3,4,5,6,7,8,9,10})));

System.out.println(find(new char[]{'a','b','c','e','d','f'}, 'e'));

}

public static char nextChar(char ch) {

if(ch >= 'A' && ch <='B') {

ch = (char)((int)ch + 1);

}

return ch;

}

public static double[] halfArray(double d[]) {

double arr[] = new double[d.length];

for(int i=0;i<d.length;i++) {

arr[i] = d[i]/2.0;

}

return arr;

}

public static int find(char d[], char t) {

int sub = -1;

for(int i=0;i<d.length;i++) {

if(d[i] == t) {

sub = i;

break;

}

}

return sub;

}

}

Output:

B
[0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]
3

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote