Advertisement
Maku779

Identification Number 1.0 (Java)

Sep 21st, 2020 (edited)
1,763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4.  
  5. public class Main
  6. {
  7.     public static void main(String[] args)
  8.     {
  9.         boolean willLoop;
  10.         String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // first character of idenNum
  11.         String tempName; // temporary storage for storing names
  12.         List <String> name = new ArrayList<>(); // storage for storing names
  13.         List <String> code = new ArrayList<>(); // storage for identification number
  14.         int NPB = 8; // NUMBER of names PER BATCH, every batch of idenNum contains 9 data in ArrayList
  15.         int batch = 0; // will increment if nth batch is full
  16.         int NON = 0; // will use to identify NUMBER OF NAMES inside ArrayList
  17.         char tempLet; // temporary storage for storing first character of idenNum
  18.         String tempCode;
  19.         do
  20.         {
  21.             Scanner UI = new Scanner(System.in); // Scanner object for user input
  22.             Scanner UI1 = new Scanner(System.in); // 2nd scanner object
  23.             willLoop = false;
  24.             System.out.print("Complete Name: ");
  25.             tempName = UI.nextLine();
  26.             UI.close();
  27.  
  28.             if (NON <= NPB)
  29.             { // will execute if the number of person is less than equal to 8 (we use 8 cause indices in array list always starts with 0)
  30.                 tempLet = letters.charAt(batch); // will use to cut the nth batch of character in "letter" variable
  31.                 tempCode = (Character.toString(tempLet)) + "-" +(NON + 1); // will use to temporarily store the nth batch of identification num
  32.                 NON++;
  33.                 name.add(tempName); // will store entered name
  34.                 code.add(tempCode); // will store identification number in name's index
  35.             }
  36.             if (NON == 9) // will execute if the nth batch of name is full
  37.             {
  38.                 batch++;
  39.                 NON = 0;
  40.             }
  41.             String ans = "";
  42.             System.out.print("Would you like to continue? [Y/N]: ");
  43.             ans = UI1.nextLine();
  44.             UI1.close();
  45.             switch (ans)
  46.             {
  47.                 case "Y":
  48.                     willLoop = true;
  49.                     break;
  50.                 case "N":
  51.                     willLoop = false;
  52.                     break;
  53.             }
  54.         }while(willLoop == true);
  55.         System.out.println("\n\n\nOutput:");
  56.         try
  57.         {
  58.             for (int i = 0; i < name.size(); i++)
  59.             {
  60.                 System.out.println(code.get(i) + " ==> " + name.get(i));
  61.             }
  62.         }
  63.         catch (IndexOutOfBoundsException iobe)
  64.         {}
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement