What's up with this. Just trying to test my hands on java packages, and had this error(by java) after successful compilation:
Error occurred during initialization of VM
java.lang.Error: Properties init: Could not determine current working directory.
at java.lang.System.initProperties(Native Method)
at java.lang.System.initializeSystemClass(System.java :1119)
Main.java
package com.aceix.simplecalc; import com.aceix.simplecalc.inputhandler.InputHandler; import com.aceix.simplecalc.mathoperation.MathOperation; public class Main { public static void main(String[] args) { try { System.out.println("Welcome to Aceix's simplecalc v1.0"); double num1=Double.parseDouble((InputHandler.getInput("Enter a number: "))); double num2=Double.parseDouble(InputHandler.getInput("\nEnter another number: ")); int op=Integer.parseInt(InputHandler.getInput("1. Add\n2. Subtract\n3. Multiply\n4. Divide\nSelection: ")); double ans=0.0d; switch (op) { case 1: ans=MathOperation.add(num1, num2); break; case 2: ans=MathOperation.subtract(num1, num2); break; case 3: ans=MathOperation.multiply(num1, num2); break; case 4: ans=MathOperation.divide(num1, num2); break; default: System.out.println("Invalid selection!!!"); break; } System.out.println("\n\n\nYou result is: "+ans); return; } catch (Exception e) { e.getMessage(); } } }
MathOperation.java
package com.aceix.simplecalc.mathoperation; public class MathOperation { public static double add(double lhs, double rhs) { return lhs+rhs; } public static double subtract(double lhs, double rhs) { return lhs-rhs; } public static double multiply(double lhs, double rhs) { return lhs*rhs; } public static double divide(double lhs, double rhs) { return lhs/rhs; } }
InputHandler.java
package com.aceix.simplecalc.inputhandler; public class InputHandler { public static String getInput(String prompt) { System.out.println(prompt); return System.console().readLine().trim(); } }
And please show me a suitable way to accept input from console.
Thanks,
Aceix.