So, I'm making a key code generator that creates a five character key code using a-z and 0-9 and )-!. That means there are 46 possible characters for each piece of keycode.

Here is my code so far:

import java.util.Random; import java.util.Scanner; import java.io.*; public class RandomKeyCode { public static String generate() { double c1, c2, c3, c4, c5; String cc1, cc2, cc3, cc4, cc5; String[] choice = new String[5]; String num; Random rand = new Random(); c1 = ((Math.random()*46)+1); find(c1); c2 = ((Math.random()*46)+1); find(c2); c3 = ((Math.random()*46)+1); find(c3); c4 = ((Math.random()*46)+1); find(c4); c5 = ((Math.random()*46)+1); find(c5); } public static void enter() { } public static String find(double c) { String out; switch(c) { case 1: out = "a"; case 2: out = "b"; case 3: out = "c"; case 4: out = "d"; case 5: out = "e"; case 6: out = "f"; case 7: out = "g"; case 8: out = "h"; case 9: out = "i"; case 10: out = "j"; case 11: out = "k"; case 12: out = "l"; case 13: out = "m"; case 14: out = "n"; case 15: out = "o"; case 16: out = "p"; case 17: out = "q"; case 18: out = "r"; case 19: out = "s"; case 20: out = "t"; case 21: out = "u"; case 22: out = "v"; case 23: out = "w"; case 24: out = "x"; case 25: out = "y"; case 26: out = "z"; case 27: out = "1"; case 28: out = "2"; case 29: out = "3"; case 30: out = "4"; case 31: out = "5"; case 32: out = "6"; case 33: out = "7"; case 34: out = "8"; case 35: out = "9"; case 36: out = "0"; case 37: out = "!"; case 38: out = "@"; case 39: out = "#"; case 40: out = "$"; case 41: out = "%"; case 42: out = "^"; case 43: out = "&"; case 44: out = "*"; case 45: out = "("; case 46: out = ")"; } return out; } public static void main(String[] args) { String q; //question variable System.out.print("Do you want to generate your key code, or do you want to enter it?"); switch(q.toLowerCase()) { case("generate") : generate(); case("enter") : enter(); } } }

The errors I am concerned with are the converting errors. In the generate() part of the code, the

double c1, c2, c3, c4, c5;

shows that there are a couple of double numbers that correspond to the parts of the keycode. In the later part of the script, with the switch(c), it says it can't switch on a variable type double.

That's only one of my problems.

When I try to switch the double values to ints, the line

c1 = ((Math.random()*46)+1);

find(c1);

tells me that it can't convert from an int to a double to do math. Also, when I try to do it with floats, same thing happens. I also try to add .toInt() or .toString() to convert it to something, it says it can't convert with the primitive type double.

AGH!

Help please?

-Silent