小编soh*_*hhe的帖子

How to replace switch-case to OOP

I have methods with which I get data from a database. Depending on the variable that the user entered through the console, I must execute the desired method

       while (flag) {
           try {
               sw = new ScannerWrapper();
               menuHeader();
               int choice = sw.readInt();
               switch (choice) {
                   case 1:
                       System.out.println("Input first name: ");
                       String name = sw.readLine().toUpperCase();
                       printResults(DataParser.getFilmByName(name));
                       break;
                     case 0:
                       System.out.println("Bye-bye. Come again");
                       flag = false;
                       break;
                   default:
                       System.out.println("Please enter correct number");
               }
           } catch (Exception e) {
               System.out.println("Enter correct data"); …
Run Code Online (Sandbox Code Playgroud)

java oop

1
推荐指数
1
解决办法
83
查看次数

标签 统计

java ×1

oop ×1