This is a program which will randomly generate sentences using five different ar
ID: 3821194 • Letter: T
Question
This is a program which will randomly generate sentences using five different arrays of strings. The arrays are as follows: one array for nouns (must have at least 30 different words). one array for adjectives (must have at least 30 different adjectives). one array for verbs (must have at least 30 different verbs). one array for prepositions (must have at least 20 different prepositions). one array for articles (can only have 2 "the" and "a"). Your application should have a method which accepts the five arrays as parameters and returns a randomly generated sentence using the strings from the given arrays. Your program should display seven different randomly generated strings every time the program is executed. A randomly generated string always has the following format:Explanation / Answer
//Randomly generate sentences
// this code has around 10 to 15 words.. it can be modified as your specifications.
import java.lang.String;
public class Sentence{
public static void main(String[] args) {
String[] noun={"sun", "moon","aunty","car", "cat", "God", "dog", "Elephant", "college", "monkey", "girl", "clock","pen","paper","water","rain"};
String[] adjectives ={"adorable", "amused", "attractive", "bad", "beautiful", "bewildered", "blushing", "bored", "brainy", "busy"};
String[] verb={"run", "call","hear","know","recognized","belive","is","smells","appears","went","acted","come","taste"};
String[] prep={"at","about","under","against","across","along","as","around","before" ,"behind" ,"below","beneath","but","by","during"};
String[] articles={"the","a"};
for (int m=1;m<8;m++){
int j=0+(int)(Math.random()*2);
int j1=0+(int)(Math.random()*2);
int i=0 + (int)(Math.random() * 10);
int k=0 + (int)(Math.random() * 10);
//System.out.print(i);
String n=noun[i]; String ad= adjectives[i]; String v= verb[i]; String p= prep[i]; String at=articles[j];
String n1=noun[k]; String ad1= adjectives[k]; String at1= articles[j1];
sentence( n, ad,v,p, at,n1,ad1,at1);
}
}
public static void sentence(String n,String ad, String v,String p,String at,String n1,String ad1,String at1){
System.out.print(at+" " );
System.out.print(ad+" ");
System.out.print(n+" ");
System.out.print(v+" ");
System.out.print(p+" ");
System.out.print(at1+" ");
System.out.print(ad1+" ");
System.out.print(n1+" ");
System.out.println();
}
}
}
output:
run:
a bewildered God belive along a busy monkey
the bad car know against a blushing dog
the amused moon call about the blushing dog
the busy monkey went behind a bewildered God
the bewildered God belive along a bad car
a beautiful cat recognized across the amused moon
the busy monkey went behind the adorable sun
BUILD SUCCESSFUL (total time: 0 seconds)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.