Background: A sentence is a sequence of words with two possible structures: Namel and Name2 Verb Object. Namel or Name2
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Background: A sentence is a sequence of words with two possible structures: Namel and Name2 Verb Object. Namel or Name2
Please code this in the Java language. Any help would be greatly
appreciated.
Background: A sentence is a sequence of words with two possible structures: Namel and Name2 Verb Object. Namel or Name2 Verb Object. Where Namel and Name2 can be any word from the text file names.txt, Verb can be any verb from verbs.txt, and Object is any line from things.txt. Example of acceptable sentences: Amari and Riley will bake 1 suit. Riley or Jilali deserve rug. (Note that Jilali isn't in names.txt but because of the connector or, we accept the sentence) Riley and Felix afforded 2 Knee PROTECTION gears. Example of non-acceptable sentences Riley and Jilali deserve rug. (Jilali isn't in names.txt) zane crashed Trumpet. (two names must be in the sentence) Riley and Zane crash Trumpet (sentences must end with a dot) Max and max afford iphone. (no duplication of a name is allowed)
The goal of this HW is to: 1) generate random sentences, and 2) check whether a given sentence is acceptable. Coding requirements Beside the text files mentioned above, you are provided with the sentenceTester and SentenceGenerator classes (both in Sentence Tester.java). You only work on the sentenceGenerator class. The sentenceTester class and the method signatures provided cannot be changed. //import whatever package.class needed... public class Sentence Tester { public static void main(String [] args) { SentenceGenerator my Sentence = new SentenceGenerator(); mySentence.decomposeSentence (mySentence.getSentence); mySentence.decomposeSentence("Kiara and John eat 2 suit."); //this should say "Sentence not acceptable" String sentence = "Zane OR Riley deserved suit."; System.out.println(Sentence Generator.check( sentence)); // this prints false sentence = "Zane oR Riley deserved 1 suit."; System.out.println(SentenceGenerator.check(sentence)); // this prints true } }
class SentenceGenerator { private String sentence; //keep private here! // add the getter and the setter of sentence: void getSentence) and void setSentence(String sentence) // add as many helper methods as you see fit public SentenceGenerator() { // Using the provided text files, generate a random sentence to assign to the private data member sentence // See Java documentation on the Random class } public static void decomposeSentence (String sentence) { // First check that sentence is acceptable. // Say sentence is Riley and Zane crashed Trumpet. // your code should print: [Riley][and][Zane] [crashed][Trumpet] this method prints: // If the sentence is Riley or Zane will crash Trumpet. // [Riley][or][Zane] [will crash][Trumpet] } public static boolean check (String sentence) { // this method returns true if the passed parameter sentence is acceptable. // Otherwise, it returns false. // You may need to trim the extra spaces in sentence before you start working on it return ...; } }
accept accepted will accept add added will add admire admired will admire admit admitted will admit advise advised will advise afford afforded will afford agree agreed will agree alert alerted will alert allow allowed will allow amuse amused will amuse announce announced will announce annoy annoyed will annoy answer answered will answer applaud applauded will applaud appreciate appreciated will appreciate approve approved will approve arrive arrived will arrive ask asked will ask attempt attempted will attempt attend attended will attend avoid avoided will avoid bake baked will bake bang banged will bang bat batted will bat bathe bathed will bathe battle battled will battle beam beamed will beam beg begged will beg behave behaved will behave belong belonged will belong bleach bleached will bleach blind blinded will blind blink blinked will blink blot blotted will blot blush blushed will blush boast boasted will boast
Liam Noah Oliver Elijah William James Benjamin Lucas Henry Alexander Mason Michael Ethan Daniel Jacob Logan Jackson Levi Sebastian Mateo Jack Owen Theodore Aiden Samuel Joseph
2 Pairs of jeans 2 Sport shorts 3 Shorts 1 Skiing pants 4 Shirts 6 T-shirts 1 Tank top 4 Sweaters 1 Suit 2 Winter sweater 3 Jackets 1 Cap 1 Beanie 4 Shoes Rug 1 Scarf 1 pair of flip flops 1 pair of gloves 1 set of socks* 1 set of boxers* 1 Belt 4 Guitars Guitar Amp 3 Guitar Cables Trumpet Bike Diving goggles Skiing goggles Sunglasses Rollerskates 3 Hand protection gears 2 Knee protection gears Embroidered picture
//import whatever package.class needed public class Sentence Tester { public static void main(String[] args) { SentenceGenerator mySentence = new SentenceGenerator(); mySentence.decomposeSentence(mySentence.getSentence()); String sentence = "Zane or Riley deserved suit."; System.out.println(SentenceGenerator.check(sentence)); // this prints false mySentence.decomposeSentence("Kiara and John eat 2 suit"); sentence = "Zane oR Riley deserved 1 suit."; System.out.println(SentenceGenerator.check(sentence)); // this prints true } } // class SentenceGenerator { String sentence; // add the getter and the setter of sentence // add as many helper methods as you see fit public String getSentence() { return sentence; } public SentenceGenerator() { // generate a random sentence to assign to the private data member sentence // See Java documentation on the Random class sentence = "Something"; } public static void decomposeSentence(String sentence) { // This method prints sentence. Say sentence is Riley and Zane crashed Trumpet., // your code should print:[Riley][and][Zane) crashed][Trumpet] // If the sentence is Riley or Zane will crash Trumpet., this method prints: // [Riley][or][Zane][ will crash][Trumpet]
} public static boolean check(String sentence) { // this method returns true if the passed parameter sentence is acceptable. // Otherwise, it returns false. // You may need to trim the extra spaces in sentence before you start working on it } }