Here you can find the source of generateDescription()
private static String generateDescription()
//package com.java2s; /* Licensed Materials - Property of IBM */ import java.util.concurrent.ThreadLocalRandom; public class Main { /**/*from www.java2s . co m*/ * A selection of possible sizes for the description. Maximum length should be 11 characters. */ private static final String[] SIZE = { "Tiny", "Small", "Medium", "Large", "Extra large", "Huge" }; /** * A selection of possible colours for the description. Maximum length should be 6 characters. */ private static final String[] COLOUR = { "blue", "red", "orange", "green", "yellow", "white", "black", "purple" }; /** * A selection of possible shapes for the description. Maximum length should be 6 characters. */ private static final String[] SHAPE = { "round", "square", "oval", "flat" }; /** * A selection of possible materials for the description. Maximum length should be 7 characters. */ private static final String[] MATERIAL = { "plastic", "metal", "card" }; /** * A selection of possible object types for the description. Maximum length should be 6 characters. */ private static final String[] NOUN = { "widget", "thing", "plug", "nut", "bit", "part", "panel" }; /** * Generates a description for a random part using the arrays of constants * {@link #SIZE}, {@link #COLOUR}, {@link #SHAPE}, {@link #MATERIAL}, and * {@link #NOUN}. The description will be a string of maximum length 40 characters. * * @return a human-readable description of an object */ private static String generateDescription() { // Source of random numbers ThreadLocalRandom r = ThreadLocalRandom.current(); // Buffer to hold the generated description - max possible length of 40 characters StringBuilder sb = new StringBuilder(40); // Generate a random sequence of adjectives and finish with a noun sb.append(SIZE[r.nextInt(SIZE.length)]); sb.append(' '); sb.append(COLOUR[r.nextInt(COLOUR.length)]); sb.append(' '); sb.append(SHAPE[r.nextInt(SHAPE.length)]); sb.append(' '); sb.append(MATERIAL[r.nextInt(MATERIAL.length)]); sb.append(' '); sb.append(NOUN[r.nextInt(NOUN.length)]); // Return the created description return sb.toString(); } }