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

These problems have me stumped. All three of these question are created in one j

ID: 3887476 • Letter: T

Question

These problems have me stumped. All three of these question are created in one java project. Can someone show me their code please. I am using Eclipse (Java) to code. Thanks! 2. (10 points) Write a program, SentenceAnalysis, that asks the user to enter a sentence. Then write a method that counts the number of whitespace characters in a String. Use the method on the sentence entered by the user to count the number of whitespaces. The method signature is: public static int countwhitespaces (String sentence) User input: I can't go back to yesterday because I was a different person then. Output: 12 3. (25 points) To the class SentenceAnalysis in the previous problem add a method that checks if a string consist only of digits: public static boolean isNumeric(String sentence) the method returns true if and only if all the characters in the String are digits. 4. (30 points) To the class SentenceAnalysis in the previous problem add a method that accepts as input parameter a String and returns the string with all whitespaces removed: public static String removewhitespaces (String text) Note: You need to use for loops and you are NOT allowed to use the method replace.

Explanation / Answer

// SentenceAnalysis.java
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class SentenceAnalysis
{
public static int countWhiteSpaces(String sentence)
{
int count = 0;
for (int i = 0; i < sentence.length(); i++ )
{
char c = sentence.charAt(i);
if(c == ' ')
count++;
}

return count;

}


public static boolean isNumeric(String sentence)
{
  
for (int i = 0; i < sentence.length(); i++ )
{
char c = sentence.charAt(i);
if(c < '0' || c > '9')
return false;
}

return true;

}

public static String removeWhiteSpaces(String text)
{
String result = "";
for (int i = 0; i < text.length(); i++ )
{
char c = text.charAt(i);
if(c != ' ')
result = result + c;
}

return result;

}

public static void main(String args[]) throws IOException
{
Scanner scan = new Scanner(System.in);
  
System.out.print("Enter a sentence: ");
String sentence = scan.nextLine();
  
System.out.println(countWhiteSpaces(sentence));
System.out.println(isNumeric(sentence));
System.out.println(removeWhiteSpaces(sentence));

}
}

/*
output:

Enter a sentence: I am not a good person
5
false
Iamnotagoodperson

*/

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