0 امتیاز
قبل در برنامه نویسی توسط (10 امتیاز)
ویرایش شده قبل توسط
package phonebook;

import java.util.ArrayList;
import java.util.Scanner;

public class PhoneBook {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        ArrayList<Contact> contactList = new ArrayList<>();
        int counter = 1;
        String name;
        String number;
        String details;


        while (true) {
            System.out.println();
            System.out.println("Choose number (just number):");
            System.out.println("1. Add Contact");
            System.out.println("2. Show Contacts");
            System.out.println("3. Search");
            System.out.println("4. Exit");
            System.out.println("*-*-*-*-*-*-*-*-*-*");
            int menu = scanner.nextInt();
            scanner.nextLine();


            switch (menu) {


                case 1:
                    do {
                        System.out.println(counter + " Contact");
                        System.out.println("Enter Contact Name :");
                        name = scanner.nextLine();
                    } while (name.isEmpty());

                    do {
                        System.out.println("Enter Contact Number With 11 Character And Start With 0 :");
                        number = scanner.nextLine();
                    } while (number.length() != 11 || !number.startsWith("0"));
                    System.out.println("If You Want Enter Some Detaile :");
                    details = scanner.nextLine();
                    contactList.add(new Contact(counter, name, number, details));
                    counter++;
                    System.out.println("Contact Successfully Saved");
                    break;


                case 2:
                    System.out.println("Your PhoneBook:");
                    for (Contact contact : contactList) {
                        System.out.println(contact);
                       // System.out.println(contactList.sort(name));

                    }
                    break;


                case 3: {
                    System.out.println("Enter Word :");
                    String search = scanner.nextLine();
                    
                        }

                case 4:
                    System.out.println("Finish");
                    System.exit(0);
                    break;
                default:
                    System.out.println("ERROR.Enter Correct Number!!!!!!");

            }


        }
    }
}






**************************************************************************************************

**************************************************************************************************

**************************************************************************************************

**************************************************************************************************

**************************************************************************************************




package phonebook;
public class Contact
{
    int counter;
    String name;
    String number;
    String details;

    public Contact(int counter, String name, String number,String details) {
        this.counter = counter;
        this.name = name;
        this.number = number;
        this.details = details;
    }

    @Override
    public String toString() {
        return counter+". " +name+ " " +number+ "  " + details;
    }
}

سوالات مشابه

+1 امتیاز
1 پاسخ 624 بازدید
+1 امتیاز
1 پاسخ 1.5هزار بازدید
+2 امتیاز
2 پاسخ 892 بازدید
+1 امتیاز
1 پاسخ 1.9هزار بازدید
+1 امتیاز
1 پاسخ 1.1هزار بازدید
0 امتیاز
1 پاسخ 1.6هزار بازدید
+1 امتیاز
1 پاسخ 1.4هزار بازدید
0 امتیاز
1 پاسخ 578 بازدید
...