Mini project on sentence generator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Mini project on sentence generator

Your Java programme will randomly generate sentences from a predefined set of words in various lists. Use the following lists for starters 1. Subject List [cook, runner, driver, student, musician, artist, writer, boy, girl, man] 2. Verb List [cooked, ate, drank, solved, played, painted, penned, played, wrote, created] 3. Adjective List [best, sweetest, hardest, nicest, saddest, happiest] 4. Object List [rice, ice-cream, beer, equation, tune, portrait, story, song, poem, riddle] When you click “Generate” the app should display a random sentence with the structure “The {subject} {verb} the {adjective} {object}.” An example of a random sentence generated by your app could be; The cook painted the happiest story

5th Aug 2023, 2:02 AM
Sulemana Fusheini
Sulemana Fusheini - avatar
4 Answers
+ 3
Did you tried this mini project yourself? We don't write codes for any school projects. To help you we need to see your code first. Share your attempted code.
5th Aug 2023, 4:49 AM
D Shah 🎯⏳️
D Shah 🎯⏳️ - avatar
+ 1
Refer this https://code.sololearn.com/cnJtuk2aU4P5/?ref=app This program defines the lists of subjects, verbs, adjectives, and objects as arrays. It then uses a Random object to select a random element from each list and creates a sentence following the specified structure. When you run the program, it will display a randomly generated sentence like the example you provided. Hope this helps
5th Aug 2023, 4:54 PM
‎ ຸ
5th Aug 2023, 7:02 AM
Angela
Angela - avatar
0
import java.util.Random; public class RandomSentenceGenerator { public static void main(String[] args) { String[] subjects = {"cook", "runner", "driver", "student", "musician", "artist", "writer", "boy", "girl", "man"}; String[] verbs = {"cooked", "ate", "drank", "solved", "played", "painted", "penned", "played", "wrote", "created"}; String[] adjectives = {"best", "sweetest", "hardest", "nicest", "saddest", "happiest"}; String[] objects = {"rice", "ice-cream", "beer", "equation", "tune", "portrait", "story", "song", "poem", "riddle"}; Random rand = new Random(); String subject = subjects[rand.nextInt(subjects.length)]; String verb = verbs[rand.nextInt(verbs.length)]; String adjective = adjectives[rand.nextInt(adjectives.length)]; String object = objects[rand.nextInt(objects.length)]; String sentence = "The " + subject + " " + verb + " the " + adjective + " " + object + "."; System.out.println(sentence); } }
5th Aug 2023, 3:22 PM
Sulemana Fusheini
Sulemana Fusheini - avatar