By GokiSoft.com| 13:34 16/09/2022|
Java Basic

Java Basic- OOP - quản lý sách trong java

Cài đặt lớp Book gồm các thuộc tính:

private String bookName;

private String bookAuthor;

private String producer;

private int yearPublishing;

private float price;

 

Cài đặt 2 constructors, các phương thức set/get cho các thuộc tính của lớp.

Cài đặt 2 phương thức input() và display để nhập và hiển thị các thuộc tính của lớp.

 

Cài đặt lớp AptechBook kế thừa lớp Book và bổ sung thêm vào thuộc tính:

private String language;

private int semester;

 

Cài đặt 2 constructor trong đó sử dụng super để gọi đến constructor của lớp cha.

Cài đặt các phương thức get/set cho các thuộc tính bổ sung

Override các phương thức input() và display().

 

Cài đặt lớp Test trong đó tạo menu và thực hiện theo các chức năng của menu:

1.    Nhập thông tin n cuốn sách của Aptech

2.    Hiển thị thông tin vừa nhập

3.    Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị

4.    Tìm kiếm theo tên sách

5.    Tìm kiếm theo tên tác giả

6.    Thoát.

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

cuonglee [C1907L]
cuonglee

2020-04-10 12:43:18



/*
 * 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;
import jdk.internal.util.xml.impl.Input;

/**
 *
 * @author Admin
 */
public class Book {
    private String bookName;
    private String bookAuthor;
    private String producer;
    private int yearPublishing;
    private float price;
    
    public Book() {
    }

    public Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
        this.bookName = bookName;
        this.bookAuthor = bookAuthor;
        this.producer = producer;
        this.yearPublishing = yearPublishing;
        this.price = price;
    }

    public String getBookName() {
        return bookName;
    }

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

    public String getBookAuthor() {
        return bookAuthor;
    }

    public void setBookAuthor(String bookAuthor) {
        this.bookAuthor = bookAuthor;
    }

    public String getProducer() {
        return producer;
    }

    public void setProducer(String producer) {
        this.producer = producer;
    }

    public int getYearPublishing() {
        return yearPublishing;
    }

    public void setYearPublishing(int yearPublishing) {
        this.yearPublishing = yearPublishing;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    
    
    public void display(){
        System.out.println("ten sach: "+bookName);
        System.out.println("ten tac gia: " + bookAuthor);
        System.out.println("producer la: " + producer);
        System.out.println("yearPublishing la: " + yearPublishing);
        System.out.println("price :" + price);
   
    }
    public void input(){
        Scanner input = new Scanner(System.in);
        System.out.println("nhap ten sach");
        bookName = input.nextLine();
        System.out.println("nhap ten tac gia");
        bookAuthor = input.nextLine();
        System.out.println("nhap producer");
        producer = input.nextLine();
        System.out.println("nhap yearPublishing");
        yearPublishing = input.nextInt();
        System.out.println("nhap price");
        price = input.nextFloat();  
       
    }
   
   
    
}
/*
 * 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;
import jdk.internal.util.xml.impl.Input;

/**
 *
 * @author Admin
 */
public class AptechBook  extends Book{
    private String language;
    private int semester;
    
    public AptechBook() {
        super();
    }
    public AptechBook(String language, int semester) {
        this.language = language;
        this.semester = semester;
    }

    public AptechBook(String language, int semester, String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
        super(bookName, bookAuthor, producer, yearPublishing, price);
        this.language = language;
        this.semester = semester;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public int getSemester() {
        return semester;
    }

    public void setSemester(int semester) {
        this.semester = semester;
    }

    

    @Override
    public void input() {
        Scanner add = new Scanner(System.in);
        super.input();
        System.out.println("Moi ban nhap ngon ngu: ");
        language = add.nextLine();
        System.out.println("moi ban nhap semester");
        semester = add.nextInt();
        
    }
    @Override
    public void display() {
        super.display(); 
        System.out.println("language: " + language);
        System.out.println("semester la: " + semester);
        System.out.println("------------------------------");
        
    }
   
}
/*
 * 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.Collections;
import java.util.Comparator;
import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Test {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = 0,choose;
        ArrayList<AptechBook> list = new ArrayList<>();//
        do{
            show();
            choose = input.nextInt();
            switch(choose){
                case 1:
                    System.out.println("nhap thong tin n book");
                    System.out.println("nhap n");
                    n = input.nextInt();
                    for(int i=0; i<n;i++){
                        AptechBook apt = new AptechBook();
//                          Book bk = new Book();
                          apt.input();
                          list.add(apt);
                    };
                    break;
                case 2:
                    System.out.println("hien thi thong tin");
                    for(int i=0; i<list.size();i++){
                        list.get(i).display();
                    };
                    break;
                case 3:
                    System.out.println("sap xep giam dan theo nam xuat ban");
//                    Collections.sort(list, new Comparator<AptechBook>(){
//                    @Override
//                    public int compare(AptechBook o1, AptechBook o2) {
//                         return o1.getYearPublishing() >= o2.getYearPublishing() ? -1:1;
//                        }
//                     });
//                    //hiện thị
//                     for(int i =0; i <list.size(); i++) {
//			list.get(i).display();
//                    }
                    for (int i = 0; i < n-1; i++) {
                        for (int j = i+1; j < n; j++) {
                            if (list.get(i).getYearPublishing() < list.get(j).getYearPublishing()) {
                                AptechBook temp = list.get(j);
                                list.set(j, list.get(i));
                                list.set(i, temp);
                            }
                        }
                    }
                    //hiện thị
                    for (int i = 0; i <n; i++) {
                        list.get(list.size()-1).display();
                    }
                    break;
                case 4:
                    break;
                case 5:
                    break;
                case 6:
                    break;
                            
            }
        }while(choose!=6);
    }
    
    
    
    
    
    
    
    
    
    static void show(){
        System.out.println("1. Nhap thong tin N cuon sach.");
        System.out.println("2. Hien thi thong tin vua nhap.");
        System.out.println("3. Sap xem thong tin giam dan theo nam xuat ban va hien thi");
        System.out.println("4. Tim kiem theo ten sach");
        System.out.println("5. Tim kiem theo ten tac gia");
        System.out.println("6. Thoat");
        System.out.println("==============================");
        System.out.println("Choose");
    }

    


}



Lê Xuân Dũng [JavaFree]
Lê Xuân Dũng

2020-03-26 05:56:25



package QuanlySach;

import java.util.Scanner;

public class Book {

    private String bookName;
    private String bookAuthor;
    private String producer;
    private int publishingYear;
    private float price;

    public Book() {
    }

    public Book(String bookName, String bookAuthor, String producer, int publishingYear, float price) {
        
        this.bookName = bookName;
        this.bookAuthor = bookAuthor;
        this.producer = producer;
        this.publishingYear = publishingYear;
        this.price = price;
    }

    public String getBookName() {
        return bookName;
    }

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

    public String getBookAuthor() {
        return bookAuthor;
    }

    public void setBookAuthor(String bookAuthor) {
        this.bookAuthor = bookAuthor;
    }

    public String getProducer() {
        return producer;
    }

    public void setProducer(String producer) {
        this.producer = producer;
    }

    public int getPublishingYear() {
        return publishingYear;
    }

    public void setPublishingYear(int publishingYear) {
        this.publishingYear = publishingYear;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }
    
    public void input() {
		Scanner sc = new Scanner(System.in);
		System.out.println("Moi nhap ten sach: ");
		bookName = sc.nextLine();
		
		System.out.println("Moi nhap tac gia: ");
		bookAuthor = sc.nextLine();
		
		System.out.println("Moi nhap ten nha xuat ban: ");
		producer = sc.nextLine();
		
		System.out.println("Moi nhap nam xuat ban: ");
		publishingYear = Integer.parseInt(sc.nextLine());
		
		System.out.println("Moi nhap gia tien: ");
		price = Float.parseFloat(sc.nextLine());
	}
	
	public void display() {
		
                System.out.println("------------------------------");
		System.out.println("Ten cuon sach: "+bookName);
		System.out.println("Ten tac gia: "+bookAuthor);
		System.out.println("Ten nha xuat ban: "+producer);
		System.out.println("Nam xuat ban: "+publishingYear);
		System.out.println("Gia tien: "+price);
        }

}



package QuanlySach;

import java.util.Scanner;

public class AptechBook extends Book {

    private String language;
    private int semester;

    public AptechBook() {
        super();
    }

    public AptechBook(String language, int semester) {
        this.language = language;
        this.semester = semester;
    }

    public AptechBook(String bookName, String bookAuthor, String producer, int publishingYear, float price, String language, int semester) {
        super(bookName, bookAuthor, producer, publishingYear, price);
        this.language = language;
        this.semester = semester;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public int getSemester() {
        return semester;
    }

    public void setSemester(int semester) {
        this.semester = semester;
    }


    @Override
    public void input() {
        Scanner sc = new Scanner(System.in);
        super.input();

        System.out.println("Moi ban nhap ngon ngu: ");
        language = sc.nextLine();

        System.out.println("Moi ban nhap hoc ki: ");
        semester = Integer.parseInt(sc.nextLine());
    }

    @Override
    public void display() {
        super.display();
        System.out.println("Ngon ngu cuon sach: " + language);
        System.out.println("Hoc ki: " + semester);
        System.out.println("------------------------------");
    }

}



package QuanlySach;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int n, choose;
        Scanner sc = new Scanner(System.in);
        ArrayList<AptechBook> bookList = new ArrayList<>();
        do {
            showMenu();
            choose = Integer.parseInt(sc.nextLine());
            switch (choose) {
                case 1:
                    System.out.println("Nhap so luong n quyen sach can nhap thong tin:");
                    n = Integer.parseInt(sc.nextLine());

                    for (int i = 0; i < n; i++) {
                        AptechBook book = new AptechBook();
                        book.input();
                        bookList.add(book);
                    }
                    break;
                case 2:
                    for (int i = 0; i < bookList.size(); i++) {
                        bookList.get(i).display();
                    }
//                    for (AptechBook aptechBook : bookList) {
//                        aptechBook.display();
//                    }
                    break;
                case 3:
                    Collections.sort(bookList, new Comparator<AptechBook>() {

                        @Override
                        public int compare(AptechBook o1, AptechBook o2) {
                            if(o1.getPublishingYear() >= o2.getPublishingYear())
                                return -1;
                            else
                                return 1;
                        }
                    });
                    
                    for (AptechBook aptechBook : bookList) {
                        aptechBook.display();
                    }
                    break;
                case 4:
                    int count = 0;
                    System.out.println("Moi nhap ten sach can tim: ");
                    String bookNameSearch = sc.nextLine();
                    for (int i = 0; i < bookList.size(); i++) {
                        if (bookList.get(i).getBookName().equalsIgnoreCase(bookNameSearch)) {
                            bookList.get(i).display();
                            count++;
                        }
                    }
                    if (count == 0) {
                        System.out.println("Khong tim thay quyen sach nay!");
                    }
                    break;
                case 5:
                    boolean find = false;
                    System.out.println("Moi nhap ten tac gia can tim: ");
                    String bookAuthorSearch = sc.nextLine();
                    for (int i = 0; i < bookList.size(); i++) {
                        if (bookList.get(i).getBookAuthor().equalsIgnoreCase(bookAuthorSearch)) {
                            bookList.get(i).display();
                            find = true;
                        }
                    }
                    if (!find) {
                        System.out.println("Khong tim thay tac gia nay!");
                    }
                    break;
                case 6:
                    System.out.println("Good-bye!");
                    break;
                default:
                    System.out.println("Nhap sai! Moi nhap lai!");
                    break;
            }

        } while (choose != 6);
    }

    static void showMenu() {
        System.out.println("------------------------------");
        System.out.println("1. Nhap thong tin n cuon sach cua Aptech. ");
        System.out.println("2. Hien thi thong tin sach.");
        System.out.println("3. Sap xep sach theo nam xuat ban va hien thi.");
        System.out.println("4. Tim kiem theo ten sach.");
        System.out.println("5. Tim kiem theo ten tac gia.");
        System.out.println("6. Thoat.");
        System.out.println("------------------------------");
        System.out.println("Choose: ");
    }
}



Lê Xuân Dũng [JavaFree]
Lê Xuân Dũng

2020-03-26 05:46:49



package QuanlySach;

import java.util.Scanner;

public class Book {

    private String bookName;
    private String bookAuthor;
    private String producer;
    private int publishingYear;
    private float price;

    public Book() {
    }

    public Book(String bookName, String bookAuthor, String producer, int publishingYear, float price) {
        super();
        this.bookName = bookName;
        this.bookAuthor = bookAuthor;
        this.producer = producer;
        this.publishingYear = publishingYear;
        this.price = price;
    }

    public String getBookName() {
        return bookName;
    }

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

    public String getBookAuthor() {
        return bookAuthor;
    }

    public void setBookAuthor(String bookAuthor) {
        this.bookAuthor = bookAuthor;
    }

    public String getProducer() {
        return producer;
    }

    public void setProducer(String producer) {
        this.producer = producer;
    }

    public int getPublishingYear() {
        return publishingYear;
    }

    public void setPublishingYear(int publishingYear) {
        this.publishingYear = publishingYear;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }
    
//    public void input(){
//        Scanner sc = new Scanner(System.in);
//        System.out.println("Nhap ten sach: ");
//        this.bookName = sc.nextLine();
//        System.out.println("Nhap ten tac gia: ");
//        this.bookAuthor = sc.nextLine();
//        System.out.println("Nhap NXB: ");
//        this.producer = sc.nextLine();
//        System.out.println("Nhap nam xuat ban: ");
//        this.publishingYear = Integer.parseInt(sc.nextLine());
//        System.out.println("Nhap gia tien: ");
//        this.price = Float.parseFloat(sc.nextLine());
//        
//    }
// 
//    
//    public String display(){
//        return ("Ten sach: "+this.bookName+", Ten tac gia: "+this.bookAuthor+", NXB: "+this.producer+", Nam xuat ban: "+this.publishingYear+", Gia tien: "+this.price);
//    }
    public void input() {
		Scanner sc = new Scanner(System.in);
		System.out.println("Moi nhap ten sach: ");
		bookName = sc.nextLine();
		
		System.out.println("Moi nhap tac gia: ");
		bookAuthor = sc.nextLine();
		
		System.out.println("Moi nhap ten nha xuat ban: ");
		producer = sc.nextLine();
		
		System.out.println("Moi nhap nam xuat ban: ");
		publishingYear = Integer.parseInt(sc.nextLine());
		
		System.out.println("Moi nhap gia tien: ");
		price = Float.parseFloat(sc.nextLine());
	}
	
	public void display() {
		
                System.out.println("------------------------------");
		System.out.println("Ten cuon sach: "+bookName);
		System.out.println("Ten tac gia: "+bookAuthor);
		System.out.println("Ten nha xuat ban: "+producer);
		System.out.println("Nam xuat ban: "+publishingYear);
		System.out.println("Gia tien: "+price);
        }

}



package QuanlySach;

import java.util.Scanner;

public class AptechBook extends Book {

    private String language;
    private int semester;

    public AptechBook() {
        super();
    }

    public AptechBook(String language, int semester) {
        this.language = language;
        this.semester = semester;
    }

    public AptechBook(String bookName, String bookAuthor, String producer, int publishingYear, float price, String language, int semester) {
        super(bookName, bookAuthor, producer, publishingYear, price);
        this.language = language;
        this.semester = semester;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public int getSemester() {
        return semester;
    }

    public void setSemester(int semester) {
        this.semester = semester;
    }

//    @Override
//    public void input(){
//        
//        super.input();
//        
//        Scanner sc = new Scanner(System.in);
//        
//        System.out.println("Nhap ngon ngu: ");
//        this.language = sc.nextLine();
//        
//        System.out.println("Nhap hoc ky: ");
//        this.semester = Integer.parseInt(sc.nextLine());
//    }
//    
//    @Override
//    public String display(){
//        return "{" + super.display()+", Ngon ngu: "+this.language+", Hoc ky: "+this.semester + "}"; 
//    }
    @Override
    public void input() {
        Scanner sc = new Scanner(System.in);
        super.input();

        System.out.println("Moi ban nhap ngon ngu: ");
        language = sc.nextLine();

        System.out.println("Moi ban nhap hoc ki: ");
        semester = Integer.parseInt(sc.nextLine());
    }

    @Override
    public void display() {
        super.display();
        System.out.println("Ngon ngu cuon sach: " + language);
        System.out.println("Hoc ki: " + semester);
        System.out.println("------------------------------");
    }

}



package QuanlySach;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int n, choose;
        Scanner sc = new Scanner(System.in);
        ArrayList<AptechBook> bookList = new ArrayList<>();
        do {
            showMenu();
            choose = Integer.parseInt(sc.nextLine());
            switch (choose) {
                case 1:
                    System.out.println("Nhap so luong n quyen sach can nhap thong tin:");
                    n = Integer.parseInt(sc.nextLine());

                    for (int i = 0; i < n; i++) {
                        AptechBook book = new AptechBook();
                        book.input();
                        bookList.add(book);
                    }
                    break;
                case 2:
                    for (int i = 0; i < bookList.size(); i++) {
                        bookList.get(i).display();
                    }
//                    for (AptechBook aptechBook : bookList) {
//                        aptechBook.display();
//                    }
                    break;
                case 3:
                    Collections.sort(bookList, new Comparator<AptechBook>() {

                        @Override
                        public int compare(AptechBook o1, AptechBook o2) {
                            if(o1.getPublishingYear() >= o2.getPublishingYear())
                                return -1;
                            else
                                return 1;
                        }
                    });
                    
                    for (AptechBook aptechBook : bookList) {
                        aptechBook.display();
                    }
                    break;
                case 4:
                    int count = 0;
                    System.out.println("Moi nhap ten sach can tim: ");
                    String bookNameSearch = sc.nextLine();
                    for (int i = 0; i < bookList.size(); i++) {
                        if (bookList.get(i).getBookName().equalsIgnoreCase(bookNameSearch)) {
                            bookList.get(i).display();
                            count++;
                        }
                    }
                    if (count == 0) {
                        System.out.println("Khong tim thay quyen sach nay!");
                    }
                    break;
                case 5:
                    boolean find = false;
                    System.out.println("Moi nhap ten tac gia can tim: ");
                    String bookAuthorSearch = sc.nextLine();
                    for (int i = 0; i < bookList.size(); i++) {
                        if (bookList.get(i).getBookAuthor().equalsIgnoreCase(bookAuthorSearch)) {
                            bookList.get(i).display();
                            find = true;
                        }
                    }
                    if (!find) {
                        System.out.println("Khong tim thay tac gia nay!");
                    }
                    break;
                case 6:
                    System.out.println("Good-bye!");
                    break;
                default:
                    System.out.println("Nhap sai! Moi nhap lai!");
                    break;
            }

        } while (choose != 6);
    }

    static void showMenu() {
        System.out.println("------------------------------");
        System.out.println("1. Nhap thong tin n cuon sach cua Aptech. ");
        System.out.println("2. Hien thi thong tin sach.");
        System.out.println("3. Sap xep sach theo nam xuat ban va hien thi.");
        System.out.println("4. Tim kiem theo ten sach.");
        System.out.println("5. Tim kiem theo ten tac gia.");
        System.out.println("6. Thoat.");
        System.out.println("------------------------------");
        System.out.println("Choose: ");
    }
}



Phạm Kim Anh [JavaFree]
Phạm Kim Anh

2020-03-25 14:49:24



package quanlysach;

import java.util.Scanner;

public class Book {
	
	private String bookName;
	private String bookAuthor;
	private String producer;
	private int yearPublishing;
	private float price;
	
	public Book() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param bookName
	 * @param bookAuthor
	 * @param producer
	 * @param yearPublishing
	 * @param price
	 */
	public Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
		super();
		this.bookName = bookName;
		this.bookAuthor = bookAuthor;
		this.producer = producer;
		this.yearPublishing = yearPublishing;
		this.price = price;
	}

	public String getBookName() {
		return bookName;
	}

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

	public String getBookAuthor() {
		return bookAuthor;
	}

	public void setBookAuthor(String bookAuthor) {
		this.bookAuthor = bookAuthor;
	}

	public String getProducer() {
		return producer;
	}

	public void setProducer(String producer) {
		this.producer = producer;
	}

	public int getYearPublishing() {
		return yearPublishing;
	}

	public void setYearPublishing(int yearPublishing) {
		this.yearPublishing = yearPublishing;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}
	
	public void input() {
		Scanner sc = new Scanner(System.in);
		System.out.println("Moi ban nhap ten sach: ");
		bookName = sc.nextLine();
		
		System.out.println("Moi ban nhap tac gia cuon sach: ");
		bookAuthor = sc.nextLine();
		
		System.out.println("Moi ban nhap ten nha xuat ban: ");
		producer = sc.nextLine();
		
		System.out.println("Moi ban nhap nam xuat ban: ");
		yearPublishing = Integer.parseInt(sc.nextLine());
		
		System.out.println("Moi ban nhap gia: ");
		price = Float.parseFloat(sc.nextLine());
	}
	
	public void display() {
		System.out.println("---------------------------------------------");
		System.out.println("Ten cuon sach la: "+bookName);
		System.out.println("Ten tac gia cuon sach la: "+bookAuthor);
		System.out.println("Ten nha xuat ban la: "+producer);
		System.out.println("Nam xuat ban cuon sach la: "+yearPublishing);
		System.out.println("Gia cua cuon sach la: "+price);
		
	}

}

package quanlysach;

import java.util.Scanner;

public class AptechBook extends Book{

	private String language;
	private int semester;
	
	public AptechBook() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param language
	 * @param semester
	 */
	public AptechBook(String language, int semester) {
		super();
		this.language = language;
		this.semester = semester;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public int getSemester() {
		return semester;
	}

	public void setSemester(int semester) {
		this.semester = semester;
	}
	
	@Override
	public void input() {
		Scanner sc = new Scanner(System.in);
		super.input();
		
		System.out.println("Moi ban nhap ngon ngu: ");
		language = sc.nextLine();
		
		System.out.println("Moi ban nhap lan tai ban: ");
		semester = Integer.parseInt(sc.nextLine());
	}
	
	@Override
	public void display() {
		super.display();
		System.out.println("Ngon ngu cuon sach la: "+language);
		System.out.println("Cuon sach tai ban lan thu "+semester);
		System.out.println("---------------------------------------------");
	}
}


package quanlysach;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Test {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		ArrayList<AptechBook> listAp = new ArrayList<AptechBook>();
		
		int choose;
		boolean exit = false;
		int i;
		do {
			menu();
			System.out.println("Moi ban nhap lua chon: ");
			choose = Integer.parseInt(sc.nextLine());
			switch(choose) {
			case 1:
				System.out.println("1. Nhap thong tin n cuon sach Aptech.");
				
				System.out.println("Moi ban nhap so sach can them: ");
				int n = Integer.parseInt(sc.nextLine());
				for( i = 0; i < n; i++) {
					AptechBook aptechBook = new AptechBook();
					aptechBook.input();
					//luu doi tuong aptechBook vao list AptechBook
					listAp.add(aptechBook);
				}
				break;
			case 2:
				System.out.println("2. Hien thi thong tin vua nhap.");
				for(AptechBook ap : listAp) {
					ap.display();
				}
				break;
			case 3:
				System.out.println("3. Sap xep thong tin giam dan theo nam xuat ban va hien thi.");
				
				Collections.sort(listAp, new Comparator<AptechBook>() {

					@Override
					public int compare(AptechBook o1, AptechBook o2) {
						return o1.getYearPublishing() >= o2.getYearPublishing() ? -1:1;
					}
				});
				
				//hien thi
				for( i =0; i <listAp.size(); i++) {
					listAp.get(i).display();
				}
				break;
			case 4:
				System.out.println("4. Tim kiem theo ten sach.");
				
				int count = 0;
				System.out.println("Moi ban nhap ten sach can tim: ");
				String tenSachTK = sc.nextLine();
				for(i = 0; i < listAp.size(); i++) {
					if(listAp.get(i).getBookName().equalsIgnoreCase(tenSachTK)) {
						listAp.get(i).display();
						count++;
					}
				}
				if(count == 0) {
					System.out.println("Khong tim thay ten sach ban can tim");
				}
				break;
			case 5:
				System.out.println("5. Tim kiem theo ten tac gia.");
				
				int count1 = 0;
				System.out.println("Moi ban nhap ten tac gia can tim: ");
				String tacGiaTK = sc.nextLine();
				for(i = 0; i < listAp.size(); i++) {
					if(listAp.get(i).getBookAuthor().equalsIgnoreCase(tacGiaTK)) {
						listAp.get(i).display();
					}
				}
				if(count1 == 0) {
					System.out.println("Khong tim thay tac gia ban can tim");
				}
				break;
			case 6:
				System.out.println("Goodbye!");
				exit = true;
				break;
			default:
				System.out.println("Moi ban chon lua chon duoi menu: ");
				break;
			}
			
		}while(choose != 6);
	}

	static void menu() {
		System.out.println("==============================================================");
		System.out.println("1. Nhap thong tin n cuon sach cua Aptech");
		System.out.println("2. Hien thi thong tin vua nhap");
		System.out.println("3. Sap xep thong tin giam dan theo nam xuat ban va hien thi");
		System.out.println("4. Tim kiem theo ten sach");
		System.out.println("5. Tim kiem theo ten tac gia");
		System.out.println("6. Thoat");
		System.out.println("==============================================================");
	}
}




Phạm Kim Anh [JavaFree]
Phạm Kim Anh

2020-03-25 14:49:23



package quanlysach;

import java.util.Scanner;

public class Book {
	
	private String bookName;
	private String bookAuthor;
	private String producer;
	private int yearPublishing;
	private float price;
	
	public Book() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param bookName
	 * @param bookAuthor
	 * @param producer
	 * @param yearPublishing
	 * @param price
	 */
	public Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
		super();
		this.bookName = bookName;
		this.bookAuthor = bookAuthor;
		this.producer = producer;
		this.yearPublishing = yearPublishing;
		this.price = price;
	}

	public String getBookName() {
		return bookName;
	}

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

	public String getBookAuthor() {
		return bookAuthor;
	}

	public void setBookAuthor(String bookAuthor) {
		this.bookAuthor = bookAuthor;
	}

	public String getProducer() {
		return producer;
	}

	public void setProducer(String producer) {
		this.producer = producer;
	}

	public int getYearPublishing() {
		return yearPublishing;
	}

	public void setYearPublishing(int yearPublishing) {
		this.yearPublishing = yearPublishing;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}
	
	public void input() {
		Scanner sc = new Scanner(System.in);
		System.out.println("Moi ban nhap ten sach: ");
		bookName = sc.nextLine();
		
		System.out.println("Moi ban nhap tac gia cuon sach: ");
		bookAuthor = sc.nextLine();
		
		System.out.println("Moi ban nhap ten nha xuat ban: ");
		producer = sc.nextLine();
		
		System.out.println("Moi ban nhap nam xuat ban: ");
		yearPublishing = Integer.parseInt(sc.nextLine());
		
		System.out.println("Moi ban nhap gia: ");
		price = Float.parseFloat(sc.nextLine());
	}
	
	public void display() {
		System.out.println("---------------------------------------------");
		System.out.println("Ten cuon sach la: "+bookName);
		System.out.println("Ten tac gia cuon sach la: "+bookAuthor);
		System.out.println("Ten nha xuat ban la: "+producer);
		System.out.println("Nam xuat ban cuon sach la: "+yearPublishing);
		System.out.println("Gia cua cuon sach la: "+price);
		
	}

}

package quanlysach;

import java.util.Scanner;

public class AptechBook extends Book{

	private String language;
	private int semester;
	
	public AptechBook() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param language
	 * @param semester
	 */
	public AptechBook(String language, int semester) {
		super();
		this.language = language;
		this.semester = semester;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public int getSemester() {
		return semester;
	}

	public void setSemester(int semester) {
		this.semester = semester;
	}
	
	@Override
	public void input() {
		Scanner sc = new Scanner(System.in);
		super.input();
		
		System.out.println("Moi ban nhap ngon ngu: ");
		language = sc.nextLine();
		
		System.out.println("Moi ban nhap lan tai ban: ");
		semester = Integer.parseInt(sc.nextLine());
	}
	
	@Override
	public void display() {
		super.display();
		System.out.println("Ngon ngu cuon sach la: "+language);
		System.out.println("Cuon sach tai ban lan thu "+semester);
		System.out.println("---------------------------------------------");
	}
}


package quanlysach;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Test {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		ArrayList<AptechBook> listAp = new ArrayList<AptechBook>();
		
		int choose;
		boolean exit = false;
		int i;
		do {
			menu();
			System.out.println("Moi ban nhap lua chon: ");
			choose = Integer.parseInt(sc.nextLine());
			switch(choose) {
			case 1:
				System.out.println("1. Nhap thong tin n cuon sach Aptech.");
				
				System.out.println("Moi ban nhap so sach can them: ");
				int n = Integer.parseInt(sc.nextLine());
				for( i = 0; i < n; i++) {
					AptechBook aptechBook = new AptechBook();
					aptechBook.input();
					//luu doi tuong aptechBook vao list AptechBook
					listAp.add(aptechBook);
				}
				break;
			case 2:
				System.out.println("2. Hien thi thong tin vua nhap.");
				for(AptechBook ap : listAp) {
					ap.display();
				}
				break;
			case 3:
				System.out.println("3. Sap xep thong tin giam dan theo nam xuat ban va hien thi.");
				
				Collections.sort(listAp, new Comparator<AptechBook>() {

					@Override
					public int compare(AptechBook o1, AptechBook o2) {
						return o1.getYearPublishing() >= o2.getYearPublishing() ? -1:1;
					}
				});
				
				//hien thi
				for( i =0; i <listAp.size(); i++) {
					listAp.get(i).display();
				}
				break;
			case 4:
				System.out.println("4. Tim kiem theo ten sach.");
				
				int count = 0;
				System.out.println("Moi ban nhap ten sach can tim: ");
				String tenSachTK = sc.nextLine();
				for(i = 0; i < listAp.size(); i++) {
					if(listAp.get(i).getBookName().equalsIgnoreCase(tenSachTK)) {
						listAp.get(i).display();
						count++;
					}
				}
				if(count == 0) {
					System.out.println("Khong tim thay ten sach ban can tim");
				}
				break;
			case 5:
				System.out.println("5. Tim kiem theo ten tac gia.");
				
				int count1 = 0;
				System.out.println("Moi ban nhap ten tac gia can tim: ");
				String tacGiaTK = sc.nextLine();
				for(i = 0; i < listAp.size(); i++) {
					if(listAp.get(i).getBookAuthor().equalsIgnoreCase(tacGiaTK)) {
						listAp.get(i).display();
					}
				}
				if(count1 == 0) {
					System.out.println("Khong tim thay tac gia ban can tim");
				}
				break;
			case 6:
				System.out.println("Goodbye!");
				exit = true;
				break;
			default:
				System.out.println("Moi ban chon lua chon duoi menu: ");
				break;
			}
			
		}while(choose != 6);
	}

	static void menu() {
		System.out.println("==============================================================");
		System.out.println("1. Nhap thong tin n cuon sach cua Aptech");
		System.out.println("2. Hien thi thong tin vua nhap");
		System.out.println("3. Sap xep thong tin giam dan theo nam xuat ban va hien thi");
		System.out.println("4. Tim kiem theo ten sach");
		System.out.println("5. Tim kiem theo ten tac gia");
		System.out.println("6. Thoat");
		System.out.println("==============================================================");
	}
}




Phạm Kim Anh [JavaFree]
Phạm Kim Anh

2020-03-25 14:49:21



package quanlysach;

import java.util.Scanner;

public class Book {
	
	private String bookName;
	private String bookAuthor;
	private String producer;
	private int yearPublishing;
	private float price;
	
	public Book() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param bookName
	 * @param bookAuthor
	 * @param producer
	 * @param yearPublishing
	 * @param price
	 */
	public Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
		super();
		this.bookName = bookName;
		this.bookAuthor = bookAuthor;
		this.producer = producer;
		this.yearPublishing = yearPublishing;
		this.price = price;
	}

	public String getBookName() {
		return bookName;
	}

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

	public String getBookAuthor() {
		return bookAuthor;
	}

	public void setBookAuthor(String bookAuthor) {
		this.bookAuthor = bookAuthor;
	}

	public String getProducer() {
		return producer;
	}

	public void setProducer(String producer) {
		this.producer = producer;
	}

	public int getYearPublishing() {
		return yearPublishing;
	}

	public void setYearPublishing(int yearPublishing) {
		this.yearPublishing = yearPublishing;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}
	
	public void input() {
		Scanner sc = new Scanner(System.in);
		System.out.println("Moi ban nhap ten sach: ");
		bookName = sc.nextLine();
		
		System.out.println("Moi ban nhap tac gia cuon sach: ");
		bookAuthor = sc.nextLine();
		
		System.out.println("Moi ban nhap ten nha xuat ban: ");
		producer = sc.nextLine();
		
		System.out.println("Moi ban nhap nam xuat ban: ");
		yearPublishing = Integer.parseInt(sc.nextLine());
		
		System.out.println("Moi ban nhap gia: ");
		price = Float.parseFloat(sc.nextLine());
	}
	
	public void display() {
		System.out.println("---------------------------------------------");
		System.out.println("Ten cuon sach la: "+bookName);
		System.out.println("Ten tac gia cuon sach la: "+bookAuthor);
		System.out.println("Ten nha xuat ban la: "+producer);
		System.out.println("Nam xuat ban cuon sach la: "+yearPublishing);
		System.out.println("Gia cua cuon sach la: "+price);
		
	}

}

package quanlysach;

import java.util.Scanner;

public class AptechBook extends Book{

	private String language;
	private int semester;
	
	public AptechBook() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param language
	 * @param semester
	 */
	public AptechBook(String language, int semester) {
		super();
		this.language = language;
		this.semester = semester;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public int getSemester() {
		return semester;
	}

	public void setSemester(int semester) {
		this.semester = semester;
	}
	
	@Override
	public void input() {
		Scanner sc = new Scanner(System.in);
		super.input();
		
		System.out.println("Moi ban nhap ngon ngu: ");
		language = sc.nextLine();
		
		System.out.println("Moi ban nhap lan tai ban: ");
		semester = Integer.parseInt(sc.nextLine());
	}
	
	@Override
	public void display() {
		super.display();
		System.out.println("Ngon ngu cuon sach la: "+language);
		System.out.println("Cuon sach tai ban lan thu "+semester);
		System.out.println("---------------------------------------------");
	}
}


package quanlysach;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Test {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		ArrayList<AptechBook> listAp = new ArrayList<AptechBook>();
		
		int choose;
		boolean exit = false;
		int i;
		do {
			menu();
			System.out.println("Moi ban nhap lua chon: ");
			choose = Integer.parseInt(sc.nextLine());
			switch(choose) {
			case 1:
				System.out.println("1. Nhap thong tin n cuon sach Aptech.");
				
				System.out.println("Moi ban nhap so sach can them: ");
				int n = Integer.parseInt(sc.nextLine());
				for( i = 0; i < n; i++) {
					AptechBook aptechBook = new AptechBook();
					aptechBook.input();
					//luu doi tuong aptechBook vao list AptechBook
					listAp.add(aptechBook);
				}
				break;
			case 2:
				System.out.println("2. Hien thi thong tin vua nhap.");
				for(AptechBook ap : listAp) {
					ap.display();
				}
				break;
			case 3:
				System.out.println("3. Sap xep thong tin giam dan theo nam xuat ban va hien thi.");
				
				Collections.sort(listAp, new Comparator<AptechBook>() {

					@Override
					public int compare(AptechBook o1, AptechBook o2) {
						return o1.getYearPublishing() >= o2.getYearPublishing() ? -1:1;
					}
				});
				
				//hien thi
				for( i =0; i <listAp.size(); i++) {
					listAp.get(i).display();
				}
				break;
			case 4:
				System.out.println("4. Tim kiem theo ten sach.");
				
				int count = 0;
				System.out.println("Moi ban nhap ten sach can tim: ");
				String tenSachTK = sc.nextLine();
				for(i = 0; i < listAp.size(); i++) {
					if(listAp.get(i).getBookName().equalsIgnoreCase(tenSachTK)) {
						listAp.get(i).display();
						count++;
					}
				}
				if(count == 0) {
					System.out.println("Khong tim thay ten sach ban can tim");
				}
				break;
			case 5:
				System.out.println("5. Tim kiem theo ten tac gia.");
				
				int count1 = 0;
				System.out.println("Moi ban nhap ten tac gia can tim: ");
				String tacGiaTK = sc.nextLine();
				for(i = 0; i < listAp.size(); i++) {
					if(listAp.get(i).getBookAuthor().equalsIgnoreCase(tacGiaTK)) {
						listAp.get(i).display();
					}
				}
				if(count1 == 0) {
					System.out.println("Khong tim thay tac gia ban can tim");
				}
				break;
			case 6:
				System.out.println("Goodbye!");
				exit = true;
				break;
			default:
				System.out.println("Moi ban chon lua chon duoi menu: ");
				break;
			}
			
		}while(choose != 6);
	}

	static void menu() {
		System.out.println("==============================================================");
		System.out.println("1. Nhap thong tin n cuon sach cua Aptech");
		System.out.println("2. Hien thi thong tin vua nhap");
		System.out.println("3. Sap xep thong tin giam dan theo nam xuat ban va hien thi");
		System.out.println("4. Tim kiem theo ten sach");
		System.out.println("5. Tim kiem theo ten tac gia");
		System.out.println("6. Thoat");
		System.out.println("==============================================================");
	}
}




hoangkhiem [C1907L]
hoangkhiem

2020-03-20 10:26:31



/*
 * 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 baitap2;

import java.util.Scanner;

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

    private String bookName;
    private String bookAuthor;
    private String producer;
    private int yearPublishing;
    private float price;

    public Book() {

    }

    public Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
        this.bookName = bookName;
        this.bookAuthor = bookAuthor;
        this.producer = producer;
        this.yearPublishing = yearPublishing;
        this.price = price;
    }

    public String getBookName() {
        return bookName;
    }

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

    public String getBookAuthor() {
        return bookAuthor;
    }

    public void setBookAuthor(String bookAuthor) {
        this.bookAuthor = bookAuthor;
    }

    public String getProducer() {
        return producer;
    }

    public void setProducer(String producer) {
        this.producer = producer;
    }

    public int getYearPublishing() {
        return yearPublishing;
    }

    public void setYearPublishing(int yearPublishing) {
        this.yearPublishing = yearPublishing;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public void input() {
        //source code
        Scanner input = new Scanner(System.in);
        System.out.println("Mời nhập tên sách : ");
        bookName = input.nextLine();
        System.out.println("Mời nhập tên tác giả của cuốn sách :  ");
        bookAuthor = input.nextLine();
        System.out.println("Mời nhập nhà xuất bản của cuốn sách :");
        producer = input.nextLine();
        System.out.println("Mời nhập năm xuất bản của cuốn sách : ");
        yearPublishing = Integer.parseInt(input.nextLine());
        System.out.println("Mời nhập giá tiền : ");
        price = Integer.parseInt(input.nextLine());

    }

    public void display() {
        System.out.println("Tên sách : " + bookName);
        System.out.println("Tên tác giả : " + bookAuthor);
        System.out.println("Nhà xuất bản : " + producer);
        System.out.println("Năm xuất bản : " + yearPublishing);
        System.out.println("Giá tiền : " + price);
    }
}



/*
 * 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 baitap2;

import java.util.Scanner;

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

    private String language;
    private int semester;

    public AptechBook() {
    }

    public AptechBook(String language, int semester) {
        this.language = language;
        this.semester = semester;
    }

    public AptechBook(String language, int semester, String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
        super(bookName, bookAuthor, producer, yearPublishing, price);
        this.language = language;
        this.semester = semester;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public int getSemester() {
        return semester;
    }

    public void setSemester(int semester) {
        this.semester = semester;
    }

    @Override
    public void input() {
        super.input();
        Scanner input = new Scanner(System.in);
        System.out.println("Ngôn ngữ là : ");
        language = input.nextLine();
        System.out.println("Học kỳ : ");
        semester = Integer.parseInt(input.nextLine());

    }

    public void display() {
        super.display();
        System.out.println("Ngôn ngữ sách là : " + language);
        System.out.println("Học kỳ là : " + semester);
    }

}



/*
 * 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 baitap2;

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

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

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        ArrayList<AptechBook> arr = new ArrayList<>();
        int luachon, sosach = 0;
        do {
            System.out.println("1.Nhập thông tin n cuốn sách của Aptech");
            System.out.println("2.Hiển thị thông tin vừa nhập");
            System.out.println("3.Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            System.out.println("4.Tìm kiếm theo tên sách");
            System.out.println("5.Tìm kiếm theo tên tác giả");
            System.out.println("6.Thoát.");
            System.out.println("Mời lựa chọn ạ ");
            luachon = Integer.parseInt(input.nextLine());
            switch (luachon) {
                case 1:
                    System.out.print("\nNhap vao so sach: ");
                    sosach = Integer.parseInt(input.nextLine());
                    for (int i = 0; i < sosach; i++) {
                        AptechBook sach = new AptechBook();
                        sach.input();
                        arr.add(sach);
                    }
                    break;
                case 2:
                    for (int i = 0; i < sosach; i++) {
                        arr.get(i).display();
                    }
                    break;
                case 3:
                    break;
                case 4:
                    System.out.print("Nhap vao ten sach: ");
                    String tmp = input.nextLine();
                    for (int i = 0; i < sosach; i++) {
                        if (arr.get(i).getBookName().equals(tmp) == true) {
                            arr.get(i).display();
                            break;
                        }
                    }
                    break;
                case 5:
                    break;
                case 6:
                    System.out.println("Tam biet ");
                    break;
                default:
                    System.out.println("Mời bạn lua chon dung");
                    break;

            }
        } while (luachon != 6);
    }
}



Nguyễn Hoàng Anh [C1907L]
Nguyễn Hoàng Anh

2020-03-20 09:40:15



/*
 * 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 bookManager;

/**
 *
 * @author Redmibook 14
 */
public class Book {

    private String bookName;

    private String bookAuthor;

    private String producer;

    private int yearPublishing;

    private float price;

    void Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
        this.bookName = bookName;
        this.bookAuthor = bookAuthor;
        this.producer = producer;
        this.yearPublishing = yearPublishing;
        this.price = price;
    }

    void Book() {
    }

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

    public void setBookAuthor(String bookAuthor) {
        this.bookAuthor = bookAuthor;
    }

    public void setProducer(String producer) {
        this.producer = producer;
    }

    public void setYearPublishing(int yearPublishing) {
        this.yearPublishing = yearPublishing;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public String getBookName() {
        return bookName;
    }

    public String getBookAuthor() {
        return bookAuthor;
    }

    public String getProducer() {
        return producer;
    }

    public int getYearPublishing() {
        return yearPublishing;
    }

    public float getPrice() {
        return price;
    }

    public void input(String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
        this.bookName = bookName;
        this.bookAuthor = bookAuthor;
        this.producer = producer;
        this.yearPublishing = yearPublishing;
        this.price = price;
    }

    public void display() {
        System.out.println("Book name : " + bookName);
        System.out.println("Book author : " + bookAuthor);
        System.out.println("Book producer : " + producer);
        System.out.println("Book year publishing : " + yearPublishing);
        System.out.println("Book price : " + price);
    }
}



/*
 * 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 bookManager;

/**
 *
 * @author Redmibook 14
 */
public class AptechBook extends Book {

    private String language;

    private int semester;

    @Override
    public void Book() {
        super.Book();
    }

    @Override
    public void Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
        super.Book(bookName, bookAuthor, producer, yearPublishing, price);
    }
    
 
        
    public void setLanguage(String language) {
        this.language = language;
    }

    public void setSemester(int semester) {
        this.semester = semester;
    }

    public String getLanguage() {
        return language;
    }

    public int getSemester() {
        return semester;
    }

    @Override
    public void input(String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
        super.input(bookName, bookAuthor, producer, yearPublishing, price);
    }

    public void input(String language, int semester) {
        this.language = language;
        this.semester = semester;
    }
    @Override
    public void display(){
        super.display();
        System.out.println("Language : " + language);
        System.out.println("Semester : " + semester);
    }
}



/*
 * 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 bookManager;

import java.util.*;

/**
 *
 * @author Redmibook 14
 */
public class Test {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        ArrayList<AptechBook> arrBook = new ArrayList();
        while (true) {
            System.out.println("1.    Nhập thông tin n cuốn sách của Aptech");
            System.out.println("2.    Hiển thị thông tin vừa nhập");
            System.out.println("3.    Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            System.out.println("4.    Tìm kiếm theo tên sách");
            System.out.println("5.    Tìm kiếm theo tên tác giả");
            System.out.println("6.    Thoát.");
            String choice = input.nextLine();
            switch (choice) {
                case "1":
                    System.out.println("Nhập số lượng cuốn sách : ");
                    int n = Integer.parseInt(input.nextLine());
                    for (int i = 0; i < n; i++) {
                        AptechBook aptechbook = new AptechBook();
                        System.out.println("Nhập thông tin cuốn sách " + (i + 1));
                        System.out.println("Tên sách : ");
                        String bookName = input.nextLine();
                        System.out.println("Tên tác giả : ");
                        String bookAuthor = input.nextLine();
                        System.out.println("Tên biên tập : ");
                        String producer = input.nextLine();
                        System.out.println("Năm phát hành : ");
                        int yearPublishing = Integer.parseInt(input.nextLine());
                        System.out.println("Giá sách : ");
                        float price = Float.parseFloat(input.nextLine());
                        System.out.println("Ngôn ngữ : ");
                        String language = input.nextLine();
                        System.out.println("Semester : ");
                        int semester = Integer.parseInt(input.nextLine());
                        aptechbook.input(bookName, bookAuthor, producer, yearPublishing, price);
                        aptechbook.input(language, semester);
                        arrBook.add(aptechbook);
                    }

                    break;
                case "2":
                    for (int i = 0; i < arrBook.size(); i++) {
                        arrBook.get(i).display();
                        System.out.println(".........");
                    }
                    break;
                case "3":
                    Collections.sort(arrBook, new yearComparator());
                    for (int i = 0; i < arrBook.size(); i++) {
                        arrBook.get(i).display();
                        System.out.println(".........");
                    }
                    break;
                case "4":
                    System.out.println("Nhập tên sách : ");
                    String ten = input.nextLine();
                    int flag = 1;
                    for (int i = 0; i < arrBook.size(); i++) {
                        if (arrBook.get(i).getBookName().equals(ten) == true) {
                            arrBook.get(i).display();
                            flag = 2;
                        }
                    }
                    if(flag == 1){
                        System.out.println("Không có quyển sách nào");
                    }
                    break;
                case "5":
                    System.out.println("Nhập tên tác giả : ");
                    String tenTacGia = input.nextLine();
                    int flag2 = 1;
                    for (int i = 0; i < arrBook.size(); i++) {
                        if (arrBook.get(i).getBookAuthor().equals(tenTacGia) == true) {
                            arrBook.get(i).display();
                            flag2 = 2;
                        }
                    }
                      if(flag2 == 1){
                        System.out.println("Không có tác giả nào");
                    }
                    break;
                case "6":
                    return;

            }
        }
    }
}



/*
 * 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 bookManager;
import java.util.*;
/**
 *
 * @author Redmibook 14
 */
class yearComparator implements Comparator<AptechBook> {
   
    public int compare(AptechBook b1,AptechBook b2){
        if(b1.getYearPublishing() == b2.getYearPublishing()){
            return 0;
        }else if(b1.getYearPublishing() > b2.getYearPublishing()){
            return 1;
        }else{
            return -1;
        }
    }
}



trung [C1907L]
trung

2020-03-19 15:18:51



package test;

import java.util.Scanner;

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

    private String bookName;
    private String bookAuthor;
    private String producer;
    private int yearPublishing;
    private float price;

    public Book() {
    }

    public Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
        this.bookName = bookName;
        this.bookAuthor = bookAuthor;
        this.producer = producer;
        this.yearPublishing = yearPublishing;
        this.price = price;
    }

    public String getBookName() {
        return bookName;
    }

    public String getBookAuthor() {
        return bookAuthor;
    }

    public String getProducer() {
        return producer;
    }

    public int getYearPublishing() {
        return yearPublishing;
    }

    public float getPrice() {
        return price;
    }

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

    public void setBookAuthor(String bookAuthor) {
        this.bookAuthor = bookAuthor;
    }

    public void setProducer(String producer) {
        this.producer = producer;
    }

    public void setYearPublishing(int yearPublishing) {
        this.yearPublishing = yearPublishing;
    }

    public void setPrice(float price) {
        this.price = price;
    }

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

        System.out.println("Nhap vao tac gia: ");
        this.bookAuthor = input.nextLine();

        System.out.println("Nhap vao producer: ");
        this.producer = input.nextLine();

        System.out.println("Nhap vao nam xuat ban: ");
        this.yearPublishing = Integer.parseInt(input.nextLine());

        System.out.println("Nhap vao gia sach: ");
        this.price = Float.parseFloat(input.nextLine());
    }

    public void display() {
        System.out.format("ten sach: %s\n", this.bookName);
        System.out.format("tac gia: %s\n", this.bookAuthor);
        System.out.format("producer: %s\n", this.producer);
        System.out.format("nam xuat ban: %d\n", this.yearPublishing);
        System.out.format("gia sach: %f\n", this.price);
    }
}



/*
 * 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 test;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class AptechBook extends Book{
    private String language;
    private int semester;

    public AptechBook() {
        super();
    }

    public AptechBook(String language, int semester) {
        this.language = language;
        this.semester = semester;
    }

    public AptechBook(String language, int semester, String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
        super(bookName, bookAuthor, producer, yearPublishing, price);
        this.language = language;
        this.semester = semester;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public int getSemester() {
        return semester;
    }

    public void setSemester(int semester) {
        this.semester = semester;
    }

    @Override
    public void input() {
        Scanner input = new Scanner(System.in);
        super.input();
        System.out.println("Nhap vao language: ");
        this.language = input.nextLine();
        System.out.println("Nhap vao semester: ");
        this.semester = Integer.parseInt(input.nextLine());
    }
    
    @Override
    public void display() {
        super.display();
        System.out.format("Language la: %s",this.language);
        System.out.format("Language la: %d",this.semester);
    }
    
}



/*
 * 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 test;

import java.util.Scanner;
import java.lang.Math;
import java.util.ArrayList;

/**
 *
 * @author prdox
 */
//Viết chương trình hiển thị thông tin cá nhân của bạn bao gồm (tên, tuổi, địa chỉ, email, sđt)
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N = Integer.parseInt(input.nextLine());
        ArrayList<AptechBook> arr = new ArrayList<AptechBook>();
        Boolean exit = false;
        while (!exit) {
            System.out.println("Select option: ");
            System.out.println("1.    Nhập thông tin n cuốn sách của Aptech");
            System.out.println("2.    Hiển thị thông tin vừa nhập");
            System.out.println("3.    Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            System.out.println("4.    Tìm kiếm theo tên sách");
            System.out.println("5.    Tìm kiếm theo tên tác giả");
            System.out.println("6.    Thoát.");
            int option = Integer.parseInt(input.nextLine());
            switch (option) {
                case 1:
                    for (int i = 0; i < N; i++) {
                        arr.add(new AptechBook());
                        arr.get(arr.size() - 1).input();
                    }
                    break;
                case 2:
                    for (int i = 0; i < N; i++) {
                        arr.get(arr.size() - 1).display();
                    }
                    break;
                case 3:
                    for (int i = 0; i < N - 1; i++) {
                        for (int j = i + 1; j < N; j++) {
                            if (arr.get(i).getYearPublishing() < arr.get(j).getYearPublishing()) {
                                AptechBook temp = arr.get(j);
                                arr.set(j, arr.get(i));
                                arr.set(i, temp);
                            }
                        }
                    }
                    for (int i = 0; i < N; i++) {
                        arr.get(arr.size() - 1).display();
                    }
                    break;
                case 4:
                    System.out.println("Nhap vao ten sach can tim kiem: ");
                    String tenSach = input.nextLine();
                    for (int i = 0; i < N; i++) {
                        if (arr.get(i).getBookName() == tenSach) {
                            System.out.format("Ten sach la: %s", arr.get(i).getBookName());
                            arr.get(i).display();
                        }
                    }
                    break;
                case 5:
                    System.out.println("Nhap vao ten tac gia can tim kiem: ");
                    String tacgia = input.nextLine();
                    for (int i = 0; i < N; i++) {
                        if (arr.get(i).getBookAuthor() == tacgia) {
                            System.out.format("Ten sach la: %s", arr.get(i).getBookName());
                        }
                    }
                    break;
                case 6:
                    exit = true;
                    break;

            }
        }

        // Sap xep
        //Tim kiem theo ten tac gia
    }

}



Hoàng Quang Huy [C1907L]
Hoàng Quang Huy

2020-03-19 06:50:01



//Class Book
package Lesson4;
import java.util.*;

public class Book {

    private String bookName;
    private String bookAuthor;
    private String producer;
    private int yearPublishing;
    private float price;
    
    public Book(){}
    
    public Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
        this.bookName = bookName;
        this.bookAuthor = bookAuthor;
        this.producer = producer;
        this.yearPublishing = yearPublishing;
        this.price = price;
    }

    public String getBookName() {
        return bookName;
    }

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

    public String getBookAuthor() {
        return bookAuthor;
    }

    public void setBookAuthor(String bookAuthor) {
        this.bookAuthor = bookAuthor;
    }

    public String getProducer() {
        return producer;
    }

    public void setProducer(String producer) {
        this.producer = producer;
    }

    public int getYearPublishing() {
        return yearPublishing;
    }

    public void setYearPublishing(int yearPublishing) {
        this.yearPublishing = yearPublishing;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }
    // Hàm nhập
    public void input(){
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập tên sách: ");
        bookName = input.nextLine();
        System.out.println("Nhập tên tác giả: ");
        bookAuthor = input.nextLine();
        System.out.println("Nhập tên nhà sản xuất: ");
        producer = input.nextLine();
        System.out.println("Nhập năm xuất bản: ");
        yearPublishing = Integer.parseInt(input.nextLine());
        System.out.println("Nhập giá tiền: ");
        price = Float.parseFloat(input.nextLine());
    }
    
    //Hàm xuất
    public void display(){
        System.out.println("Tên sách: "+bookName);
        System.out.println("Tên tác giả: "+bookAuthor);
        System.out.println("Tên nhà xuất bản: "+producer);
        System.out.println("Năm xuất bản: "+yearPublishing);
        System.out.println("Giá tiền: "+price);
    }
}
-------------------------------------------------------------------------------------

//Class AptechBook extends Book
package Lesson4;
import java.util.*;

public class AptechBook extends Book {

    private String language;
    private int semester;

    public String getLanguage() {
        return language;
    }

    public AptechBook() {
        super();
    }

    public AptechBook(String language, int semester, String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
        super(bookName, bookAuthor, producer, yearPublishing, price);
        this.language = language;
        this.semester = semester;
    }
    
    public void setLanguage(String language) {
        this.language = language;
    }

    public int getSemester() {
        return semester;
    }

    public void setSemester(int semester) {
        this.semester = semester;
    }
    
    @Override
    public void input(){
        Scanner input = new Scanner(System.in);
        super.input();
        System.out.println("Nhập ngôn ngữ: ");
        language = input.nextLine();
        System.out.println("Nhập kỳ học: ");
        semester = Integer.parseInt(input.nextLine());
    }
    
    @Override
    public void display(){
        super.display();
        System.out.println("Ngôn ngữ:  "+ language);
        System.out.println("Kỳ học: "+semester);
    }
}

-------------------------------------------------------------------------------------

package Lesson4;

import java.util.*;

public class Test {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int n;
        String authorname;
        String bookname;
        int choice;
        int countbook =0;
        int countauthor=0;
        boolean flag = true;
        ArrayList<AptechBook> books = new ArrayList<>();
        while (flag) {
            System.out.println("1. Nhập thông tin n cuốn sách của Aptech");
            System.out.println("2. Hiển thị thông tin vừa nhập");
            System.out.println("3. Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            System.out.println("4. Tìm kiếm theo tên sách");
            System.out.println("5. Tìm kiếm theo tên tác giả");
            System.out.println("6. Thoát.");
            System.out.println("Lựa chọn của bạn: ");
            choice = Integer.parseInt(input.nextLine());
            switch (choice) {
                case 1:
                    System.out.println("Nhập n: ");
                    n = Integer.parseInt(input.nextLine());
                    for (int i = 0; i < n; i++) {
                        AptechBook book = new AptechBook();
                        System.out.println("- Nhập thông tin cho quyển sách thứ " + (i + 1));
                        book.input();
                        books.add(book);
                    }
                    break;
                case 2:
                    for (int i = 0; i < books.size(); i++) {
                        System.out.println("- Thông tin quyển sách thứ " + (i + 1));
                        books.get(i).display();
                    }
                    break;
                case 3:
                    for (int i = 0; i < books.size() - 1; i++) {
                        for (int j = i + 1; j < books.size(); j++) {
                            if (books.get(i).getYearPublishing() < books.get(j).getYearPublishing()) {
                                Collections.swap(books, i, j);
                            }
                        }
                    }
                    System.out.println("- Thông tin sách sau khi sắp xếp theo năm xuất bản giảm dần là: ");
                    for (int i = 0; i < books.size(); i++) {
                        books.get(i).display();
                        System.out.println("-----------------");
                    }
                    break;
                case 4:
                    System.out.println("Nhập tên sách cần tìm kiếm: ");
                    bookname = input.nextLine();
                    countbook = 0;
                    for (int i = 0; i < books.size(); i++) {
                        if (books.get(i).getBookName().equals(bookname)) {
                            books.get(i).display();
                            System.out.println("-----------------");
                            countbook++;
                        }
                    }if(countbook == 0){
                       System.out.println("Không tìm thấy sách mà bạn cần tìm");     
                            }
                    
                    break;
                case 5:
                    System.out.println("Nhập tên tác giả cần tìm kiếm: ");
                    authorname = input.nextLine();
                    countauthor = 0;
                    for (int i = 0; i < books.size(); i++) {
                        if (books.get(i).getBookAuthor().equals(authorname)) {
                            
                            books.get(i).display();
                            System.out.println("-----------------");
                            countauthor++;
                        }
                    }
                    if(countauthor == 0){
                       System.out.println("Không tìm thấy sách mà bạn cần tìm");     
                            }
                    break;
                case 6:
                    System.out.println("Thoát chương trình");
                    flag = false;
                    break;
                default:
                    System.out.println("Lựa chọn không hợp lệ");
                    break;
            }
        }
    }
}