Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.ArrayList;
- import java.util.List;
- public class Main
- {
- public static void main(String[] args)
- {
- boolean willLoop;
- String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // first character of idenNum
- String tempName; // temporary storage for storing names
- List <String> name = new ArrayList<>(); // storage for storing names
- List <String> code = new ArrayList<>(); // storage for identification number
- int NPB = 8; // NUMBER of names PER BATCH, every batch of idenNum contains 9 data in ArrayList
- int batch = 0; // will increment if nth batch is full
- int NON = 0; // will use to identify NUMBER OF NAMES inside ArrayList
- char tempLet; // temporary storage for storing first character of idenNum
- String tempCode;
- do
- {
- Scanner UI = new Scanner(System.in); // Scanner object for user input
- Scanner UI1 = new Scanner(System.in); // 2nd scanner object
- willLoop = false;
- System.out.print("Complete Name: ");
- tempName = UI.nextLine();
- UI.close();
- if (NON <= NPB)
- { // 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)
- tempLet = letters.charAt(batch); // will use to cut the nth batch of character in "letter" variable
- tempCode = (Character.toString(tempLet)) + "-" +(NON + 1); // will use to temporarily store the nth batch of identification num
- NON++;
- name.add(tempName); // will store entered name
- code.add(tempCode); // will store identification number in name's index
- }
- if (NON == 9) // will execute if the nth batch of name is full
- {
- batch++;
- NON = 0;
- }
- String ans = "";
- System.out.print("Would you like to continue? [Y/N]: ");
- ans = UI1.nextLine();
- UI1.close();
- switch (ans)
- {
- case "Y":
- willLoop = true;
- break;
- case "N":
- willLoop = false;
- break;
- }
- }while(willLoop == true);
- System.out.println("\n\n\nOutput:");
- try
- {
- for (int i = 0; i < name.size(); i++)
- {
- System.out.println(code.get(i) + " ==> " + name.get(i));
- }
- }
- catch (IndexOutOfBoundsException iobe)
- {}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement