By GokiSoft.com| 07:00 08/02/2020|
Java Basic

Java basic- Assignment - Quản lý sách BT1006

Xây dựng menu chương trình như sau.

Menu :

1. Nhập thông tin sách

2. Hiển thị tất cả sách ra màn hình

3. Nhập thông tin tác giả

4. Tìm kiếm tất cả sách được viết bởi tác giả

5. Thoát

Choose : ???

Yêu cầu :

Thiết kế lớp đối tượng tác giả gồm các thuộc tính sau (Tên, tuổi, bút danh, ngày sinh, quê quán) 

- Chú ý : cài đặt tất cả các thuộc tính chỉ có thuộc tính đọc dữ liệu

- Tạo các hàm tạo ko đối và đầy đủ đối số

- Tạo phương thức nhập thông tin tác giả, và xem thông tin tác giả

- Chú ý : Mỗi tác giả có bút danh duy nhất, ko được phép nhập trùng lặp tên bút danh của tác giả

Thiết kế lớp book gồm các thuộc tín : Tên sách, ngày xuất bản, but danh

- Cài đặt get/set cho các thuộc tính, hàm tạo ko đối và đầy đủ tham số

- Tạo hàm nhập và xem thông tin sách

- Chú ý : Khi nhập tên bút danh của tác giả, nếu chưa tồn tại thì -> Xuất hiện màn hình nhập thông tin cho tác giả đó luôn.

Xây dựng từng chức năng chương trình

Khi người dùng chọn 1 : Hỏi người dùng nhập số sách cần thêm -> sau đó nhập thông tin cho từng quấn sách -> và lưa vào 1 list.

Khi người dùng chọn 2 : In tất cả thông tin quấn sách.

Khi người dùng chon 3 : Hỏi người dùng nhập số tác giả -> Nhập thông tin tác giả.

Khi người dùng chọn 4 : Hiển thị màn hình nhập bút danh cần tìm -> in ra quấn sach của tác giả đó

Khi người dùng chọn 5 : Thoát chương trình.

Liên kết rút gọn:

https://gokisoft.com/1006

Bình luận

avatar
Lê Minh Bắc [T1907A]
2020-03-16 07:09:23



package assignment;
import java.util.Scanner;
import java.util.ArrayList;
public class main {
    public static void main(String[] args) {
       int choose, n;
       
       ArrayList<Author> authorList = new ArrayList<>();
       ArrayList<Book> bookList = new ArrayList<>();
       
       Scanner input = new Scanner(System.in);
       do{
           ShowMenu();
           choose = Integer.parseInt(input.nextLine());
           
           switch(choose){
               case 1:
                   System.out.println("Nhap so sach can them: ");
                   n = Integer.parseInt(input.nextLine());
                   for (int i = 0; i < n; i++) {
                       Book book = new Book();
                       book.input();
                       boolean isFind = false;
                       for (int j = 0; j < authorList.size(); j++) {
                           if(authorList.get(j).getPseudonym().equalsIgnoreCase(book.getPseudonym())){
                               isFind = true;
                               break;
                           }
                       }if(!isFind){
                           Author author = new Author(book.getPseudonym());
                           author.input();
                           authorList.add(author);
                       }
                       bookList.add(book);
                   }
                   break;
               case 2:
                   for (Book book : bookList) {
                       book.display();
                   }
                   break;
               case 3:
                   System.out.println("Nhap so tac gia can them: ");
                   n = Integer.parseInt(input.nextLine());
                   
                   for (int i = 0; i < n; i++) {
                       Author author = new Author();
                       author.input(authorList);
                       authorList.add(author);
                   }
                   break;
               case 4:
                   System.out.println("Nhap ten but danh can tim: ");
                   String pseudonym = input.nextLine();
                   
                   for (int i = 0; i < bookList.size(); i++) {
                       if(bookList.get(i).getPseudonym().equalsIgnoreCase(pseudonym)){
                           bookList.get(i).display();
                       }
                   }
                   break;
               case 5:
                   System.out.println("BaiBaiiii!");
                   break;
               default:
                   System.err.println("Error...");
                   break;
           }
       }while(choose != 5);
    }
    
    static void ShowMenu() {
        System.out.println("1. Nhap thong tin sach");
        System.out.println("2. Hien thi tat ca sach ra man hinh");
        System.out.println("3. Nhap thong tin tac gia");
        System.out.println("4. Tim kiem sach theo but danh");
        System.out.println("5. Thoat");
        System.out.print("Nhap: ");
    }
}



package assignment;
import java.util.ArrayList;
import java.util.Scanner;
public class Author {
    private String name;
    private int age;
    private String pseudonym;
    private String birthday;
    private String address;

    public Author() {
    }

    public Author(String pseudonym) {
        this.pseudonym = pseudonym;
    }

    public Author(String name, int age, String pseudonym, String birthday, String address) {
        this.name = name;
        this.age = age;
        this.pseudonym = pseudonym;
        this.birthday = birthday;
        this.address = address;
    }
    
    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public String getPseudonym() {
        return pseudonym;
    }

    public String getBirthday() {
        return birthday;
    }

    public String getAddress() {
        return address;
    }
    
    public void input(ArrayList<Author> authorList){
        
        input(); 
        Scanner input = new Scanner(System.in);
        
        System.out.println("Nhap but danh: ");
        while(true){
            pseudonym = input.nextLine();
            boolean isFind = false;
            for (int i = 0; i < authorList.size(); i++) {
                if(authorList.get(i).getPseudonym().equalsIgnoreCase(pseudonym)){
                    isFind = true;
                    break;
                }
            }
            if(!isFind){
                break;
            }else{
                System.err.println("Nhap but danh khac: ");
            }
        }
    }
    
    public void input(){
        System.out.println("=============================");
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap ten tac gia: ");
        name = input.nextLine();
        
        System.out.println("Nhap tuoi: ");
        age = Integer.parseInt(input.nextLine());
        
        System.out.println("Nhap ngay sinh: ");
        birthday = input.nextLine();
        
        System.out.println("Nhap dia chi: ");
        address = input.nextLine();
    }
    
    public void display(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Author{" + "name=" + name + ", age=" + age + ", pseudonym=" + pseudonym + ", birthday=" + birthday + ", address=" + address + '}';
    }
}



package assignment;
import java.util.Scanner;
public class Book {
    String BookName;
    String PublicationDate;
    String Pseudonym;

    public Book() {
    }

    public Book(String BookName, String PublicationDate, String pseudonym) {
        this.BookName = BookName;
        this.PublicationDate = PublicationDate;
        this.Pseudonym = pseudonym;
    }

    public String getBookName() {
        return BookName;
    }

    public void setBookName(String BookName) {
        this.BookName = BookName;
    }

    public String getPublicationDate() {
        return PublicationDate;
    }

    public void setPublicationDate(String PublicationDate) {
        this.PublicationDate = PublicationDate;
    }

    public String getPseudonym() {
        return Pseudonym;
    }

    public void setPseudonym(String pseudonym) {
        this.Pseudonym = pseudonym;
    }
    
    public void input() {
        System.out.println("=============================");
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap ten sach: ");
        BookName = input.nextLine();
        
        System.out.println("Ngay xuat ban: ");
        PublicationDate = input.nextLine();
        
        System.out.println("Nhap but danh: ");
        Pseudonym = input.nextLine();
    }
    
    public void display() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Book{" + "BookName=" + BookName + ", PublicationDate=" + PublicationDate + ", Pseudonym=" + Pseudonym + '}';
    }
}


avatar
Phạm Ngọc Minh [T1907A]
2020-03-15 17:19:26



package AssiQLS;

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


public class Main {
    public static void main(String[] args) {
        List<Author> listAuthor = new ArrayList<>();
        List<Book> listBook = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        int choose;

        do {
            showmenu();
            choose = Integer.parseInt(scanner.nextLine());
            switch (choose) {
                case 1:
                    boolean check = false;
                    System.out.println("Nhap thong tin sach");
                    Book bk = new Book();
                    bk.input();
                    for (int i = 0; i < listAuthor.size(); i++) {
                        if (bk.getNickname().equalsIgnoreCase(listAuthor.get(i).getNickname())) {
                            check = true;
                            break;
                        }
                    }
                    if (check) {
                        listBook.add(bk);
                    } else {
                        Author author = new Author(bk.getNickname());
                        author.input();
                        listAuthor.add(author);
                        listBook.add(bk);

                    }
                case 2:
                    listBook.forEach((listBook1) -> {
                        listBook1.display();
                });
                    break;

                case 3:
                    Author author = new Author();
                    author.input(listAuthor);
                    listAuthor.add(author);
                    listAuthor.forEach((author1) -> {
                        author1.display();
                });

                case 4:
                    String butdanh = scanner.nextLine();
                    for (int i = 0; i < listBook.size(); i++) {
                        if (butdanh.equalsIgnoreCase(listBook.get(i).getNickname())) {
                            listBook.get(i).display();
                        }
                    }
                    break;
                case 5:
                    System.out.println("Exit ");
                    break;
                default:
                    System.out.println("Nhap sai roi");
                    break;
            }
        } while (choose != 5);
    }

    public static void showmenu() {
        System.out.println("1. Nhap thong tin sach");
        System.out.println("2. Hien thi tat ca sach ra man hinh");
        System.out.println("3. Nhap thong tin tac gia");
        System.out.println("4. TIm kiem tat ca sach duoc viet boi tac gia");
        System.out.println("5: Thoat");
        System.out.println("Choose: ");
    }
}



package AsiiQLS;

import java.util.List;
import java.util.Scanner;

public class Author {
    public String name;
    public int old;
    public String nickname;
    public String birthday;
    public String address;

    public Author() {
    }

    public Author(String nickname) {
        this.nickname = nickname;
    }

    public Author(String name, int old, String nickname, String birthday, String address) {
        this.name = name;
        this.old = old;
        this.nickname = nickname;
        this.birthday = birthday;
        this.address = address;
    }

    public void input(List<Author> listAuthor) {
        Scanner sc = new Scanner(System.in);
        input();
        while (true) {
            System.out.println("Nhap but danh tac gia");
            nickname = sc.nextLine();
            boolean a = true;
            for (int i = 0; i < listAuthor.size(); i++) {
                if (nickname.equalsIgnoreCase(listAuthor.get(i).getNickname())) {
                    a = false;
                }
            }
            if (a) {
                break;
            } else {
                System.err.println("nickname da ton tai");
            }
        }

    }

    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap ten tac gia:");
        name = sc.nextLine();
        System.out.println("Nhap tuoi tac gia");
        old = Integer.parseInt(sc.nextLine());
        System.out.println("Nhap dia chi:");
        address = sc.nextLine();
    }

    public void display() {
        System.out.println(toString());
    }

    public String getName() {
        return name;
    }

    public int getOld() {
        return old;
    }

    public String getNickname() {
        return nickname;
    }

    public String getBirthday() {
        return birthday;
    }

    public String getAddress() {
        return address;
    }

    @Override
    public String toString() {
        return "Author{" + "name=" + name + ", old=" + old + ", nickname=" + nickname + ", birthday=" + birthday + ", address=" + address + '}';
    }
}



package AssiQLS;

import java.util.Scanner;

public class Book {
     String bookName;
    String createdAt;
    String nickname;

    public Book() {
    }

    public Book(String bookName, String createdAt, String nickname) {
        this.bookName = bookName;
        this.createdAt = createdAt;
        this.nickname = nickname;
    }

    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap ten sach: ");
        bookName = input.nextLine();

        System.out.println("Ngay xuat ban: ");
        createdAt = input.nextLine();
        System.out.println("Nhap but danh");
        nickname = input.nextLine();
    }

    public void display() {
        System.out.println(toString());
    }

    public String getBookName() {
        return bookName;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public String getNickname() {
        return nickname;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    @Override
    public String toString() {
        return "Book{" + "bookName=" + bookName + ", createdAt=" + createdAt + ", nickname=" + nickname + '}';
    }
}


avatar
Trần Anh Quân [T1907A]
2020-03-15 17:14:20



package QuanLiSach;

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

/**
 *
 * @author Anh Quan
 */
public class Main {
    public static void main(String[] args) {
        List<Author> listAuthor = new ArrayList<>();
        List<Book> listBook = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        int choose;

        do {
            showmenu();
            choose = Integer.parseInt(scanner.nextLine());
            switch (choose) {
                case 1:
                    boolean check = false;
                    System.out.println("Nhap thong tin sach");
                    Book bk = new Book();
                    bk.input();
                    for (int i = 0; i < listAuthor.size(); i++) {
                        if (bk.getNickname().equalsIgnoreCase(listAuthor.get(i).getNickname())) {
                            check = true;
                            break;
                        }
                    }
                    if (check) {
                        listBook.add(bk);
                    } else {
                        Author author = new Author(bk.getNickname());
                        author.input();
                        listAuthor.add(author);
                        listBook.add(bk);

                    }
                case 2:
                    listBook.forEach((listBook1) -> {
                        listBook1.display();
                });
                    break;

                case 3:
                    Author author = new Author();
                    author.input(listAuthor);
                    listAuthor.add(author);
                    listAuthor.forEach((author1) -> {
                        author1.display();
                });

                case 4:
                    String butdanh = scanner.nextLine();
                    for (int i = 0; i < listBook.size(); i++) {
                        if (butdanh.equalsIgnoreCase(listBook.get(i).getNickname())) {
                            listBook.get(i).display();
                        }
                    }
                    break;
                case 5:
                    System.out.println("Exit ");
                    break;
                default:
                    System.out.println("Nhap sai roi");
                    break;
            }
        } while (choose != 5);
    }

    public static void showmenu() {
        System.out.println("1. Nhap thong tin sach");
        System.out.println("2. Hien thi tat ca sach ra man hinh");
        System.out.println("3. Nhap thong tin tac gia");
        System.out.println("4. TIm kiem tat ca sach duoc viet boi tac gia");
        System.out.println("5: Thoat");
        System.out.println("Choose: ");
    }
}



package QuanLiSach;

import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Anh Quan
 */
public class Author {
    public String name;
    public int old;
    public String nickname;
    public String birthday;
    public String address;

    public Author() {
    }

    public Author(String nickname) {
        this.nickname = nickname;
    }

    public Author(String name, int old, String nickname, String birthday, String address) {
        this.name = name;
        this.old = old;
        this.nickname = nickname;
        this.birthday = birthday;
        this.address = address;
    }

    public void input(List<Author> listAuthor) {
        Scanner sc = new Scanner(System.in);
        input();
        while (true) {
            System.out.println("Nhap but danh tac gia");
            nickname = sc.nextLine();
            boolean a = true;
            for (int i = 0; i < listAuthor.size(); i++) {
                if (nickname.equalsIgnoreCase(listAuthor.get(i).getNickname())) {
                    a = false;
                }
            }
            if (a) {
                break;
            } else {
                System.err.println("nickname da ton tai");
            }
        }

    }

    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap ten tac gia:");
        name = sc.nextLine();
        System.out.println("Nhap tuoi tac gia");
        old = Integer.parseInt(sc.nextLine());
        System.out.println("Nhap dia chi:");
        address = sc.nextLine();
    }

    public void display() {
        System.out.println(toString());
    }

    public String getName() {
        return name;
    }

    public int getOld() {
        return old;
    }

    public String getNickname() {
        return nickname;
    }

    public String getBirthday() {
        return birthday;
    }

    public String getAddress() {
        return address;
    }

    @Override
    public String toString() {
        return "Author{" + "name=" + name + ", old=" + old + ", nickname=" + nickname + ", birthday=" + birthday + ", address=" + address + '}';
    }
}



package QuanLiSach;

import java.util.Scanner;

/**
 *
 * @author Anh Quan
 */
public class Book {
     String bookName;
    String createdAt;
    String nickname;

    public Book() {
    }

    public Book(String bookName, String createdAt, String nickname) {
        this.bookName = bookName;
        this.createdAt = createdAt;
        this.nickname = nickname;
    }

    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap ten sach: ");
        bookName = input.nextLine();

        System.out.println("Ngay xuat ban: ");
        createdAt = input.nextLine();
        System.out.println("Nhap but danh");
        nickname = input.nextLine();
    }

    public void display() {
        System.out.println(toString());
    }

    public String getBookName() {
        return bookName;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public String getNickname() {
        return nickname;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    @Override
    public String toString() {
        return "Book{" + "bookName=" + bookName + ", createdAt=" + createdAt + ", nickname=" + nickname + '}';
    }
}


avatar
NguyenHuuThanh [T1907A]
2020-03-15 09:44:20



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Assignment03;
import java.util.Scanner;
/**
 *
 * @author Minh
 */
public class Author {
    String name;
    Integer age;
    String butdanh;
    String birthday;
    String country;
    
    public Author()
    {
        
    }

    public Author(String name, Integer age, String butdanh, String birthday, String country) {
        this.name = name;
        this.age = age;
        this.butdanh = butdanh;
        this.birthday = birthday;
        this.country = country;
    }

    public String getName() {
        return name;
    }

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

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getButdanh() {
        return butdanh;
    }

    public void setButdanh(String butdanh) {
        this.butdanh = butdanh;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }
    
    public void input()
    {
        Scanner scan = new Scanner(System.in);
        name = scan.nextLine();
        butdanh = scan.nextLine();
        birthday = scan.nextLine();
        country = scan.nextLine();
        age =Integer.parseInt(scan.nextLine());
    }
    public void display()
    {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Author{" + "name=" + name + ", age=" + age + ", butdanh=" + butdanh + ", birthday=" + birthday + ", country=" + country + '}';
    }
    
    public void nhap()
    {
        Scanner scan = new Scanner(System.in);
        name = scan.nextLine();
        birthday = scan.nextLine();
        country = scan.nextLine();
        age =Integer.parseInt(scan.nextLine());
    }

   
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Assignment03;
import java.util.Scanner;
import java.util.ArrayList;
/**
 *
 * @author Minh
 */
public class Book {
    String bookname;
    String datepublish;
    String butdanh;
    
    public Book(){
        
    }

    public Book(String bookname, String datepublish, String butdanh) {
        this.bookname = bookname;
        this.datepublish = datepublish;
        this.butdanh = butdanh;
    }

    public String getBookname() {
        return bookname;
    }

    public void setBookname(String bookname) {
        this.bookname = bookname;
    }

    public String getDatepublish() {
        return datepublish;
    }

    public void setDatepublish(String datepublish) {
        this.datepublish = datepublish;
    }

    public String getButdanh() {
        return butdanh;
    }

    public void setButdanh(String butdanh) {
        this.butdanh = butdanh;
    }
    public void input(ArrayList<Author> author)
    {
        input();
       for(int i = 0; i < author.size(); i++)
       {
           if (!butdanh.equalsIgnoreCase(author.get(i).getButdanh()))
           {
               Author at = new Author();
               at.nhap();
               at.display();
               author.add(at);
           }
           else
           {
               break;
           }
       }
        
    }
    public void input()
    {
        
       Scanner scan = new Scanner(System.in);
        bookname = scan.nextLine();
        datepublish = scan.nextLine();
        butdanh = scan.nextLine();
    }
    public void display()
    {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Book{" + "bookname=" + bookname + ", datepublish=" + datepublish + ", butdanh=" + butdanh + '}';
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Assignment03;
import java.util.Scanner;
import java.util.ArrayList;
/**
 *
 * @author Minh
 */
public class Main {
    public static void main(String[] args)
    {
        ArrayList<Book> bk1 = new ArrayList<>();
        ArrayList<Author> at1 = new ArrayList<>();
        Scanner scan = new Scanner(System.in);
        int choice;
        
        do
        {
            showMenu();
            System.out.println("Nhap");
            choice = Integer.parseInt(scan.nextLine());
            
            
            switch(choice)
            {
                case 1 :
                    System.out.println("Nhap so sach can them");
                    int n = Integer.parseInt(scan.nextLine());
                    for(int i = 0 ; i < n ; i++)
                    {
                        Book bk = new Book();
                        bk.input();
                        bk1.add(bk);
                    }
                    break;
                case 2 :
                    for (int i = 0 ; i< bk1.size(); i++)
                    {
                        bk1.get(i).display();
                    }
                    break;
                case 3 :
                    System.out.println("Nhap so tac gia can them");
                    int n1 = Integer.parseInt(scan.nextLine());
                    for ( int i1 = 0 ; i1 < n1 ; i1++)
                    {
                        Author at = new Author();
                        at.input();
                        at1.add(at);
                    }
                    break;
                case 4 :
                    System.out.println("Nhap but danh can tim");
                    String bd = scan.nextLine();
                    for (int x =0 ; x < at1.size();x++)
                    {
                        if(bd.equalsIgnoreCase(at1.get(x).getButdanh()))
                        {
                            for(int k = 0; k < bk1.size(); k++)
                            {
                                if (bk1.get(k).getButdanh().equalsIgnoreCase(at1.get(x).getButdanh()))
                                {
                                    bk1.get(k).display();
                                }
                            }
                        }
                    }
                    
                    break;
                case 5 :
                    System.out.println("Thoat");
                    break;
                
                
                
                
                
            }
        }while(choice!=5);
        
       
        
    }
    public static void showMenu()
    {
        System.out.println("1. List sach");
        System.out.println("2. Show list sach");
        System.out.println("3. Age - > Tacgia");
        System.out.println("4 Butdanh -> Sach");
        System.out.println("5.Thoat");
    }
    
}


avatar
lê văn phương [T1907A]
2020-03-15 03:42:01



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package quanlysach;

import java.util.Scanner;

/**
 *
 * @author HOME
 */public class Book {

    String bookName;
    String createdAt;
    String nickname;

    public Book() {
    }

    public Book(String bookName, String createdAt, String nickname) {
        this.bookName = bookName;
        this.createdAt = createdAt;
        this.nickname = nickname;
    }

    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap ten sach: ");
        bookName = input.nextLine();

        System.out.println("Ngay xuat ban: ");
        createdAt = input.nextLine();
        System.out.println("Nhap but danh");
        nickname = input.nextLine();
    }

    public void display() {
        System.out.println(toString());
    }

    public String getBookName() {
        return bookName;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public String getNickname() {
        return nickname;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    @Override
    public String toString() {
        return "Book{" + "bookName=" + bookName + ", createdAt=" + createdAt + ", nickname=" + nickname + '}';
    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package quanlysach;

import java.util.List;
import java.util.Scanner;

/**
 *
 * @author HOME
 */

public class Author {

    private String name;
    private int old;
    private String nickname;
    private String birthday;
    private String address;

    public Author() {
    }

    public Author(String nickname) {
        this.nickname = nickname;
    }

    public Author(String name, int old, String nickname, String birthday, String address) {
        this.name = name;
        this.old = old;
        this.nickname = nickname;
        this.birthday = birthday;
        this.address = address;
    }

    public void input(List<Author> listAuthor) {
        Scanner sc = new Scanner(System.in);
        input();
        while (true) {
            System.out.println("Nhap butdanh tac gia");
            nickname = sc.nextLine();
            boolean a = true;
            for (int i = 0; i < listAuthor.size(); i++) {
                if (nickname.equalsIgnoreCase(listAuthor.get(i).getNickname())) {
                    a = false;
                }
            }
            if (a) {
                break;
            } else {
                System.err.println("nickname da ton tai");
            }
        }

    }

    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap ten tac gia:");
        name = sc.nextLine();
        System.out.println("Nhap tuoi tac gia");
        old = Integer.parseInt(sc.nextLine());
        System.out.println("Nhap dia chi:");
        address = sc.nextLine();
    }

    public void display() {
        System.out.println(toString());
    }

    public String getName() {
        return name;
    }

    public int getOld() {
        return old;
    }

    public String getNickname() {
        return nickname;
    }

    public String getBirthday() {
        return birthday;
    }

    public String getAddress() {
        return address;
    }

    @Override
    public String toString() {
        return "Author{" + "name=" + name + ", old=" + old + ", nickname=" + nickname + ", birthday=" + birthday + ", address=" + address + '}';
    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package quanlysach;

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

/**
 *
 * @author HOME
 */
public class QuanLySach {
    
    public static void main(String[] args) {
        List<Author> listAuthor = new ArrayList<>();
        List<Book> listBook = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        int choose;

        do {
            showmenu();
            choose = Integer.parseInt(sc.nextLine());
            switch (choose) {
                case 1:
                    boolean check = false;
                    System.out.println("Nhap thong tin sach");
                    Book bk = new Book();
                    bk.input();
                    for (int i = 0; i < listAuthor.size(); i++) {
                        if (bk.getNickname().equalsIgnoreCase(listAuthor.get(i).getNickname())) {
                            check = true;
                            break;
                        }
                    }
                    if (check) {
                        listBook.add(bk);
                    } else {
                        Author author = new Author(bk.getNickname());
                        author.input();
                        listAuthor.add(author);
                        listBook.add(bk);

                    }
                case 2:
                    for (Book listBook1 : listBook) {
                        listBook1.display();
                    }
                    break;
                case 3:
                    Author author = new Author();
                    author.input(listAuthor);
                    listAuthor.add(author);
                    for (Author author1 : listAuthor) {
                        author1.display();
                    }
                case 4:
                    String butdanh = sc.nextLine();
                    for (int i = 0; i < listBook.size(); i++) {
                        if (butdanh.equalsIgnoreCase(listBook.get(i).getNickname())) {
                            listBook.get(i).display();
                        }
                    }
                    break;
                case 5:
                    System.out.println("Exit thanh cong");
                    break;
                default:
                    System.out.println("Nhap sai roi");
                    break;
            }
        } while (choose != 5);
    }

    public static void showmenu() {
        System.out.println("1. Nhập thông tin sách");
        System.out.println("2. Hiển thị tất cả sách ra màn hình");
        System.out.println("3. Nhập thông tin tác giả");
        System.out.println("4. Tìm kiếm tất cả sách được viết bởi tác giả");
        System.out.println("5: Thoat");
        System.out.println("Choose: ");
    }
}


avatar
nguyễn văn huy [T1907A]
2020-03-15 00:21:46



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QLSach;

import java.util.*;

/**
 *
 * @author ASUS
 */
public class Main {

    public static void main(String[] args) {
        Scanner huy = new Scanner(System.in);
        ArrayList<TacGia> tacgiaList= new ArrayList<>();
        ArrayList<Book> bookList = new ArrayList<>();
        int choise;
        int n;
        do {
            menu();
            choise = Integer.parseInt(huy.nextLine());
            switch (choise) {
                case 1:
                    System.out.println("nhap thong tin cuon sach");
                    n=Integer.parseInt(huy.nextLine());
                    Book book=new Book();
                    book.huy();
                    boolean thao =false;//chua tim thay
                    for (int j = 0; j < tacgiaList.size(); j++) {
                        if(tacgiaList.get(j).getNickName().equalsIgnoreCase(book.getNickName())){
                            thao=true;
                            break;
                        }
                    }
                    if(!thao){//khi chua tim thay nickName
                        TacGia tacgia=new TacGia(book.getNickName());
                        tacgia.huy();
                        tacgiaList.add(tacgia);
                    }
                    bookList.add(book);
                    break;
                case 2:
                    for (TacGia tacgia:tacgiaList) {
                        tacgia.display();
                    }
                    break;
                case 3:
                    System.out.println("nhap so tac gia");
                    n=Integer.parseInt(huy.nextLine());
                    
                    for (int i = 0; i < n; i++) {
                        TacGia tacgia=new TacGia();
                        tacgia.huy(tacgiaList);
                        tacgiaList.add(tacgia);
                    }
                    break;
                case 4:
                    System.out.println("nhap ten bit danh can tim kiem");
                    String nickName=huy.nextLine();
                    for (int i = 0; i <bookList.size(); i++) {
                        if(bookList.get(i).getNickName().equalsIgnoreCase(nickName)){
                            bookList.get(i).display();
                        }
                    }
                    break;
                case 5:
                    System.out.println("thoat");
                    break;
                default:
                    System.out.println("nhap sai");
                    break;
            }

        } while (choise != 5);
    }

    static void menu() {
        System.out.println("1.nhap thong tin sach");
        System.out.println("2.hien thi sach");
        System.out.println("3.nhap thong tin tac gia");
        System.out.println("4.tim kiem sach theo but danh");
        System.out.println("5.thoat");
    }
}
.........
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QLSach;
import java.util.*;
/**
 *
 * @author ASUS
 */
public class Book {
    String bookName;
    String creatAl;
    String nickName;

    public Book() {
    }

    public Book(String bookName, String creatAl, String nickName) {
        this.bookName = bookName;
        this.creatAl = creatAl;
        this.nickName = nickName;
    }
    public void huy(){
        Scanner huy=new Scanner(System.in);
        System.out.println("nhap ten sach");
        bookName=huy.nextLine();
        System.out.println("nhap ngay suat ban");
        creatAl=huy.nextLine();
        System.out.println("nhap but danh");
        nickName=huy.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Book{" + "bookName=" + bookName + ", creatAl=" + creatAl + ", nickName=" + nickName + '}';
    }
    

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getCreatAl() {
        return creatAl;
    }

    public void setCreatAl(String creatAl) {
        this.creatAl = creatAl;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }
    
}
......
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QLSach;
import java.util.*;
/**
 *
 * @author ASUS
 */
public class TacGia {
    private String name;
    private int old;
    private String nickName;
    private String birthday;
    private String address;

    public TacGia() {
    }

    public TacGia(String nickName) {
        this.nickName = nickName;
    }
    
    public TacGia(String name, int old, String nickName, String birthday, String address) {
        this.name = name;
        this.old = old;
        this.nickName = nickName;
        this.birthday = birthday;
        this.address = address;
    }
    public void huy(ArrayList<TacGia> tacgiaList){
        Scanner huy=new Scanner(System.in);
        huy();
        System.out.println("nhap but danh");
        while(true){
            nickName=huy.nextLine();
            boolean thao=false;
            for (int i = 0; i < tacgiaList.size(); i++) {
                if(tacgiaList.get(i).getNickName().equalsIgnoreCase(nickName)){
                    thao=true;
                }
            }
            if(!thao){
                break;
            }else{
                System.out.println("nhap trung but danh");
            }
        }
       
    }
    public String getName() {
        return name;
    }

    public int getOld() {
        return old;
    }

    public String getNickName() {
        return nickName;
    }

    public String getBirthday() {
        return birthday;
    }

    public String getAddress() {
        return address;
    }
     public void huy(){
        Scanner huy=new Scanner(System.in);
        System.out.println("Nhap ten tg");
        name=huy.nextLine();
        System.out.println("nhap tuoi");
        old=Integer.parseInt(huy.nextLine());
        System.out.println("nhap ngay sinh");
        birthday=huy.nextLine();
        System.out.println("nhap dia chi");
        address=huy.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "TacGia{" + "name=" + name + ", old=" + old + ", nickName=" + nickName + ", birthday=" + birthday + ", address=" + address + '}';
    }
    
}


avatar
Minh Nghia [T1907A]
2020-03-14 14:52:56



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bt81;

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

/**
 *
 * @author Administrator
 */
public class Author {
    private String name;
    private int age;
    private String nickname;
    private String birthday;
    private String accommodation;

    public Author() {
    }

    public Author(String nickname) {
        this.nickname = nickname;
    }
    

    public Author(String name, int age, String nickname, String birthday, String accommodation) {
        this.name = name;
        this.age = age;
        this.nickname = nickname;
        this.birthday = birthday;
        this.accommodation = accommodation;
    }

    public String getName() {
        return name;
    }

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

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getNickName() {
        return nickname;
    }

    public void setPseudonym(String pseudonym) {
        this.nickname = nickname;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getAccommodation() {
        return accommodation;
    }

    public void setAccommodation(String accommodation) {
        this.accommodation = accommodation;
    }
    
    public void input(ArrayList<Author> authorList){
        System.out.println("--------------------");
        input();
        Scanner scan = new Scanner(System.in);
        
        
        System.out.println("Nhap but danh tac gia:");
        while(true){
            nickname = scan.nextLine();
            boolean isFind = false;
            for (int i = 0; i < authorList.size(); i++) {
                if(authorList.get(i).getNickName().equalsIgnoreCase(nickname)){
                    isFind = true; 
                    break;
                }
            }
            if(!isFind){
                break;
            }else{
                System.err.println("Nhap but danh khac");
            }
        }
        
    }
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap ten tac gia:");
        name = scan.nextLine();
        System.out.println("Nhap tuoi tac gia:");
        age = Integer.parseInt(scan.nextLine());
        
        System.out.println("Nhap ngay sinh tac gia:");
        birthday = scan.nextLine();
        System.out.println("Nhap que quan tac gia:");
        accommodation = scan.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }
    @Override
    public String toString() {
        return "Author{" + "name=" + name + ", age=" + age + ", pseudonym=" + nickname + ", birthday=" + birthday + ", accommodation=" + accommodation + '}';
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bt81;


import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Book {
    String nameBook;
    int publicationDate;
    String nickname;

    public Book() {
    }

    public Book(String nameBook, int publicationDate, String nickname) {
        this.nameBook = nameBook;
        this.publicationDate = publicationDate;
        this.nickname = nickname;
    }

    

    public String getNameBook() {
        return nameBook;
    }

    public void setNameBook(String nameBook) {
        this.nameBook = nameBook;
    }

    public int getPublicationDate() {
        return publicationDate;
    }

    public void setPublicationDate(int publicationDate) {
        this.publicationDate = publicationDate;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("---------------s");
        System.out.println("Nhap ten sach:");
        nameBook = scan.nextLine();
        System.out.println("Nhap ngay xuat ban:");
        publicationDate = Integer.parseInt(scan.nextLine());
        System.out.println("Nhap but danh:");
        nickname = scan.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }
    @Override
    public String toString() {
        return "Book{" + "nameBook=" + nameBook + ", publicationDate=" + publicationDate + ", pseudonym=" + nickname + '}';
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bt81;

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

/**
 *
 * @author Administrator
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int choose,n;
        ArrayList<Author> authorList = new ArrayList<>();
        ArrayList<Book> bookList = new ArrayList<>();
        do{
            showMenu();
            System.out.println("Choose:");
            choose = Integer.parseInt(scan.nextLine());
            
            switch(choose){
                case 1:
                    System.out.println("Nhap so sach can them:");
                    n = Integer.parseInt(scan.nextLine());
                    for (int i = 0; i < n; i++) {
                        Book book = new Book();
                        book.input();
                        
                        boolean isFind = false;
                        for(int j = 0; j < authorList.size(); j++){
                            if(authorList.get(j).getNickName().equalsIgnoreCase(book.getNickname())){
                                isFind = true;
                                break;
                            }
                            
                            
                        }
                        if(!isFind){
                            Author author = new Author(book.getNickname());
                            author.input();
                            
                            //luu thong tin tac gia
                            authorList.add(author);
                        }
                        bookList.add(book);
                    }
                    break;
                case 2:
                    for(int i = 0; i < bookList.size(); i++){
                        bookList.get(i).display();
                    }
                    break;
                case 3:
                    
                    System.out.println("Nhap so tac gia:");
                    n = Integer.parseInt(scan.nextLine());
                    for(int i = 0; i < n; i++){
                        Author author = new Author();
                        author.input(authorList);
                        
                        authorList.add(author);
                        
                    }
                    
                    
                    break;
                case 4:
                    System.out.println("Nhap ten but danh can tim kiem:");
                    String nickname = scan.nextLine();
                    for (int i = 0; i < bookList.size(); i++) {
                        if(bookList.get(i).getNickname().equalsIgnoreCase(nickname)){
                            bookList.get(i).display();
                        }
                    }
                    break;
                case 5:
                    System.out.println("Thoat");
                    break;
                default:
                    System.out.println("Chon lai:");
                    break;
            }
        }while(choose != 5);
    }
    public static void showMenu(){
        System.out.println("1. Nhap thong tin sach:");
        System.out.println("2. In tat ca thong tin cuon sach.");
        System.out.println("3. Nhap thong tin tac gia:");
        System.out.println("4. Tim kiem sach theo but danh");
        System.out.println("5. Thoat");
        
    }
    
}


avatar
Minh Nghia [T1907A]
2020-03-14 14:52:22



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bt81;

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

/**
 *
 * @author Administrator
 */
public class Author {
    private String name;
    private int age;
    private String nickname;
    private String birthday;
    private String accommodation;

    public Author() {
    }

    public Author(String nickname) {
        this.nickname = nickname;
    }
    

    public Author(String name, int age, String nickname, String birthday, String accommodation) {
        this.name = name;
        this.age = age;
        this.nickname = nickname;
        this.birthday = birthday;
        this.accommodation = accommodation;
    }

    public String getName() {
        return name;
    }

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

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getNickName() {
        return nickname;
    }

    public void setPseudonym(String pseudonym) {
        this.nickname = nickname;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getAccommodation() {
        return accommodation;
    }

    public void setAccommodation(String accommodation) {
        this.accommodation = accommodation;
    }
    
    public void input(ArrayList<Author> authorList){
        System.out.println("--------------------");
        input();
        Scanner scan = new Scanner(System.in);
        
        
        System.out.println("Nhap but danh tac gia:");
        while(true){
            nickname = scan.nextLine();
            boolean isFind = false;
            for (int i = 0; i < authorList.size(); i++) {
                if(authorList.get(i).getNickName().equalsIgnoreCase(nickname)){
                    isFind = true; 
                    break;
                }
            }
            if(!isFind){
                break;
            }else{
                System.err.println("Nhap but danh khac");
            }
        }
        
    }
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap ten tac gia:");
        name = scan.nextLine();
        System.out.println("Nhap tuoi tac gia:");
        age = Integer.parseInt(scan.nextLine());
        
        System.out.println("Nhap ngay sinh tac gia:");
        birthday = scan.nextLine();
        System.out.println("Nhap que quan tac gia:");
        accommodation = scan.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }
    @Override
    public String toString() {
        return "Author{" + "name=" + name + ", age=" + age + ", pseudonym=" + nickname + ", birthday=" + birthday + ", accommodation=" + accommodation + '}';
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bt81;


import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Book {
    String nameBook;
    int publicationDate;
    String nickname;

    public Book() {
    }

    public Book(String nameBook, int publicationDate, String nickname) {
        this.nameBook = nameBook;
        this.publicationDate = publicationDate;
        this.nickname = nickname;
    }

    

    public String getNameBook() {
        return nameBook;
    }

    public void setNameBook(String nameBook) {
        this.nameBook = nameBook;
    }

    public int getPublicationDate() {
        return publicationDate;
    }

    public void setPublicationDate(int publicationDate) {
        this.publicationDate = publicationDate;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("---------------s");
        System.out.println("Nhap ten sach:");
        nameBook = scan.nextLine();
        System.out.println("Nhap ngay xuat ban:");
        publicationDate = Integer.parseInt(scan.nextLine());
        System.out.println("Nhap but danh:");
        nickname = scan.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }
    @Override
    public String toString() {
        return "Book{" + "nameBook=" + nameBook + ", publicationDate=" + publicationDate + ", pseudonym=" + nickname + '}';
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bt81;

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

/**
 *
 * @author Administrator
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int choose,n;
        ArrayList<Author> authorList = new ArrayList<>();
        ArrayList<Book> bookList = new ArrayList<>();
        do{
            showMenu();
            System.out.println("Choose:");
            choose = Integer.parseInt(scan.nextLine());
            
            switch(choose){
                case 1:
                    System.out.println("Nhap so sach can them:");
                    n = Integer.parseInt(scan.nextLine());
                    for (int i = 0; i < n; i++) {
                        Book book = new Book();
                        book.input();
                        
                        boolean isFind = false;
                        for(int j = 0; j < authorList.size(); j++){
                            if(authorList.get(j).getNickName().equalsIgnoreCase(book.getNickname())){
                                isFind = true;
                                break;
                            }
                            
                            
                        }
                        if(!isFind){
                            Author author = new Author(book.getNickname());
                            author.input();
                            
                            //luu thong tin tac gia
                            authorList.add(author);
                        }
                        bookList.add(book);
                    }
                    break;
                case 2:
                    for(int i = 0; i < bookList.size(); i++){
                        bookList.get(i).display();
                    }
                    break;
                case 3:
                    
                    System.out.println("Nhap so tac gia:");
                    n = Integer.parseInt(scan.nextLine());
                    for(int i = 0; i < n; i++){
                        Author author = new Author();
                        author.input(authorList);
                        
                        authorList.add(author);
                        
                    }
                    
                    
                    break;
                case 4:
                    System.out.println("Nhap ten but danh can tim kiem:");
                    String nickname = scan.nextLine();
                    for (int i = 0; i < bookList.size(); i++) {
                        if(bookList.get(i).getNickname().equalsIgnoreCase(nickname)){
                            bookList.get(i).display();
                        }
                    }
                    break;
                case 5:
                    System.out.println("Thoat");
                    break;
                default:
                    System.out.println("Chon lai:");
                    break;
            }
        }while(choose != 5);
    }
    public static void showMenu(){
        System.out.println("1. Nhap thong tin sach:");
        System.out.println("2. In tat ca thong tin cuon sach.");
        System.out.println("3. Nhap thong tin tac gia:");
        System.out.println("4. Tim kiem sach theo but danh");
        System.out.println("5. Thoat");
        
    }
    
}


avatar
Phí Văn Long [T1907A]
2020-03-14 07:28:08

main :



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLiSach;

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

/**
 *
 * @author Admin
 */
public class Main {
    public static void main(String[] args) {
        List<Author> listAuthor = new ArrayList<>();
        List<Book> listBook = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        int choose;

        do {
            showmenu();
            choose = Integer.parseInt(scanner.nextLine());
            switch (choose) {
                case 1:
                    boolean check = false;
                    System.out.println("Nhap thong tin sach");
                    Book bk = new Book();
                    bk.input();
                    for (int i = 0; i < listAuthor.size(); i++) {
                        if (bk.getNickname().equalsIgnoreCase(listAuthor.get(i).getNickname())) {
                            check = true;
                            break;
                        }
                    }
                    if (check) {
                        listBook.add(bk);
                    } else {
                        Author author = new Author(bk.getNickname());
                        author.input();
                        listAuthor.add(author);
                        listBook.add(bk);

                    }
                case 2:
                    listBook.forEach((listBook1) -> {
                        listBook1.display();
                });
                    break;

                case 3:
                    Author author = new Author();
                    author.input(listAuthor);
                    listAuthor.add(author);
                    listAuthor.forEach((author1) -> {
                        author1.display();
                });

                case 4:
                    String butdanh = scanner.nextLine();
                    for (int i = 0; i < listBook.size(); i++) {
                        if (butdanh.equalsIgnoreCase(listBook.get(i).getNickname())) {
                            listBook.get(i).display();
                        }
                    }
                    break;
                case 5:
                    System.out.println("Exit ");
                    break;
                default:
                    System.out.println("Nhap sai roi");
                    break;
            }
        } while (choose != 5);
    }

    public static void showmenu() {
        System.out.println("1. Nhap thong tin sach");
        System.out.println("2. Hien thi tat ca sach ra man hinh");
        System.out.println("3. Nhap thong tin tac gia");
        System.out.println("4. TIm kiem tat ca sach duoc viet boi tac gia");
        System.out.println("5: Thoat");
        System.out.println("Choose: ");
    }
}
author:




/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLiSach;

import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Author {
    public String name;
    public int old;
    public String nickname;
    public String birthday;
    public String address;

    public Author() {
    }

    public Author(String nickname) {
        this.nickname = nickname;
    }

    public Author(String name, int old, String nickname, String birthday, String address) {
        this.name = name;
        this.old = old;
        this.nickname = nickname;
        this.birthday = birthday;
        this.address = address;
    }

    public void input(List<Author> listAuthor) {
        Scanner sc = new Scanner(System.in);
        input();
        while (true) {
            System.out.println("Nhap but danh tac gia");
            nickname = sc.nextLine();
            boolean a = true;
            for (int i = 0; i < listAuthor.size(); i++) {
                if (nickname.equalsIgnoreCase(listAuthor.get(i).getNickname())) {
                    a = false;
                }
            }
            if (a) {
                break;
            } else {
                System.err.println("nickname da ton tai");
            }
        }

    }

    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap ten tac gia:");
        name = sc.nextLine();
        System.out.println("Nhap tuoi tac gia");
        old = Integer.parseInt(sc.nextLine());
        System.out.println("Nhap dia chi:");
        address = sc.nextLine();
    }

    public void display() {
        System.out.println(toString());
    }

    public String getName() {
        return name;
    }

    public int getOld() {
        return old;
    }

    public String getNickname() {
        return nickname;
    }

    public String getBirthday() {
        return birthday;
    }

    public String getAddress() {
        return address;
    }

    @Override
    public String toString() {
        return "Author{" + "name=" + name + ", old=" + old + ", nickname=" + nickname + ", birthday=" + birthday + ", address=" + address + '}';
    }
}
book :




/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLiSach;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Book {
     String bookName;
    String createdAt;
    String nickname;

    public Book() {
    }

    public Book(String bookName, String createdAt, String nickname) {
        this.bookName = bookName;
        this.createdAt = createdAt;
        this.nickname = nickname;
    }

    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap ten sach: ");
        bookName = input.nextLine();

        System.out.println("Ngay xuat ban: ");
        createdAt = input.nextLine();
        System.out.println("Nhap but danh");
        nickname = input.nextLine();
    }

    public void display() {
        System.out.println(toString());
    }

    public String getBookName() {
        return bookName;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public String getNickname() {
        return nickname;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    @Override
    public String toString() {
        return "Book{" + "bookName=" + bookName + ", createdAt=" + createdAt + ", nickname=" + nickname + '}';
    }
}


avatar
Phan Bạch Tùng Dương [T1907A]
2020-03-14 07:27:43



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QLSach;

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

/**
 *
 * @author Admin
 */
public class Main {

    public static void main(String[] args) {
        List<Author> listAuthor = new ArrayList<>();
        List<Book> listBook = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        int choose;

        do {
            showmenu();
            choose = Integer.parseInt(sc.nextLine());
            switch (choose) {
                case 1:
                    boolean check = false;
                    System.out.println("Nhap thong tin sach");
                    Book bk = new Book();
                    bk.input();
                    for (int i = 0; i < listAuthor.size(); i++) {
                        if (bk.getNickname().equalsIgnoreCase(listAuthor.get(i).getNickname())) {
                            check = true;
                            break;
                        }
                    }
                    if (check) {
                        listBook.add(bk);
                    } else {
                        Author author = new Author(bk.getNickname());
                        author.input();
                        listAuthor.add(author);
                        listBook.add(bk);

                    }
                case 2:
                    for (Book listBook1 : listBook) {
                        listBook1.display();
                    }
                    break;
                case 3:
                    Author author = new Author();
                    author.input(listAuthor);
                    listAuthor.add(author);
                    for (Author author1 : listAuthor) {
                        author1.display();
                    }
                case 4:
                    String butdanh = sc.nextLine();
                    for (int i = 0; i < listBook.size(); i++) {
                        if (butdanh.equalsIgnoreCase(listBook.get(i).getNickname())) {
                            listBook.get(i).display();
                        }
                    }
                    break;
                case 5:
                    System.out.println("Exit thanh cong");
                    break;
                default:
                    System.out.println("Nhap sai roi");
                    break;
            }
        } while (choose != 5);
    }

    public static void showmenu() {
        System.out.println("1. Nhập thông tin sách.");
        System.out.println("2. Hiển thị tất cả sách ra màn hình.");
        System.out.println("3. Nhập thông tin tác giả.");
        System.out.println("4. Tìm kiếm tất cả sách được viết bởi tác giả.");
        System.out.println("5: Thoat.");
        System.out.println("Choose: ");
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QLSach;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Book {

    String bookName;
    String createdAt;
    String nickname;

    public Book() {
    }

    public Book(String bookName, String createdAt, String nickname) {
        this.bookName = bookName;
        this.createdAt = createdAt;
        this.nickname = nickname;
    }

    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap ten sach : ");
        bookName = input.nextLine();

        System.out.println("Ngay xuat ban : ");
        createdAt = input.nextLine();
        System.out.println("Nhap but danh : ");
        nickname = input.nextLine();
    }

    public void display() {
        System.out.println(toString());
    }

    public String getBookName() {
        return bookName;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public String getNickname() {
        return nickname;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    @Override
    public String toString() {
        return "Book{" + "bookName=" + bookName + ", createdAt=" + createdAt + ", nickname=" + nickname + '}';
    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QLSach;

import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Author {

    private String name;
    private int old;
    private String nickname;
    private String birthday;
    private String address;

    public Author() {
    }

    public Author(String nickname) {
        this.nickname = nickname;
    }

    public Author(String name, int old, String nickname, String birthday, String address) {
        this.name = name;
        this.old = old;
        this.nickname = nickname;
        this.birthday = birthday;
        this.address = address;
    }

    public void input(List<Author> listAuthor) {
        Scanner sc = new Scanner(System.in);
        input();
        while (true) {
            System.out.println("Nhap but danh tac gia : ");
            nickname = sc.nextLine();
            boolean a = true;
            for (int i = 0; i < listAuthor.size(); i++) {
                if (nickname.equalsIgnoreCase(listAuthor.get(i).getNickname())) {
                    a = false;
                }
            }
            if (a) {
                break;
            } else {
                System.err.println("nickname da ton tai");
            }
        }

    }

    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap ten tac gia : ");
        name = sc.nextLine();
        System.out.println("Nhap tuoi tac gia : ");
        old = Integer.parseInt(sc.nextLine());
        System.out.println("Nhap dia chi : ");
        address = sc.nextLine();
    }

    public void display() {
        System.out.println(toString());
    }

    public String getName() {
        return name;
    }

    public int getOld() {
        return old;
    }

    public String getNickname() {
        return nickname;
    }

    public String getBirthday() {
        return birthday;
    }

    public String getAddress() {
        return address;
    }

    @Override
    public String toString() {
        return "Author{" + "name=" + name + ", old=" + old + ", nickname=" + nickname + ", birthday=" + birthday + ", address=" + address + '}';
    }

}