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
4 Antworten
+ 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.
+ 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
0
i wrote it in python
https://code.sololearn.com/cv12OugqFtDi/?ref=app
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);
}
}