dimanche 29 octobre 2017

need to select random word from each list [duplicate]

This question already has an answer here:

I am new to java and I am struggling with this assignment. The method shoutOutCannedMessage() will return the selected message string. Your shoutOutRandomMessage() method should use a random number generator that selects one word from each data structure to form a random message. The random number generated should not exceed the bounds of your data. In other words, if you only have 5 words in a data structure, the random number generated should not be an index that has no word stored. The method shoutOutRandomMessage() should return a randomly generated message string in accordance with specifications, in the following form: Subject - Verb - Adjective - Object - Adverb (for example, “You read hard books quickly”). Where I am having an issue is how to call a random word from each list. Here is what I have so far. Please forgive me as I am new to Java.

package virtualworld;
import java.util.*;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author SClough
 */

public class Randomwords {


public static void main(String[] args) { 

}

      //holds the words to be generated.

      String[] subject= {" She", " Cat", " School", " Home", " They" };
      String[] verb= {" working", " sleeping", " eating", " playing"," studying" };
      String[] adjective= {" brainy", " calm", " determined", " encouraging", " graceful" };
      String[] object= {" class", " cookie", " book", " flower", " puddle"};
      String[] adverb= {" correctly. ", " loudly. ", " quickly. ", " eagerly. ", " carefully. "};


       Random rand = new Random();//intialize a Random


      //randomly create sentence.




     System.out.println( +randomSentence );

      }




Aucun commentaire:

Enregistrer un commentaire