java - This compiles but does not run..any idea why? -
i running on mac , compiles in terminal after type in java lab9 doesn't anything. below put terminal
last login: wed nov 12 15:29:48 on ttys000 roberts-macbook-pro-3:~ robertsemulka$ cd /users/robertsemulka/desktop roberts-macbook-pro-3:desktop robertsemulka$ javac lab9.java roberts-macbook-pro-3:desktop robertsemulka$ java lab9
//compiles not run
import java.util.scanner; import java.util.random; public class lab9 { public static void main(string[] args) { //create arrays int[] lotterynum = new int[5]; int[] usernum = new int[5]; //create scanner , random objects scanner keyboard = new scanner(system.in); random randomgenerator = new random(); //declare , initialize variable track correct digits int numcorrectdigits = 0; //todo: using for-loop, generate 5 random numbers; store numbers in lotterynum array for(int i=0;i<5;i++) { int randomint = randomgenerator.nextint(10); lotterynum[i] = randomint; } //todo: using for-loop, prompt user 5 digits; store digits in usernum array for(int i=0;i<5;i++) { int userint = keyboard.nextint(); usernum[i] = userint; } //todo: using for-loop, compare lotterynum array , usernum array; increment variable numcorrectdigits //each time find matching pair of corresponding numbers for(int i=0;i<5;i++) { if(lotterynum[i] == usernum[i]) numcorrectdigits++; } //todo: display winning number , user's number //example: //the winning number is: 12771 //your number is: 30781 system.out.print("the winning number is: "); for(int i=0; i<5; i++) { system.out.println(lotterynum[i]); } system.out.println(); system.out.print("your number is: "); for(int i=0; i<5; i++) { system.out.println(usernum[i]); } //print blank line system.out.println(); //todo: display number of correct digits //example: //number of correct digits is: 2 //todo: complete switch statement below display results user switch(numcorrectdigits) { case 0: system.out.println("your prize is: $0.00"); case 1: system.out.println("your prize is: $10.00"); case 2: system.out.println("your prize is: $100.00"); case 3: system.out.println("your prize is: $1000.00"); case 4: system.out.println("your prize is: $10,000.00"); case 5: system.out.println("your prize is: $100,000.00"); break; why compile not } system.out.println("\nplease play again!"); } } program generate 5-digit lottery number, , prompt user enter guess in form of 5-digit number. program should determine how many numbers user guessed correctly , user’s prize. program must use object of random class generate 5 integers in range 0 through 9 , must store these integers in array. program needs prompt user enter 5 integers in range 0 through 9 , needs store these integers in array. use 2 integer arrays in program. determine how many numbers user correctly guessed, program needs compare corresponding elements of both arrays in loop. use counter variable keep track of how many numbers user guessed correctly. @ end of program, output user lottery number, user’s guess, , number of digits user guessed correctly. finally, program needs determine , display user’s prize. here chart defines prizes lottery:    number of correct digits prize  0 $0  1 $10  2 $100   3 $1,000  4 $10,000   5 $100,000 here sample runs (user input given in <>): 1. welcome lottery application! please enter digit in range 0-9: <3> please enter digit in range 0-9: <0> please enter digit in range 0-9: <7> please enter digit in range 0-9: <8> please enter digit in range 0-9: <1> cs7 lab 9 fall 2014 winning number is: 12771 number is: 30781 number of correct digits: 2 prize is: $100.00! please play again!
the program waiting input. add prompt:
//todo: using for-loop, prompt user 5 digits; store digits in usernum array for(int i=0;i<5;i++) { system.out.println("enter next digit:"); int userint = keyboard.nextint(); usernum[i] = userint; }
Comments
Post a Comment