nord vpnnord vpn
Ad

Untitled

mail@pastecode.io avatar
unknown
java
a year ago
9.5 kB
1
Indexable
Never
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;

public class address extends address_main {
    public static List<address> addressList = new ArrayList<>();
    private String name, address, phonenum, email;

    public address(String name, String address, String phonenum, String email) {
        this.name = name;
        this.address = address;
        this.phonenum = phonenum;
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhonenum() {
        return phonenum;
    }

    public void setPhonenum(String phonenum) {
        this.phonenum = phonenum;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public static void main(String[] args) {

    }

    static void addEntry() {
        Scanner in = new Scanner(System.in).useDelimiter("\n");
        System.out.println("========================");
        System.out.println("\t\tAdd Entry");
        System.out.println("========================");

        System.out.print("\nEnter Name: ");
        String addName = in.next();

        for (address counter : addressList) {
            if (addName.equalsIgnoreCase(counter.getName())) {
                System.out.println(addName + " is already been registered!");
                return;
            }
        }
        System.out.print("Enter Address: ");
        String addAddress = in.next();
        System.out.print("Enter Phone Number: ");
        String addPhoneNum = in.next();
        System.out.print("Enter Email Address: ");
        String addEmail = in.next();

        address add_address = new address(addName, addAddress, addPhoneNum, addEmail);
        addressList.add((add_address));

        System.out.println(addName + " has been added on the entries");
    }

    static void deleteEntry() {
        Scanner in = new Scanner(System.in).useDelimiter("\n");
        System.out.println("========================");
        System.out.println("\t Delete Entry");
        System.out.println("========================");

        if (addressList.isEmpty()) {
            System.out.println("There is no Entries in the data base!");
            return;
        }

        System.out.println("Enter Name: ");
        String deleteEntry = in.next();


        for (address counter : addressList) {
            if (counter.getName() == deleteEntry) {
                System.out.println(deleteEntry + " is already registered");
                return;
            } else if (deleteEntry.equalsIgnoreCase(counter.getName())) {
                addressList.remove(counter);
                System.out.println(counter.name + " has been removed from the entries");
                return;
            }

        }
    }

    static void viewEntries() {
        Scanner in = new Scanner(System.in).useDelimiter("\n");
        System.out.println("========================================================================");
        System.out.println("\t View all Entries");
        System.out.println("========================================================================");

        if (addressList.isEmpty()) {
            System.out.println("There is no Entries in the data base!");
        } else {
            System.out.println("NAME\t\t\t\tADDRESS\t\t\t\tPHONE NUMBER\t\t\t\tEMAIL ADDRESS\n");
            for (address counter : addressList) {
                System.out.println(counter.getName() + "\t\t\t\t" + counter.getAddress() + "\t\t\t\t" + counter.getPhonenum() + "\t\t\t\t\t" + counter.getEmail());
            }
        }
    }

    static void updateEntries() {
        Scanner in = new Scanner(System.in).useDelimiter("\n");
        System.out.println("========================");
        System.out.println("\t Update Entry");
        System.out.println("========================");

        if (addressList.isEmpty()) {
            System.out.println("There is no Entries in the data base!");
            return;
        }

        System.out.println("Enter the name to be updated: ");
        String updateEntry = in.next();


        for (address counter : addressList) {
            if (updateEntry.equalsIgnoreCase(counter.getName())) {
                System.out.println("\n\nWelcome " + counter.getName());
                System.out.println("Address : " + counter.getAddress());
                System.out.println("Phone Number : " + counter.getPhonenum());
                System.out.println("Email Address : " + counter.getEmail());
                System.out.println("\nChange: ");
                System.out.println("[1] Name");
                System.out.println("[2] Address");
                System.out.println("[3] Phone Number");
                System.out.println("[4] Email Address");

                    switch (Main.choice()) {
                        case 1:
                                System.out.println("========================");
                                System.out.println("\t Change Name");
                                System.out.println("========================");
                                System.out.println("\nEnter new name: ");
                                String updateName = in.next();

                                for (address iterswitch : addressList) {
                                    if (iterswitch.getName().equalsIgnoreCase(updateName)) {
                                        System.out.println(iterswitch.getName() + " is existing in the database!");
                                        return;
                                    } else {
                                        System.out.println(counter.getName() + " has been changed to " + updateName + "!!");
                                        counter.setName(updateName);
                                        return;

                                    }
                                }
                            break;
                        case 2:
                            System.out.println("========================");
                            System.out.println("\t Change Address");
                            System.out.println("========================");
                            System.out.println("\nEnter new Address: ");
                            String updateAddress = in.next();

                            System.out.println(counter.getAddress() + " has been changed to " + updateAddress + "!!");
                            counter.setAddress(updateAddress);
                            break;
                        case 3:
                            System.out.println("========================");
                            System.out.println("\t Change Phone Number");
                            System.out.println("========================");
                            System.out.println("\nEnter new Phone Number: ");
                            String updatePhonenum = in.next();

                            for (address iterswitch : addressList) {
                                if (iterswitch.getPhonenum().equalsIgnoreCase(updatePhonenum)) {
                                    System.out.println(iterswitch.getPhonenum() + " is existing in the database!");
                                    return;
                                } else {
                                    System.out.println(counter.getPhonenum() + " has been changed to " + updatePhonenum + "!!");
                                    counter.setPhonenum(updatePhonenum);
                                    return;
                                }
                            }
                            break;
                        case 4:
                            System.out.println("========================");
                            System.out.println("\t Change Email");
                            System.out.println("========================");
                            System.out.println("\nEnter new Email: ");
                            String updateEmail = in.next();

                            for (address iterswitch : addressList) {
                                if (iterswitch.getEmail().equalsIgnoreCase(updateEmail)) {
                                    System.out.println(iterswitch.getEmail() + " is existing in the database!");
                                    return;
                                } else {
                                    System.out.println(counter.getEmail() + " has been changed to " + updateEmail + "!!");
                                    counter.setEmail(updateEmail);
                                    return;
                                }
                            }
                            break;
                        default:
                            System.out.println("Invalid input! Try again");
                            return;
                    }
                }
            }
        }
    }


nord vpnnord vpn
Ad