Java: How To Use Arrays -


i learning arrays today in school, , trying problem, cannot figure

// fortune teller  import java.awt.color; import java.awt.container; import java.awt.flowlayout; import java.awt.event.actionlistener; import java.awt.event.actionevent; import javax.swing.jframe; import javax.swing.jtextfield; import javax.swing.jbutton;  public class fortuneteller extends jframe     implements actionlistener {   private static final easysound ding = new easysound("ding.wav");    // declare array of "fortunes" (strings):   ___________________________________________   ...    private jtextfield display;    public fortuneteller()   {     super("fortune teller");      display = new jtextfield("  press \"next\" see fortune...", 25);     display.setbackground(color.white);     display.seteditable(false);      jbutton go = new jbutton("next");     go.addactionlistener(this);      container c = getcontentpane();     c.setlayout(new flowlayout());     c.add(display);     c.add(go);   }    public void actionperformed(actionevent e)   {     // pick , display random fortune:      ___________________________________________     ...      display.settext("  " + __________________ );     ding.play();   }    public static void main(string[] args)   {     jframe window = new fortuneteller();     window.setbounds(300, 300, 300, 100);     window.setdefaultcloseoperation(jframe.exit_on_close);     window.setresizable(false);     window.setvisible(true);    } } 

i trying fill in blanks.

for first one,, just string [] fortune;?

but how end initializing it?

and second part, have do?

please extremely lost.

here hints (without doing homework you).

you can create , populate array of strings in 1 line using following syntax:

string[] colours = {"red", "orange", "yellow", "green", "blue", "indigo", "violet"}; 

you can generate random number between 0 , x (inclusive) using following syntax:

int randomnumber = math.random() * (x + 1); 

you can select random string array following syntax:

string randomcolour = colours[math.random() * colours.length]; 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -