Advertisement
eightmoons

Main.java

Mar 27th, 2020
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.79 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.*;
  4. import java.util.ArrayList;
  5. import java.util.Random;
  6. import java.util.Scanner;
  7.  
  8. public class Main {
  9.     static String[] id;
  10.  
  11.     public static void main(String[] args) {
  12.         int idSize = 200;
  13.         id = new String[idSize];
  14.         String mstudentId, mLname, mFname, moccup, mGender, mcountryCode, mareaCode, mphoneNum;
  15.         boolean loop = false;
  16.         int x;
  17.         Scanner input = new Scanner(System.in);
  18.         char ans;
  19.         int counter = 0;
  20.         int choice;
  21.         int pil;
  22.         boolean running = true;
  23.         boolean run = true;
  24.         boolean runner = true;
  25.         String newID;
  26.  
  27.         phonebook Abook[] = new phonebook[500];
  28.  
  29.         do {
  30.             System.out.println("[1] Store Asean phonebook\n[2] Edit Entry in ASEAN\n[3] Search Asean phonebook by country\n[4] Exit\n\n");
  31.  
  32.             System.out.println("Enter A Choice");
  33.             choice = input.nextInt();
  34.             input.nextLine();
  35.  
  36.  
  37.             switch (choice) {
  38.                 case 1:
  39.                     boolean checkId = false;
  40.                     do {
  41.                         System.out.println("Enter Student Number : ");
  42.                         mstudentId = input.nextLine();
  43.                         if (counter >= 1) {
  44.                             for (int i = 0; i < id.length; i++) {
  45.                                 if (mstudentId.equals(id[i])) {
  46.                                     checkId = true;
  47.                                     break;
  48.                                 }
  49.                             }
  50.                         } else {
  51.                         }
  52.                         id[counter] = mstudentId;
  53.                         if (checkId) {
  54.                             System.err.println("\n\nThe ID is Already Registered \n\n");
  55.                             break;
  56.                         }
  57.  
  58.                         System.out.println("Enter Surname : ");
  59.                         mLname = input.nextLine();
  60.                         System.out.println("Enter First Name : ");
  61.                         mFname = input.nextLine();
  62.                         System.out.println("Enter Occupation : ");
  63.                         moccup = input.nextLine();
  64.                         System.out.println("Enter Gender (M for male, F for female) : ");
  65.                         mGender = input.nextLine();
  66.                         System.out.println("Enter your Country Code : ");
  67.                         mcountryCode = input.nextLine();
  68.                         System.out.println("Enter Area Code : ");
  69.                         mareaCode = input.nextLine();
  70.                         System.out.println("Enter Number : ");
  71.                         mphoneNum = input.nextLine();
  72.                         System.out.println("Do you want to enter another entry [Y/N]? : ");
  73.                         ans = input.nextLine().charAt(0);
  74.                         Abook[counter] = new phonebook(mstudentId, mLname, mFname, moccup, mGender, mcountryCode, mareaCode, mphoneNum);
  75.                         counter++;
  76.  
  77.                         if (ans != 'Y') {
  78.                             run = false;
  79.                         }
  80.  
  81.  
  82.                     } while (run);
  83.                     break;
  84.                 case 2:
  85.                     System.out.println("Which of the following information do you wish to change? : ");
  86.                     newID = input.nextLine();
  87.                     for (x = 0; x < counter; x++) {
  88.                         if (newID.equals(Abook[x].mstudentId)) {
  89.                             do {
  90.                                 System.out.println("\n\nHere is the existing information about " + Abook[x].mstudentId + ":");
  91.                                 System.out.println(Abook[x].mFname + " " + Abook[x].mLname + "\n is a " + Abook[x].moccup + " His number is " + Abook[x].mphoneNum);
  92.                                 System.out.println("\n\n Which of the following you want to edit?\n");
  93.  
  94.                                 System.out.println("[1] Student Number\n[2] Surname\n[3] Gender\n[4] Occupation\n[5] Country code\n[6] Area Code\n[7] Phone Number\n[8] Non- Go back to main menu\n");
  95.                                 System.out.println("Enter a choice : ");
  96.                                 pil = input.nextInt();
  97.                                 input.nextLine();
  98.  
  99.                                 switch (pil) {
  100.                                     case 1:
  101.                                         do {
  102.                                             for (x = 0; x < counter; x++) {
  103.                                                 System.out.println("Enter a new Student ID");
  104.                                                 newID = input.nextLine();
  105.                                                 Abook[x].mstudentId = newID;
  106.                                                 if (newID.equals(Abook[x].mstudentId)) {
  107.                                                     System.err.println("Already Exist");
  108.                                                     loop = true;
  109.                                                     break;
  110.                                                 } else if (newID != Abook[x].mstudentId) {
  111.                                                     Abook[x].mstudentId = newID;
  112.                                                     loop = false;
  113.                                                 }
  114.                                             }
  115.  
  116.  
  117.                                         } while (loop);
  118.                                         break;
  119.                                     case 2:
  120.                                         System.out.println("Enter a new Last Name");
  121.                                         newID = input.nextLine();
  122.                                         Abook[x].mLname = newID;
  123.                                         break;
  124.                                     case 3:
  125.                                         System.out.println("Enter new Gender");
  126.                                         newID = input.nextLine();
  127.                                         Abook[x].mGender = newID;
  128.                                         break;
  129.                                     case 4:
  130.                                         System.out.println("Enter a new occupation");
  131.                                         newID = input.nextLine();
  132.                                         Abook[x].moccup = newID;
  133.                                         break;
  134.                                     case 5:
  135.                                         System.out.println("Enter a new Country Code");
  136.                                         newID = input.nextLine();
  137.                                         Abook[x].mcountryCode = newID;
  138.                                         break;
  139.                                     case 6:
  140.                                         System.out.println("Enter a new Area Code");
  141.                                         newID = input.nextLine();
  142.                                         Abook[x].mareaCode = newID;
  143.                                         break;
  144.                                     case 7:
  145.                                         System.out.println("Enter a new phone Number");
  146.                                         newID = input.nextLine();
  147.                                         Abook[x].moccup = newID;
  148.                                         break;
  149.                                     case 8:
  150.  
  151.                                         runner = false;
  152.                                         break;
  153.  
  154.                                     default:
  155.                                         System.out.println("Invalid Keyword");
  156.  
  157.  
  158.                                 } //closing sa switch case 2
  159.  
  160.  
  161.                             } while (runner);//closing sa do sa case 2
  162.  
  163.  
  164.                         }
  165. //if closing brace
  166.  
  167.                     }
  168. //closing sa for loop
  169.                     break;
  170.  
  171.                 case 3:
  172.  
  173.                     String input1 = "Search ASEAN phonebook by country \n\n\n";
  174.                     System.out.println(input1.toUpperCase());
  175.                     System.out.println("[1] Phillipines [2] Thailand [3] Singapore [4] Indonesia [5] Malaysia [6] All [0] None");
  176.                     System.out.print("Enter choice : ");
  177.                     pil = input.nextInt();
  178.                     input.nextLine();
  179.                     switch (pil) {
  180.                         case 1:
  181.                             break;
  182.                         case 2:
  183.                             break;
  184.                         case 3:
  185.                             break;
  186.                         case 4:
  187.                             break;
  188.                         case 5:
  189.                             break;
  190.                         case 6:
  191.                             break;
  192.                         case 0:
  193.                             break;
  194.                     }
  195.                     break;
  196.                 case 4:
  197.                     System.exit(0);
  198.                     break;
  199.             }
  200.  
  201.         } while (running);
  202.  
  203.  
  204.     }
  205.     public static class phonebook {
  206.         public String mstudentId;
  207.         public String mLname;
  208.         public String mFname;
  209.         public String moccup;
  210.         public String mGender;
  211.         public String mcountryCode;
  212.         public String mareaCode;
  213.         public String mphoneNum;
  214.  
  215.         public phonebook(String mstudentId, String mLname, String mFname, String moccup, String mGender, String mcountryCode, String mareaCode, String mphoneNum) {
  216.             this.mstudentId = mstudentId;
  217.             this.mLname = mLname;
  218.             this.mFname = mFname;
  219.             this.moccup = moccup;
  220.             this.mGender = mGender;
  221.             this.mcountryCode = mcountryCode;
  222.             this.mareaCode = mareaCode;
  223.             this.mphoneNum = mphoneNum;
  224.         }
  225.     }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement