java - Need help making a Fortune Telling program using eclipse -


this fortune telling program based on origami fortune teller elementary kids used. person had choose number displayed inside fortune teller. chosen number counted out opening , closing fortune teller. person chose number available numbers on display inside fortune teller (they may or may not have been same numbers before) again counted out. final number chosen , fortune under flap read!

design , create fortune telling program works follows:

generate number between 0 , 2 , allow user choose number, number plus 1 or number plus 2 (in other words 1 of 3 consecutive numbers starting randomly chosen number) generate number (0-2) , based on number display 3 colors (of possible 4 colors) choose based on number , color combination selected, tell user fortune.

some requirements: choices must random color combination must random first input must number, second must color. make sure type these user variables appropriately. type has ramifications on if /switch statement(s). careful!! use switch statement(s) appropriate (at least 1 must used) there 6 possible numbers , 4 possible colors = make 5 fortunes , reuse them not use arrays, lists, or functions/subroutines/methods yet

this have far , i'm stuck. need add switch stmt don't know how.

import java.util.scanner; public class lab3 {       public static void main(string[] args) {         // program generates fortune depending on number , color user picked          scanner input = new scanner(system.in);         string userresponse = "0,1,2";         //variables         string[] fortune = new string[5];         fortune[0]= "something great coming";         fortune[1]= "lucky day today";         fortune[2]= "be careful today";         fortune[3]= "you on next test";         fortune[4]= "someone special coming life shortly";          int randfortune;         final int max_winge = 3;          system.out.print("pick number 0-2:");          system.out.print("choose color(red, blue, yellow, green)");            randfortune = (int)(math.random() * (max_winge)) + 1;        case 0:         system.out.println(fortune[0]);         break;     case 1:         system.out.println(fortune[1]);         break;     case 2:         system.out.println(fortune[2]);         break;     case 3:         system.out.println(fortune[3]);         break;     case 4:         system.out.println(fortune[4]);         break;        } } 

just code switch:

switch (randfortune) {     case 0:         system.out.println(fortune[0]);         break;     case 1:        // etc } 

refer switch keyword documentation complete explanation.


p.s. looks don't need switch, rather single line:

system.out.println(fortune[randfortune]); 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -