Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch Statement Survey

Tags:

java

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();
    }
like image 874
Tim Avatar asked Apr 18 '26 00:04

Tim


2 Answers

public static void music(String[] args)

This does not look like main method. You should use main in place of music: -

public static void main(String[] args)

Also, the compilation unit containing this class should have the same name as that of the class. And better use your class name as : - Music and save it as Music.java

like image 140
Rohit Jain Avatar answered Apr 20 '26 13:04

Rohit Jain


Your method must be named main. Review this tutorial.

Instead of:

public static void music(String[] args) {

try:

public static void main(String[] args) {

public static void music(String[] args) defines a static method with the same names as the class.

like image 45
pb2q Avatar answered Apr 20 '26 12:04

pb2q