Rangerguy
Rangerguy

Reputation: 69

No main class found,

This is a beginners question, why do I get a message about I don't have any main class. I am a total beginner and i have tried to read all the other answers regarding this problem. Im working in netbeans.

/**
 * @author Anders
 */
public class Main {

    public enum Valuta {  // here i assign the values i allow from the argument
        EUR,
        USD,
        RUB;

        // here i assign the conversionrates
        static final float C_EUR_TO_DKK_RATE = (float) 7.44;

        static final float C_USD_TO_DKK_RATE = (float) 5.11;

        static final float C_RUB_TO_DKK_RATE = (float) 0.156;

        static float result = 0;

        static int value = 0;


        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {

            if (args.length == 2) {
                value = Integer.parseInt(args[0]);
                String valutaIn = args[1]; //equalsIgnoreCase(null) boolean expression. How does this works??         


                Valuta enumConvert = Valuta.valueOf(valutaIn);

                switch (enumConvert) {

                    case EUR:
                        result = value * C_EUR_TO_DKK_RATE;
                        break;

                    case USD:
                        result = value * C_USD_TO_DKK_RATE;
                        break;

                    case RUB:
                        result = value * C_RUB_TO_DKK_RATE;
                        break;
                }
                System.out.println((float) value + "" + enumConvert + " converts to " + (result * 100.) / 100.0 + "Dk");
            }
            else {
                System.exit(1);
            }
        }
    }
}

Upvotes: 0

Views: 63

Answers (1)

beresfordt
beresfordt

Reputation: 5222

The method main is not in the Class Main, it is inside the enum Valuta. You probably intended the following (note the closing curly bracket after the enum):

/**
 * @author Anders
 */
public class Main {

    public enum Valuta {  // here i assign the values i allow from the argument
        EUR,
        USD,
        RUB;
    }

    // here i assign the conversionrates
    static final float C_EUR_TO_DKK_RATE = (float) 7.44;

    static final float C_USD_TO_DKK_RATE = (float) 5.11;

    static final float C_RUB_TO_DKK_RATE = (float) 0.156;

    static float result = 0;

    static int value = 0;


    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        if (args.length == 2) {
            value = Integer.parseInt(args[0]);
            String valutaIn = args[1]; //equalsIgnoreCase(null) boolean expression. How does this works??         


            Valuta enumConvert = Valuta.valueOf(valutaIn);

            switch (enumConvert) {

                case EUR:
                    result = value * C_EUR_TO_DKK_RATE;
                    break;

                case USD:
                    result = value * C_USD_TO_DKK_RATE;
                    break;

                case RUB:
                    result = value * C_RUB_TO_DKK_RATE;
                    break;
            }
            System.out.println((float) value + "" + enumConvert + " converts to " + (result * 100.) / 100.0 + "Dk");
        }
        else {
            System.exit(1);
        }
    }
}

Upvotes: 2

Related Questions