Question

USING JAVA You will be given a sentence and you will need to correct to proper...

USING JAVA

You will be given a sentence and you will need to correct to proper sentence.
  - Make sure first word and first letter is capitalized.
  - Make sure sentence ends with period.
  
  Create a class there should be NO field level variables
  In that class create a method that takes the sentence and returns corrected sentence.
  Create another method (only used by created class) that makes sure and corrects that first work first letter is capitalized
 
public class Sentence {
        public String execute(String words) {
               return null;
        }       
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*******************************Sentence.java****************/

public class Sentence {

   public char correctFirstLetter(char c) {

       if (Character.isUpperCase(c)) {

           return c;
       } else {

           return Character.toUpperCase(c);
       }
   }

   public String correctLowerAfterFirstChar(String remainingWord) {

       return remainingWord.toLowerCase();
   }

   public String correctEnd(String word) {

       if (word.endsWith(".")) {

           return word;
       } else {

           return word + ".";
       }
   }
}

/***************SentenceTest.java****************/


public class TestSentence {

   public static void main(String[] args) {

       String corrected = execute("heLlo woRlD.");
   System.out.println(corrected);
   }

   public static String execute(String word) {

       Sentence sentence = new Sentence();
       char capitalFirst = sentence.correctFirstLetter(word.charAt(0));

       String correctLower = sentence.correctLowerAfterFirstChar(word.substring(1, word.length()));

       String correctEnd = sentence.correctEnd(correctLower);

       return capitalFirst + correctEnd;
   }
}

/******************output*****************/

Hello world.

Please let me know if you have any doubt or modify the answer, Thanks:)

Add a comment
Know the answer?
Add Answer to:
USING JAVA You will be given a sentence and you will need to correct to proper...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according...

    I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the...

  • Can you please produce the Java code that solves this non-assessed homework problem? I'm very new...

    Can you please produce the Java code that solves this non-assessed homework problem? I'm very new to Java and Object-Oriented Programming and I have no idea how to construct the logic for this code. PROBLEM: "In this exercise, you will build a program that determines the validity of a select few simple English sentences, according to rules detailed below. A sentence will be represented as an array of words, which you will create as a static nested class `Word`. `Word`...

  • Need the answers to these RECURSIVE practice problems using Linked Lists in JAVA . Thank you. Complete the Link cl...

    Need the answers to these RECURSIVE practice problems using Linked Lists in JAVA . Thank you. Complete the Link class by writing methods described below. Do not use loops, or create any more methods (other than those specified), class or instance variables. public class Link private Link next; /null if this is the last link private int value; public Link(Link n, int v) nextn valuev; Do not use loops, or create any more methods (other than those specified), class or...

  • Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal...

    Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal (POJo, JavaBean) class to represent, i. e. model, varieties of green beans (also known as string beans or snap beans). Following the steps shown in "Assignment: Tutorial on Creating Classes in IntelliJ", create the class in a file of its own in the same package as class Main. Name the class an appropriate name. The class must have (a) private field variables of appropriate...

  • 26-ary tree for spell checker in JAVA You are asked to write some functionalities for a...

    26-ary tree for spell checker in JAVA You are asked to write some functionalities for a spelling checker inside Tree.java that has at least the following methods: /*Adds a word to a spelling checker’s collection of correctly spelled words*/ void add(String word) /*Returns true if the given word is spelled correctly*/ boolean check(String word) /*Returns back all words in the tree in alphabetical order*/ public String getDictionaryInAlphabeticalOrder() Store the collection of correctly spelled words in a 26-ary tree. The number...

  • Consider the following Java interface. public interface Converter<A, B> { B convert(A xs); } (a) Write...

    Consider the following Java interface. public interface Converter<A, B> { B convert(A xs); } (a) Write a default method convertAll in the interface Converter that takes ArrayList<A> xs as input and returns a new ArrayList<B>. If the ArrayList xs is [x1, : : :, xn], the method returns [convert(x1), : : :, convert(xn)]. In your method you may assume that xs is never null. If one of the calls to convert throws an exception, your method should not catch it....

  • create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines....

    create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...

  • Write the Java code for the class WordCruncher. Include the following members:

    **IN JAVAAssignment 10.1 [95 points]The WordCruncher classWrite the Java code for the class WordCruncher. Include the following members:A default constructor that sets the instance variable 'word' to the string "default".A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make...

  • This is a java program that runs on the Eclipse. Java Programming 2-1: Java Class Design...

    This is a java program that runs on the Eclipse. Java Programming 2-1: Java Class Design Interfaces Practice Activities Lesson objectives: Model business problems using Java classes Make classes immutable User Interfaces Vocabulary: Identify the vocabulary word for each definition below. A specialized method that creates an instance of a class. A keyword that qualifies a variable as a constant and prevents a method from being overridden in a subclass. A class that it can't be overridden by a subclass,...

  • Must be in Java. Please show step by step process with proper explanation and comments. Please...

    Must be in Java. Please show step by step process with proper explanation and comments. Please maintain proper indentation. CODE PROVIDED: Doctor.java HospitalDoctor.java Q1Runner.java import java.util.Scanner; public class Q1Runner { public static void main(String[] args) { Scanner kb = new Scanner(System.in);               // Do your work here        } } You are asked to create the starting point of a system to represent several types of medical doctors. You decided to implement two classes: a superclass...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT