java - Printing out specific name for a given random number; keeping a running total on the random numbers give -
my program needs print out 3 5 random numbers 10 times. skydiving problem in numbers 1-22 equal 1 point while 23-38 equal 2 points. have created program has 10 different rounds 5 random numbers in each round, can't seem print out formation related specific number i.e. if 1 number equal 1 print out "snowflake".
i have tried using if statements way print out each of formations keep getting error saying int can't become boolean.
package skydiving; import java.security.securerandom; public class skydiving{ public static void main(string[] args){ int = 1; securerandom randomnumbers = new securerandom(); while (i<=10){ system.out.printf("round %d",i++); system.out.println(""); int totalpoints = 0; (int counter = 1 ; counter <= 5; counter++) { int dive = 1 + randomnumbers.nextint(38); if(dive == 1) system.out.println("1: snowflake"); else if(dive == 2) system.out.println("2: sidebody donut"); else if(dive == 3) system.out.println("3: side flake opal"); else if(dive == 4) system.out.println("4: monopod"); else if(dive == 5) system.out.println("5: opal"); else if(dive == 6) system.out.println("6: stardian"); else if(dive == 7) system.out.println("7: sidebuddies"); else if(dive == 8) system.out.println("8: canadian tree"); else if(dive == 9) system.out.println("9: cat+accoridan"); else if(dive == 10 ) system.out.println("10: diamond"); else if(dive == 11) system.out.println("11: photon"); else if(dive == 12 ) system.out.println("12: bundy"); else if(dive == 13 ) system.out.println("13: offset"); else if(dive == 14 ) system.out.println("14: bipole"); else if(dive == 15) system.out.println("15: caterpillar"); else if(dive == 16) system.out.println("16: compressed"); else if(dive == 17 ) system.out.println("17: danish tee"); else if(dive == 18 ) system.out.println("18: zircon"); else if(dive == 19 ) system.out.println("19: ritz"); else if(dive ==20 ) system.out.println("20: piver"); else if(dive == 21) system.out.println("21: zig zag"); else if(dive == 22 ) system.out.println("22: tee"); else if(dive == 23 ) system.out.println("a:unipod"); else if(dive == 24 ) system.out.println("b: stairstep diamond"); else if(dive == 25 ) system.out.println("c: murphy flake"); else if(dive == 26 ) system.out.println("d: yuan"); else if(dive == 27 ) system.out.println("e: meeker"); else if(dive == 28) system.out.println("f: open accordian"); else if(dive == 29 ) system.out.println("g: catacord"); else if(dive == 30 ) system.out.println("h: bow"); else if(dive == 31 ) system.out.println("j: donut"); else if(dive == 32) system.out.println("k: hook"); else if(dive == 33 ) system.out.println("l: adder"); else if(dive == 34 ) system.out.println("m: star"); else if(dive == 35) system.out.println("n: crank"); else if(dive ==36 ) system.out.println("o: satelitte"); else if(dive ==37 ) system.out.println("p: sidebody"); else if(dive == 38 ) system.out.println("q: phalanx"); if(dive <= 22){ totalpoints += 1; } else{ totalpoints += 2; } } system.out.println(); system.out.println("total points: " + totalpoints); } } }
i've managed each number print out specific formation, isn't pretty she'll do. can't seem points work, starts crazy. if 3 blocks used (23-38) 6 point move. need figure way stop random numbers after 3 blocks used. there can 2 score 5 or 6, need determine way generator keep shuffling until suitable formation comes out, if have 4 random formations (1 pointers) can't have block (2 pointer) or illegal formation.
the code fragment have put incomplete. still try make problem statement.
while (i<=10) { system.out.printf("round %d",i++); system.out.println(""); int totaldives = 0; int totalpoints = 0; (int counter = 1 ; counter <= 5; counter++) { int dive = 1 + randomnumbers.nextint(38); totaldives += dive; if(dive <= 22){ totalpoints += 1; system.out.print("snowflake"); } else{ totalpoints += 2; system.out.printf("%d ", dive); } } system.out.println(); } system.out.println("total dives: " + totaldives); system.out.println("total points: " + totalpoints);
this calculates total of dives, assigns points , sums points.
update
you can use string array store dive texts. use directly print without if
statement
public static void main(string[] args){ int = 1; securerandom randomnumbers = new securerandom(); string[] divestyles = {"1: snowflake", "2: sidebody donut", "3: side flake opal", "4: monopod", "5: opal"}; // , on while (i<=10){ system.out.printf("round %d",i++); system.out.println(""); int totalpoints = 0; (int counter = 1 ; counter <= 5; counter++) { int dive = 1 + randomnumbers.nextint(38); system.out.println(divestyles[dive-1]); if(dive <= 22){ totalpoints += 1; } else{ totalpoints += 2; } } system.out.println(); system.out.println("total points: " + totalpoints); } }
Comments
Post a Comment