I am having a few problems with this build. First it is not all it will not load the main class. Second I need the user to input their choice of music and then I need the compiler to print selection. Can someone help me with this code? Please excuse me but I am totally new to programming.
public class music {
public static void music(String[] args) {
System.out.println("What's your favorite kind music?: ");
System.out.println("1. Country");
System.out.println("2. Rock");
System.out.println("3. Heavy Metal");
System.out.println("4. Folk");
try{
BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
int s = Integer.parseInt(bufferRead.readLine());
switch(s){
case 1:
System.out.println("Country");
break;
case 2:
System.out.println("Rock");
break;
case 3:
System.out.println("Heavy Metal");
break;
case 4:
System.out.println("Folk");
break;
default:
System.out.println("Country");
break;
}
}catch(IOException e){
e.printStackTrace();
}
Solution
The problem with the source as posted is that you do not have an entry point to your class (i.e. a method called
main).Suggestions
Since you mentioned you are also new to programming, I’ve taken the liberty to include some stylistic suggestions to make your code simpler and easier to read (IMO):
Further Reading
http://docs.oracle.com/javase/1.5.0/docs/guide/language/static-import.html
http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#nextInt()
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html