有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java打印输出用于阵列式课堂考勤系统

我正在设计一个考勤系统,我的问题是我不知道如何显示考勤表的输入。以下是我的系统简介

每个学生都有自己的矩阵号和密码。用户将输入他们的矩阵编号和密码。如果矩阵编号和密码正确,系统将显示一个消息对话框

我不知道如何保存输入,然后将其显示到数组中

源代码:

public class TESTARRAY {


    public static void main(String[] args) {

        String input1;



         // Creating array

       String[][] multi =  { {"40604", "MUHAMAD SYAMIL HAIQAL BIN KAMARUZZAMAN",""},
       {"40599","NIK MUHAMMAD 'INWAN BIN NIK ADNAN",""},
       {"37027","HARNANI BINTI ABDUL MAJID",""},
       {"37067","NURUL ASHIKIN BINTI MOHD FAZLI",""},
       {"37064","NURLIYANA BINTI MOHD KAMAL",""},
       {"37045","NADIATUL NAJIHAH BINTI MOHD NAZRI ",""},
       { "37065","NURSUHAILA BINTI MAD SALIM ",""}
       };


      printArray(multi);
   }


   public static void printArray(String[][] num1) {

       String input2;
       String input3;
       int password;
       int matricnumber;
       int a = 0;
       String  input4;



       boolean one = true;


       String[] columnNames = { "MATRIX NUMBER", "NAME","ATTENENDE"};


     String[][] input1 = new String[num1.length][num1[0].length];
      for (int i = 0; i < input1.length; i++) {
         for (int j = 0; j < input1[i].length; j++) {

             input1[i][j] = num1[i][j];
            }
           }



      DefaultTableModel model = new DefaultTableModel(input1, columnNames);
      JTable table = new JTable(model);
      JScrollPane scrollPane = new JScrollPane(table);

      JOptionPane.showMessageDialog(null, scrollPane, "CLASS ATTENDANCE",
            JOptionPane.INFORMATION_MESSAGE);






      //for (int i = 0; i < 7; i++) {

           while (one== true)
      {

         input2 = JOptionPane.showInputDialog("Please Enter Your Matric Number " );
           matricnumber = Integer.parseInt(input2);


          input3=JOptionPane.showInputDialog("Please Enter  Your Password: " );
          password = Integer.parseInt(input3);

          input4=JOptionPane.showInputDialog("Attendende : " );
          password = Integer.parseInt(input4);




          if (matricnumber==40604&&password==11){

              JOptionPane.showMessageDialog(null,"Hi "+num1[0][1]+""+num1[0][3]+" ("+input2+").\nYou have attend the class. Enjoy the class\nThank you " );

              //JOptionPane.showMessageDialog(null,"The student that attend the class for today:\n"+num1[0][1]+" ("+input2+" )");


               input4=JOptionPane.showInputDialog("Press 0 to stop or other number to continue " );
             a = Integer.parseInt(input4);

              switch(input4){

                  case"0":one=false;
                      break;


              }


          }

          else if (matricnumber==40599&&password==22){

                      JOptionPane.showMessageDialog(null,"Hi "+num1[1][1]+""+num1[1][3]+" ("+input2+").\nYou have attend the class. Enjoy the class\nThank you" );

                      //JOptionPane.showMessageDialog(null,"The student that attend the class for today:\n"+num1[1][1]+" ("+input2+" )");

                       input4=JOptionPane.showInputDialog("Press 0 to stop or other number to continue " );
              a = Integer.parseInt(input4);

              switch(input4){

                 case"0":one=false;
                   break;
              }
          }

          else if (matricnumber==37027&&password==33){

                      JOptionPane.showMessageDialog(null,"Hi "+num1[2][1]+""+num1[2][3]+" ("+input2+").\nYou have attend the class. Enjoy the class\nThank you" );
                      //JOptionPane.showMessageDialog(null,"The student that attend the class for today:\n"+num1[2][1]+" ("+input2+" )");

                       input4=JOptionPane.showInputDialog("Press 0 to stop or other number to continue " );
              a = Integer.parseInt(input4);

              switch(input4){

               case"0":one=false;
                break;
              }

          }

          else if (matricnumber==37067&&password==44){

                      JOptionPane.showMessageDialog(null,"Hi "+num1[3][1]+""+num1[3][3]+" ("+input2+").\nYou have attend the class. Enjoy the class\nThank you" );

                       //JOptionPane.showMessageDialog(null,"The student that attend the class for today:\n"+num1[3][1]+" ("+input2+" )");

                       input4=JOptionPane.showInputDialog("Press 0 to stop or other number to continue " );
              a = Integer.parseInt(input4);

              switch(input4){

                  case"0":one=false;
                      break;
              }

          }

          else if (matricnumber==37064&&password==55){

                      JOptionPane.showMessageDialog(null,"Hi "+num1[4][1]+""+num1[4][3]+" ("+input2+").\nYou have attend the class. Enjoy the class\nThank you" );
                      //JOptionPane.showMessageDialog(null,"The student that attend the class for today:\n"+num1[4][1]+" ("+input2+" )");

                       input4=JOptionPane.showInputDialog("Press 0 to stop or other number to continue " );
              a = Integer.parseInt(input4);

              switch(input4){

                  case"0":one=false;
                      break;
              }
          }

          else if (matricnumber==37045&&password==66){

                      JOptionPane.showMessageDialog(null,"Hi "+num1[5][1]+""+num1[5][3]+" ("+input2+")\nYou have attend the class. Enjoy the class\nThank you" );
                      //JOptionPane.showMessageDialog(null,"The student that attend the class for today:\n"+num1[5][1]+" ("+input2+" )");

                       input4=JOptionPane.showInputDialog("Press 0 to stop or other number to continue " );
              a = Integer.parseInt(input4);

              switch(input4){

                  case"0":one=false;
                      break;
              }
          }

         else if (matricnumber==37065&&password==77){

                      JOptionPane.showMessageDialog(null,"Hi "+num1[6][1]+""+num1[6][3]+" ("+input2+").\nYou have attend the class. Enjoy the class\nThank you" );
                      //JOptionPane.showMessageDialog(null,"The student that attend the class for today:\n"+num1[6][1]+" ("+input2+" )");

                       input4=JOptionPane.showInputDialog("Press 0 to stop or other number to continue " );
              a = Integer.parseInt(input4);

              switch(input4){

                  case"0":one=false;
                      break;
              }

      }

      else 

                      JOptionPane.showMessageDialog(null,"You are not the student in this class. GET OUT !!!" );
           input4=JOptionPane.showInputDialog("Press 0 to stop or other number to continue " );
              a = Integer.parseInt(input4);

              switch(input4){

                  case"n":one=false;
                     break;
              }




           } 


        String input5;
         String[][] ulti =  { {"40604", "MUHAMAD SYAMIL HAIQAL BIN KAMARUZZAMAN","num1[0][2]"},
       {"40599","NIK MUHAMMAD 'INWAN BIN NIK ADNAN","num2[1][3]"},
       {"37027","HARNANI BINTI ABDUL MAJID","num2[2][3]"},
       {"37067","NURUL ASHIKIN BINTI MOHD FAZLI","num2[3][3]"},
       {"37064","NURLIYANA BINTI MOHD KAMAL","num2[4][3]"},
       {"37045","NADIATUL NAJIHAH BINTI MOHD NAZRI ","num2[5][3]"},
       { "37065","NURSUHAILA BINTI MAD SALIM ","num2[6][3]"}
       };


      printA(ulti);
           }

       public static void printA(String[][] num2){ 



       String[] columnNames = { "MATRIX NUMBER", "NAME","ATTENDENCE"};


     String[][] input5 = new String[num2.length][num2[0].length];
      for (int i = 0; i < input5.length; i++) {
         for (int j = 0; j < input5[i].length; j++) {

             input5[i][j] = num2[i][j];
            }
           }



      DefaultTableModel model = new DefaultTableModel(input5, columnNames);
      JTable table = new JTable(model);
      JScrollPane scrollPane = new JScrollPane(table);

      JOptionPane.showMessageDialog(null, scrollPane, "CLASS ATTENDANCE",
            JOptionPane.INFORMATION_MESSAGE);
   }   
   }

共 (1) 个答案

  1. # 1 楼答案

    首先,创建一个包含所有用户输入的数组

     String[] user_input={input2, input3, input4}
    

    然后搜索二维数组中是否存在该数组

    public boolean searchMultiArray(user_input){
    
     boolean b=false;
    
     for(int i=0; i<multi.length; i++){
    
         if(java.utils.Arrays.equals(multi[i], user_input){
    
              b=true;
              break;
         } 
      }
    
     return b;
    }