This program needs to be written in Java in the requirements are below. Need by
ID: 3760389 • Letter: T
Question
This program needs to be written in Java in the requirements are below. Need by 11/7/15 evening. Already wrote the other related program but emergency situation and don't have time to study/write this one up with given time. Any assistance would be appreciated along with Life Saver.
Write a program that gets input for a string, then output this string character by character showing the upper case, lower case, initial case, binary, and hex values of each character.
.Get input for a string
.Print a header row per the example at the bottom.
.Loop through the string printing the following:
The lower case of each character
o The upper case of each character
o The initial case of each letter (case not changed)
o The ASCII value of each character
o The Binary representation of each character broken out in 2 sections of 4 bytes each (see example).
.Use the Integer wrapper class specifying the radix. Refer to the java docs for more info
o The Hex value of each character output in upper case
. Use the Integer wrapper class to convert to Hex
Output should be as follows:
Explanation / Answer
I solved only 4 questions. and remaining I hope to convert from ascii to binary and hex.
import java.util.Scanner;
public class CaseManipulation {
public static String toUpperCase(String inputString) {
String result = "";
for (int i = 0; i < inputString.length(); i++) {
char currentChar = inputString.charAt(i);
char currentCharToUpperCase = Character.toUpperCase(currentChar);
result = result + currentCharToUpperCase;
}
return result;
}
public static String toLowerCase(String inputString) {
String result = "";
for (int i = 0; i < inputString.length(); i++) {
char currentChar = inputString.charAt(i);
char currentCharToLowerCase = Character.toLowerCase(currentChar);
result = result + currentCharToLowerCase;
}
return result;
}
public static String toAscii(String inputString) {
byte[] bytes = text.getBytes("US-ASCII");
}
return bytes;
}
public static String toInitialCase(String inputString) {
String result = "";
if (inputString.length() == 0) {
return result;
}
char firstChar = inputString.charAt(0);
char firstCharToUpperCase = Character.toUpperCase(firstChar);
result = result + firstCharToUpperCase;
for (int i = 1; i < inputString.length(); i++) {
char currentChar = inputString.charAt(i);
char previousChar = inputString.charAt(i - 1);
if (previousChar == ' ') {
char currentCharToUpperCase = Character.toUpperCase(currentChar);
result = result + currentCharToUpperCase;
} else {
char currentCharToLowerCase = Character.toLowerCase(currentChar);
result = result + currentCharToLowerCase;
}
}
return result;
}
public static String toSentenceCase(String inputString) {
String result = "";
if (inputString.length() == 0) {
return result;
}
char firstChar = inputString.charAt(0);
char firstCharToUpperCase = Character.toUpperCase(firstChar);
result = result + firstCharToUpperCase;
boolean terminalCharacterEncountered = false;
char[] terminalCharacters = {'.', '?', '!'};
for (int i = 1; i < inputString.length(); i++) {
char currentChar = inputString.charAt(i);
if (terminalCharacterEncountered) {
if (currentChar == ' ') {
result = result + currentChar;
} else {
char currentCharToUpperCase = Character.toUpperCase(currentChar);
result = result + currentCharToUpperCase;
terminalCharacterEncountered = false;
}
} else {
char currentCharToLowerCase = Character.toLowerCase(currentChar);
result = result + currentCharToLowerCase;
}
for (int j = 0; j < terminalCharacters.length; j++) {
if (currentChar == terminalCharacters[j]) {
terminalCharacterEncountered = true;
break;
}
}
}
return result;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an input String: ");
String inputString = scanner.nextLine();
System.out.println("Upper Case: " + toUpperCase(inputString));
System.out.println("Lower Case: " + toLowerCase(inputString));
System.out.println("Toggle Case: " + toAscii(inputString));
System.out.println("Camel Case: " + toInitialCase(inputString));
System.out.println("Title Case: " + toSentenceCase(inputString));
}
}
import java.util.Scanner;
public class CaseManipulation {
public static String toUpperCase(String inputString) {
String result = "";
for (int i = 0; i < inputString.length(); i++) {
char currentChar = inputString.charAt(i);
char currentCharToUpperCase = Character.toUpperCase(currentChar);
result = result + currentCharToUpperCase;
}
return result;
}
public static String toLowerCase(String inputString) {
String result = "";
for (int i = 0; i < inputString.length(); i++) {
char currentChar = inputString.charAt(i);
char currentCharToLowerCase = Character.toLowerCase(currentChar);
result = result + currentCharToLowerCase;
}
return result;
}
public static String toAscii(String inputString) {
byte[] bytes = text.getBytes("US-ASCII");
}
return bytes;
}
public static String toInitialCase(String inputString) {
String result = "";
if (inputString.length() == 0) {
return result;
}
char firstChar = inputString.charAt(0);
char firstCharToUpperCase = Character.toUpperCase(firstChar);
result = result + firstCharToUpperCase;
for (int i = 1; i < inputString.length(); i++) {
char currentChar = inputString.charAt(i);
char previousChar = inputString.charAt(i - 1);
if (previousChar == ' ') {
char currentCharToUpperCase = Character.toUpperCase(currentChar);
result = result + currentCharToUpperCase;
} else {
char currentCharToLowerCase = Character.toLowerCase(currentChar);
result = result + currentCharToLowerCase;
}
}
return result;
}
public static String toSentenceCase(String inputString) {
String result = "";
if (inputString.length() == 0) {
return result;
}
char firstChar = inputString.charAt(0);
char firstCharToUpperCase = Character.toUpperCase(firstChar);
result = result + firstCharToUpperCase;
boolean terminalCharacterEncountered = false;
char[] terminalCharacters = {'.', '?', '!'};
for (int i = 1; i < inputString.length(); i++) {
char currentChar = inputString.charAt(i);
if (terminalCharacterEncountered) {
if (currentChar == ' ') {
result = result + currentChar;
} else {
char currentCharToUpperCase = Character.toUpperCase(currentChar);
result = result + currentCharToUpperCase;
terminalCharacterEncountered = false;
}
} else {
char currentCharToLowerCase = Character.toLowerCase(currentChar);
result = result + currentCharToLowerCase;
}
for (int j = 0; j < terminalCharacters.length; j++) {
if (currentChar == terminalCharacters[j]) {
terminalCharacterEncountered = true;
break;
}
}
}
return result;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an input String: ");
String inputString = scanner.nextLine();
System.out.println("Upper Case: " + toUpperCase(inputString));
System.out.println("Lower Case: " + toLowerCase(inputString));
System.out.println("Toggle Case: " + toAscii(inputString));
System.out.println("Camel Case: " + toInitialCase(inputString));
System.out.println("Title Case: " + toSentenceCase(inputString));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.