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

Create a function called makealph that receives three string parameters called f

ID: 3843374 • Letter: C

Question

Create a function called makealph that receives three string parameters called first, middle, and last and will return a string produced from those input parameters. The new string will consist of 2 parts of the original string joined together in alphabetical order. The 2 parts to be joined are these:

- the string that is closest to the beginning of the alphabet

- the string that is closest to the end of the alphabet

Remember that lowercase letters alphabetize AFTER capitals since they have larger ASCII codes, so they are considered closer to the end of the alphabet.

For example, if the original string was "Wy Lee coyote," then first is "Wy", middle is "Lee", and last is "coyote". The function will determine that the string closest to the beginning of the alphabet is "Lee", and the string closest to the end of the alphabet is "coyote". It will join these two strings as "Lee coyote" in the new string and will return this new string to main.

Explanation / Answer

Find the program below:

import java.util.*;

import java.lang.Math;

public class Alpha{

String makealph(String first, String middle, String last){
String produced = null;
char fcharacter = first.charAt(0);
int firstascii = (int) fcharacter;
char mcharacter = middle.charAt(0);
int middleascii = (int) mcharacter;
char lcharacter = last.charAt(0);
int lastascii = (int) lcharacter;

int max = Math.max(Math.max(firstascii ,middleascii),lastascii ); //To find the maximum ascii value charactor
String fout = null;
String sout = null;
if(max == firstascii){
   fout = first;
}else if(max == middleascii){
   fout = middle;
}else if(max == lastascii){
   fout = last;
}
int min = Math.min(Math.min(firstascii,middleascii),lastascii); //to find the minimum ascii value character
if(min == firstascii){
   sout = first;
}else if(min == middleascii){
   sout = middle;
}else if(min == lastascii){
   sout = last;
}
produced = String.join(" ",fout, sout);
return produced; //This string will return the produced string based on our expectation to main function.
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote