This is the code I have so far.
package milestone.pkg4;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class Milestone4 {
public static void main(String[] args){
new Milestone4().shoutOutCannedMessage();
}
public String shoutOutCannedMessage(){
String[] messages;
messages= new String[10];
messages[0]="I like HipHop";
messages[1]="I like Rock and Roll";
messages[2]="I like movies";
messages[3]="I don't like action films";
messages[4]="I'll watch anything with Jackie chan!";
messages[5]="Will Smith is a great actor";
messages[6]="Lebron James is a beast";
messages[7]="I like homecooked food";
messages[8]="I like chinese food";
messages[9]="I love pizza";
for (int i=0; i<messages.length; i++)
{
System.out.println("choice["+i+"]:" + messages[i]);//prints messages
}
System.out.print("Please choose the message to which you relate: ");
//user input section
Scanner userInput= new Scanner(System.in);
int sel= userInput.nextInt();/**looks for the number a user selects
* as their response*/
String userSelection= messages[sel];
System.out.println(userSelection);
return null;
}
//Random shout
public String shoutOutRandomMessage(){
String[] subjects={"law", "football", "movies"};
String[] objects={"ball", "knife", "sneaker"};
String[] verbs={"fleeing", "thrashing", "petting"};
String[] adverb={"softly", "belligerently", "expressively"};
String[] adjectives={"disgusting", "short", "bubbly"};
//random number generator**
the code needs to pick one random word from each array in the shoutOutRandomMessage(). It then needs to print the selected words in this order (subjects-verbs-adjectives-objects-adverb).
I am new to java. I tried loops and used random generators but it happened to print out all the objects in the array lists in the order i needed. Not, just one randomly selected object from each array list. Please help.
Aucun commentaire:
Enregistrer un commentaire