Hi I am trying to run a Java Code with multiple classes,
{ language: 'java', version: '15.0.2', files: [ { content: 'import java.util.Scanner;\n' + '\n' + 'interface DeviceController {\n' + ' String executeCommand(String cmd);\n' + ' default String getSystemStatus() { return "ONLINE"; }\n' + ' static String getFirmwareVersion() { return "v2.4"; }\n' + '}\n' + '\n' + 'class SmartLight implements DeviceController {\n' + ' @Override\n' + ' public String executeCommand(String cmd) {\n' + ' return (cmd.equals("ON") || cmd.equals("OFF")) ? "Executed" : "Unsupported Command";\n' + ' }\n' + ' String getType() { return "Light"; }\n' + '}\n' + '\n' + 'class SmartFan implements DeviceController {\n' + ' @Override\n' + ' public String executeCommand(String cmd) {\n' + ' return (cmd.equals("LOW") || cmd.equals("MED") || cmd.equals("HIGH")) ? "Executed" : "Unsupported Command";\n' + ' }\n' + ' String getType() { return "Fan"; }\n' + '}\n' + '\n' + 'public class Main {\n' + ' public static void main(String[] args) {\n' + ' Scanner sc = new Scanner(System.in);\n' + ' System.out.println("System: " + new SmartLight().getSystemStatus() + " | Firmware: " + DeviceController.getFirmwareVersion());\n' + ' \n' + ' SmartLight light = new SmartLight();\n' + ' SmartFan fan = new SmartFan();\n' + ' \n' + ' while (sc.hasNext()) {\n' + ' String type = sc.next();\n' + ' if (type.equals("END")) break;\n' + ' String cmd = sc.next();\n' + ' \n' + ' DeviceController device = type.equals("LIGHT") ? light : fan;\n' + ' String result = device.executeCommand(cmd);\n' + ' String deviceName = type.equals("LIGHT") ? "Light" : "Fan";\n' + ' \n' + ' System.out.printf("[%s] Command: %s -> %s%n", deviceName, cmd, result);\n' + ' }\n' + ' }\n' + '}' } ], stdin: 'LIGHT ON END', args: [ '-lm' ], compile_timeout: 10000, run_timeout: 3000, compile_memory_limit: -1, run_memory_limit: -1 }
It always give the output: error: can't find main(String[]) method in class: DeviceController
How can i fix this? It works in onlineGDB
Thank you.
Hi I am trying to run a Java Code with multiple classes,
{ language: 'java', version: '15.0.2', files: [ { content: 'import java.util.Scanner;\n' + '\n' + 'interface DeviceController {\n' + ' String executeCommand(String cmd);\n' + ' default String getSystemStatus() { return "ONLINE"; }\n' + ' static String getFirmwareVersion() { return "v2.4"; }\n' + '}\n' + '\n' + 'class SmartLight implements DeviceController {\n' + ' @Override\n' + ' public String executeCommand(String cmd) {\n' + ' return (cmd.equals("ON") || cmd.equals("OFF")) ? "Executed" : "Unsupported Command";\n' + ' }\n' + ' String getType() { return "Light"; }\n' + '}\n' + '\n' + 'class SmartFan implements DeviceController {\n' + ' @Override\n' + ' public String executeCommand(String cmd) {\n' + ' return (cmd.equals("LOW") || cmd.equals("MED") || cmd.equals("HIGH")) ? "Executed" : "Unsupported Command";\n' + ' }\n' + ' String getType() { return "Fan"; }\n' + '}\n' + '\n' + 'public class Main {\n' + ' public static void main(String[] args) {\n' + ' Scanner sc = new Scanner(System.in);\n' + ' System.out.println("System: " + new SmartLight().getSystemStatus() + " | Firmware: " + DeviceController.getFirmwareVersion());\n' + ' \n' + ' SmartLight light = new SmartLight();\n' + ' SmartFan fan = new SmartFan();\n' + ' \n' + ' while (sc.hasNext()) {\n' + ' String type = sc.next();\n' + ' if (type.equals("END")) break;\n' + ' String cmd = sc.next();\n' + ' \n' + ' DeviceController device = type.equals("LIGHT") ? light : fan;\n' + ' String result = device.executeCommand(cmd);\n' + ' String deviceName = type.equals("LIGHT") ? "Light" : "Fan";\n' + ' \n' + ' System.out.printf("[%s] Command: %s -> %s%n", deviceName, cmd, result);\n' + ' }\n' + ' }\n' + '}' } ], stdin: 'LIGHT ON END', args: [ '-lm' ], compile_timeout: 10000, run_timeout: 3000, compile_memory_limit: -1, run_memory_limit: -1 }It always give the output:
error: can't find main(String[]) method in class: DeviceControllerHow can i fix this? It works in onlineGDB
Thank you.