public void nhap(String tieuDe) {
System.out.println(tieuDe);
Scanner scan = new Scanner (System.in);
System.out.print("Name:");
this.name = scan.nextLine();
System.out.print("Phonenumber:");
this.phonenumber = scan.nextLine();
System.out.print("ADDRESS:");
this.diaChi = scan.nextLine();
}
public void xuat(String tieuDe) {
System.out.println(tieuDe);
String S = String.format("%20s %10s %20s", this.name, this.phonenumber, this.diaChi);
System.out.println(S);
}
public void INPUT() {
int s = 0;
Scanner scan = new Scanner(System.in);
System.out.print("Số lượng người trong danh bạ:");
int n = Integer.parseInt(scan.nextLine());
this.list = new Person[n];
for(int i = 0; i < n; i++){
System.out.println("Nhập contact thứ " + (i + 1));
list[i] = new Person();
list[i].nhap("Nhập thông tin người dùng");
s++;
}
}
public void VIEW() {
int s = 0;
Scanner scan = new Scanner(System.in);
System.out.print("Số lượng người trong danh bạ:");
int n = Integer.parseInt(scan.nextLine());
for (int i = 0; i < n; i++) {
this.list = new Person[n];
list[i] = new Person();
System.out.println("===THÔNG TIN LIÊN HỆ===");
if (this.list[i] instanceof Person) {
list[i].xuat("Thông tin contact thứ " + (i + 1));
list[i].xuat("Xuất thông tin người dùng");
System.out.printf("%-15s %-15s %-15s", "TÊN","SĐT","ĐỊA CHỈ");
System.out.println();
s++;
}
}
}
public class Main {
public static void main(String[] args) {
while(true) {
System.out.println("CHƯƠNG TRÌNH QUẢN LÝ DANH BẠ ĐIỆN THOẠI");
System.out.println("SELECT ONE");
System.out.println("1.NHẬP LIÊN HỆ/THÊM LIÊN HỆ");
System.out.println("2.XEM LIÊN HỆ");
System.out.println("3.THAY ĐỔI SỐ ĐIỆN THOẠI CỦA 1 LIÊN HỆ");
System.out.println("4.XÓA LIÊN HỆ");
System.out.println("5.TÌM 1 LIÊN HỆ");
System.out.println("6.SẮP XẾP TRẬT TỰ ABC CỦA CÁC LIÊN HỆ");
System.out.println("7.THOÁT CHƯƠNG TRÌNH");
int c;
Scanner scan = new Scanner(System.in);
System.out.print("NHẬP LỰA CHỌN CỦA BẠN: ");
c = scan.nextInt();
PHONEBOOK PB = new PHONEBOOK();
switch(c) {
case 1:{
PB.INPUT();
break;
}
case 2:{
PB.VIEW();
break;
}
--------Phía trên là đoạn code mình đã viết-----------
RUN:
===THÔNG TIN LIÊN HỆ===
Thông tin contact thứ 1
Xuất thông tin người dùng
TÊN SĐT ĐỊA CHỈ
===THÔNG TIN LIÊN HỆ===
Thông tin contact thứ 2
Xuất thông tin người dùng
TÊN SĐT ĐỊA CHỈ
Lúc chạy mình chọn option 1 nhập ok, nhưng chọn option 2 xuất nó chỉ ra line xuất không xuất được thông tin mình đã nhập, mình có thiếu dòng lệnh nào, mọi người giúp mình với
Mình muốn biết cách làm sao liên kết được các hàm void với nhau để làm tiếp chức năng TÌM KIẾM, XÓA, SỬA, THÊM thông tin, mong mọi người chỉ hướng làm cho mình, mình mới nhập môn Java OOP, nên không thể làm theo <ArrayList được, giảng viên bảo mình phải làm theo dạng khai báo Mảng.