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

Problem 2-Write a program. ChangeTense.java Create a program that allows users t

ID: 3799805 • Letter: P

Question

Problem 2-Write a program. ChangeTense.java Create a program that allows users to enter a sentence in either past or present or tense and get back the other tense. They should also include today for present tense and yesterday for past tense, For example, if a user enters: eat food today. They should get back: I ate food yesterday. Make sure ALL the following inputs are accounted for (meaning if any of these inputs are used, the program is expected to work correctly): eat food today. late food yesterday. I walk today. Iwalked yesterday. She flies today. She flew yesterday. He dances today. He danced yesterday. We cook today. We cooked yesterday. They bake today. They baked yesterday.

Explanation / Answer


import java.util.Arrays;
import java.util.Scanner;

public class PresentToPast {

   public static void main(String[] args) {

       @SuppressWarnings("resource")
       Scanner scanner = new Scanner(System.in);

       System.out.println("please enter the sentence to convert simplepast");

       String sentence = scanner.nextLine();

       String[] words = sentence.split("\s+");
      
       String ConvertedVerb = NLP_verbPastTense(words[1]);
       words[1] = ConvertedVerb;

       StringBuilder builder = new StringBuilder();
      
       for (String word : words) {

           if (word.trim().equals("today".trim())) {
               word = "yesterday";
           }

           builder.append(" " + word);
       }

       System.out.println("the converted sentence is :" + builder.toString());
       }

   public static String NLP_verbPastTense(String action) {

       /*
       *
       * e becomes ed y becomes i then add
       */

       Character exceptvowels[] = { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k',
               'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'x', 'y', 'z' };
       Character vowels[] = { 'a', 'e', 'i', 'o', 'u' };

       String result = action;// action means verb

       if (action.length() == 0) {
           return "";
       }

       if (action.charAt(action.length() - 1) == 'e') {
           result = action + "d";
       } else if (Arrays.asList(exceptvowels).contains(
               action.charAt(action.length() - 2))
               && action.charAt(action.length() - 1) == 'y') {
           result = action.substring(0, action.length() - 1) + "ied";
       } else if (action.length() > 2
               && !Arrays.asList(vowels).contains(
                       action.charAt(action.length() - 3))
               && Arrays.asList(vowels).contains(
                       action.charAt(action.length() - 2))
               && (Arrays.asList(exceptvowels).contains(
                       action.charAt(action.length() - 1))
                       && action.charAt(action.length() - 1) != 'w' && action
                       .charAt(action.length() - 1) != 'y')) {
           result = action + action.charAt(action.length() - 1) + "ed";
       } else {
           result = action + "ed";
       }

       return result;

   }
}

output

please enter the sentence to convert simplepast
we cook today
the converted sentence is : we cooked yesterday
please enter the sentence to convert simplepast
they bake today
the converted sentence is : they baked yesterday

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