Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.util.ArrayList;
- import java.util.Random;
- import java.util.Scanner;
- public class Main {
- static String[] id;
- public static void main(String[] args) {
- int idSize = 200;
- id = new String[idSize];
- String mstudentId, mLname, mFname, moccup, mGender, mcountryCode, mareaCode, mphoneNum;
- boolean loop = false;
- int x;
- Scanner input = new Scanner(System.in);
- char ans;
- int counter = 0;
- int choice;
- int pil;
- boolean running = true;
- boolean run = true;
- boolean runner = true;
- String newID;
- phonebook Abook[] = new phonebook[500];
- do {
- 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");
- System.out.println("Enter A Choice");
- choice = input.nextInt();
- input.nextLine();
- switch (choice) {
- case 1:
- boolean checkId = false;
- do {
- System.out.println("Enter Student Number : ");
- mstudentId = input.nextLine();
- if (counter >= 1) {
- for (int i = 0; i < id.length; i++) {
- if (mstudentId.equals(id[i])) {
- checkId = true;
- break;
- }
- }
- } else {
- }
- id[counter] = mstudentId;
- if (checkId) {
- System.err.println("\n\nThe ID is Already Registered \n\n");
- break;
- }
- System.out.println("Enter Surname : ");
- mLname = input.nextLine();
- System.out.println("Enter First Name : ");
- mFname = input.nextLine();
- System.out.println("Enter Occupation : ");
- moccup = input.nextLine();
- System.out.println("Enter Gender (M for male, F for female) : ");
- mGender = input.nextLine();
- System.out.println("Enter your Country Code : ");
- mcountryCode = input.nextLine();
- System.out.println("Enter Area Code : ");
- mareaCode = input.nextLine();
- System.out.println("Enter Number : ");
- mphoneNum = input.nextLine();
- System.out.println("Do you want to enter another entry [Y/N]? : ");
- ans = input.nextLine().charAt(0);
- Abook[counter] = new phonebook(mstudentId, mLname, mFname, moccup, mGender, mcountryCode, mareaCode, mphoneNum);
- counter++;
- if (ans != 'Y') {
- run = false;
- }
- } while (run);
- break;
- case 2:
- System.out.println("Which of the following information do you wish to change? : ");
- newID = input.nextLine();
- for (x = 0; x < counter; x++) {
- if (newID.equals(Abook[x].mstudentId)) {
- do {
- System.out.println("\n\nHere is the existing information about " + Abook[x].mstudentId + ":");
- System.out.println(Abook[x].mFname + " " + Abook[x].mLname + "\n is a " + Abook[x].moccup + " His number is " + Abook[x].mphoneNum);
- System.out.println("\n\n Which of the following you want to edit?\n");
- 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");
- System.out.println("Enter a choice : ");
- pil = input.nextInt();
- input.nextLine();
- switch (pil) {
- case 1:
- do {
- for (x = 0; x < counter; x++) {
- System.out.println("Enter a new Student ID");
- newID = input.nextLine();
- Abook[x].mstudentId = newID;
- if (newID.equals(Abook[x].mstudentId)) {
- System.err.println("Already Exist");
- loop = true;
- break;
- } else if (newID != Abook[x].mstudentId) {
- Abook[x].mstudentId = newID;
- loop = false;
- }
- }
- } while (loop);
- break;
- case 2:
- System.out.println("Enter a new Last Name");
- newID = input.nextLine();
- Abook[x].mLname = newID;
- break;
- case 3:
- System.out.println("Enter new Gender");
- newID = input.nextLine();
- Abook[x].mGender = newID;
- break;
- case 4:
- System.out.println("Enter a new occupation");
- newID = input.nextLine();
- Abook[x].moccup = newID;
- break;
- case 5:
- System.out.println("Enter a new Country Code");
- newID = input.nextLine();
- Abook[x].mcountryCode = newID;
- break;
- case 6:
- System.out.println("Enter a new Area Code");
- newID = input.nextLine();
- Abook[x].mareaCode = newID;
- break;
- case 7:
- System.out.println("Enter a new phone Number");
- newID = input.nextLine();
- Abook[x].moccup = newID;
- break;
- case 8:
- runner = false;
- break;
- default:
- System.out.println("Invalid Keyword");
- } //closing sa switch case 2
- } while (runner);//closing sa do sa case 2
- }
- //if closing brace
- }
- //closing sa for loop
- break;
- case 3:
- String input1 = "Search ASEAN phonebook by country \n\n\n";
- System.out.println(input1.toUpperCase());
- System.out.println("[1] Phillipines [2] Thailand [3] Singapore [4] Indonesia [5] Malaysia [6] All [0] None");
- System.out.print("Enter choice : ");
- pil = input.nextInt();
- input.nextLine();
- switch (pil) {
- case 1:
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- break;
- case 6:
- break;
- case 0:
- break;
- }
- break;
- case 4:
- System.exit(0);
- break;
- }
- } while (running);
- }
- public static class phonebook {
- public String mstudentId;
- public String mLname;
- public String mFname;
- public String moccup;
- public String mGender;
- public String mcountryCode;
- public String mareaCode;
- public String mphoneNum;
- public phonebook(String mstudentId, String mLname, String mFname, String moccup, String mGender, String mcountryCode, String mareaCode, String mphoneNum) {
- this.mstudentId = mstudentId;
- this.mLname = mLname;
- this.mFname = mFname;
- this.moccup = moccup;
- this.mGender = mGender;
- this.mcountryCode = mcountryCode;
- this.mareaCode = mareaCode;
- this.mphoneNum = mphoneNum;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement