Untitled

mail@pastecode.io avatar
unknown
java
3 years ago
5.1 kB
16
Indexable
Never
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tutor;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author chris
 */

public class Tutor {
    
    /**
     * @param args the command line arguments
     */
    
    //17 - 20
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        
//         .equals(o) || ==

// KALAU STRING!!!!!!!!!!! == kalau integer
//a = "123";
// DONT DO THIS if a == "123";
// LAKUKAN INI if a.equals("123")


//      String[] listNIK = new String[99999999];
//      index_array = 5 ...

//      listNIK[index_array] = VALUE
//      index_array++;

//      String[][] data = new String[99999][3];
//        index_array = 0;
//        index_array++;
//        data[index_array][1] = apa;
//        data[index_array][2] = apa;
//        data[index_array][3] = apa;

//        array (string[]) --> .length
//        int x = 123;
//        String y = String.valueOf(x);
//        arrayList --> .size()
//        "Aku" --> .length

ArrayList<String> listNIK = new ArrayList<>();
ArrayList<ArrayList<String>> data = new ArrayList<>();

String inp_menu = "-1";
//        !True --> false;
// INI KODE YANG AKAN DIEKSEKUSI
while(!inp_menu.equals("4")){
    System.out.print("1. Login\n2. Register\n3. Print Data\n4. Exit\nInput : ");
    inp_menu = in.nextLine();
    if(inp_menu.equals("1"))
    {
        System.out.print("NIK Anda : ");
        String inp_NIK = in.nextLine();
        System.out.print("Password Anda : ");
        String inp_pass = in.nextLine();
        int idx = -1;
        
        for(int i = 0; i < listNIK.size(); i++){
            if(inp_NIK.equals(listNIK.get(i))){
                if(data.get(i).get(1).equals(inp_pass)){
                    idx = i;
                }
            }
        }
        
        if(idx == -1){
            System.out.println("NIK / Password Salah");
        }else{
            String inp_login = "-1";
            while(!inp_login.equals("2")){
                System.out.print("1. Perkenalan Diri\n2. Exit\nInput : ");
                inp_login = in.nextLine();
                if(inp_login.equals("1")){
                    System.out.println(String.format("Nama : %s\nPassword : %s\nTanggal Lahir : %s", data.get(idx).get(0), data.get(idx).get(1), data.get(idx).get(2)));
                }else if(inp_login.equals("2")){
                    idx = -1;
                }else{
                    System.out.println("Input tidak dikenali!");
                }
            }
        }
        
    }else if(inp_menu.equals("2")){
        System.out.print("Input nama : ");
        String inp_nama = in.nextLine();
        System.out.print("Input date (DD-MM-YYYY) : ");
        String inp_date = in.nextLine();
        System.out.print("Input pass : ");
        String inp_pass = in.nextLine();
        boolean status_register = registerUser(inp_nama, inp_date, inp_pass, listNIK, data);
        
        if(status_register == true){
            System.out.println("REGISTER SUKSES!");
        }else{
            System.out.println("REGISTER GAGAL!");
        }
        
    }else if(inp_menu.equals("3")){
        for(int i = 0; i < listNIK.size(); i++){
            System.out.println(String.format("%s. %s",i+1, listNIK.get(i)));
            
            //        dp   ,  dp  ,     dp
            // { {chrisanto, chris, 12-12-2022}, {chrisanto, chris, 12-12-2022} }
            //   SetiapString yangKuNamainDP yangAdaDi Data(i)
            for (String dp : data.get(i)) {
                System.out.println("     "+dp);
            }
        }
    }else if(inp_menu.equals("4")){
    }else{
        System.out.println("Input tidak dikenali!\n");
    }
}
    }
    
    public static boolean registerUser(String v_nama, String v_date, String v_pass, ArrayList<String> vNIK, ArrayList<ArrayList<String>> vData){
        boolean statusReg = true;
        
        //PENGECEKAN
        // Kalau ada yang salah , set statusReg = false
        if(v_nama.length() < 6){
            statusReg = false;
            System.out.println("Username kurang dari 6 huruf!");
        }
        
        if(statusReg == true){
            String NIK = String.format("%04d", vNIK.size()+1);
            //12-12-1222 (dd-mm-yyyy)
            String[] d = v_date.split("-");
            // d = [12,12,1222]
            NIK += (d[0] + d[1] + d[2]);
            vNIK.add(NIK);
            
            // nama, pass, date
            ArrayList<String> temp = new ArrayList<>();
            temp.add(v_nama);
            temp.add(v_pass);
            temp.add(v_date);
            vData.add(temp);
        }
        
        return statusReg;
    }
    
}

//MENU
//KTP
//1. Generate NIK --> xxxx-dd-mm-yyyy --> 000125072003
//2. Simpen Nama
//3. Simpen Tgl lahir ("dd-mm-yyyy")
//4. Password