By GokiSoft.com| 19:30 17/04/2024|
Java Basic

Java Basic- OOP - căn bản - quản lý sách bằng java

Viết chương trình quản lý sách.

Viết chương trình thực hiện quả lý thư viện trường Aptech. Chương trình cần quản lý các đối tượng sau

- Nhà xuất bản gồm các thuộc tính : tên nhà xuất bản, ngày thành lập, tên người đại diện, năm thành lập

Viết các hàm nhập và hiển thị tất cả các thuộc tính cảu nhà xuất bản này

- Lớp đối tượng tác giả gồm các thuộc tính : tên tác giả, bút danh, ngày sinh

Viết hàm nhập và hạm hiển thị tất cả các thuộc tính của lớp đối tượng

- Sách gồm các thuộc tính : bút danh tác giả, nhà xuất bản, tên sách, (Tự thêm các thuộc tính cần thiết của sách vào)

Viết hàm nhập và hàm hiển thị 

Yêu cầu:

- Tạo các class object tương ứng

- Tạo getter/setter

- Tạo hàm tạo cho class object

- Viết các hàm nhập và hiển thị cho từng class object

- Viết đoạn chương trình khai báo 3 đối tượng nhà xuất bản, tác giả, sách.

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

5

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

Trần Nhựt Linh [java1_online]
Trần Nhựt Linh

2023-04-07 16:15:03




/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 */

package com.mycompany.qlthuvienapt;


/**
 *
 * @author mymem
 */
public class QLthuvienApt {

    public static void main(String[] args) {
        NhaXuatBan nxb1 = new NhaXuatBan();
        NhaXuatBan nxb2 = new NhaXuatBan("NXB B","02/02","Tran Van B","2002");
        
        nxb1.input();
        nxb1.display();
        nxb2.display();
        
        TacGia tg1 = new TacGia();
        TacGia tg2 = new TacGia("Mr Honda","Vario","1990");
        
        System.out.println();;
        
        tg1.input();
        tg1.display();
        tg2.display();
        
        
        Sach s1 = new Sach();
        Sach s2 = new Sach("Doremon","Fujisu","NXB A","1992","Truyen tranh");
        
        System.out.println();;
        
        s1.input();
        s1.display();
        s2.display();
    }
}



Trần Nhựt Linh [java1_online]
Trần Nhựt Linh

2023-04-07 16:14:41



/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.mycompany.qlthuvienapt;

import java.util.Scanner;

/**
 *
 * @author mymem
 */
public class Sach {
    String ten, tenTG, tenNXB,namXB,theLoai;

    public String getTen() {
        return ten;
    }

    public String getTenTG() {
        return tenTG;
    }

    public String getTenNXB() {
        return tenNXB;
    }

    public String getNamXB() {
        return namXB;
    }

    public String getTheLoai() {
        return theLoai;
    }

    public void setTen(String ten) {
        this.ten = ten;
    }

    public void setTenTG(String tenTG) {
        this.tenTG = tenTG;
    }

    public void setTenNXB(String tenNXB) {
        this.tenNXB = tenNXB;
    }

    public void setNamXB(String namXB) {
        this.namXB = namXB;
    }

    public void setTheLoai(String theLoai) {
        this.theLoai = theLoai;
    }
     
   

   

    public Sach() {
    }

    public Sach(String ten, String tenTG, String tenNXB, String namXB, String theLoai) {
        this.ten = ten;
        this.tenTG = tenTG;
        this.tenNXB = tenNXB;
        this.namXB = namXB;
        this.theLoai = theLoai;
    }

    
    public void input(){
        Scanner input = new Scanner(System.in);
        System.out.print("Nhap ten sach: ");
        ten = input.nextLine();
        System.out.print("Nhap ten TG: ");
        tenTG= input.nextLine();
        System.out.print("Nhap ten NXB: ");
        tenNXB = input.nextLine();
        System.out.print("Nhap nam XB: ");
        namXB = input.nextLine();
        System.out.print("Nhap the loai: ");
        theLoai = input.nextLine();
    }

    @Override
    public String toString() {
        return "Sach{" + "ten=" + ten + ", tenTG=" + tenTG + ", tenNXB=" + tenNXB + ", namXB=" + namXB + ", theLoai=" + theLoai + "} ";
    }

    

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



Trần Nhựt Linh [java1_online]
Trần Nhựt Linh

2023-04-07 16:14:17



/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.mycompany.qlthuvienapt;

import java.util.Scanner;

/**
 *
 * @author mymem
 */
public class TacGia {
    String ten,butDanh, ngaySinh;

    public String getTen() {
        return ten;
    }

    public String getButDanh() {
        return butDanh;
    }

    public String getNgaySinh() {
        return ngaySinh;
    }

    public void setTen(String ten) {
        this.ten = ten;
    }

    public void setButDanh(String butDanh) {
        this.butDanh = butDanh;
    }

    public void setNgaySinh(String ngaySinh) {
        this.ngaySinh = ngaySinh;
    }

   

   

    public TacGia() {
    }

    public TacGia(String ten, String butDanh, String ngaySinh) {
        this.ten = ten;
        this.butDanh = butDanh;
        this.ngaySinh = ngaySinh;
    }

   
    public void input(){
        Scanner input = new Scanner(System.in);
        System.out.print("Nhap ten tac gia: ");
        ten = input.nextLine();
        System.out.print("Nhap but danh TG: ");
        butDanh= input.nextLine();
        System.out.print("Nhap ngay sinh TG: ");
        ngaySinh = input.nextLine();
       
    }

    @Override
    public String toString() {
        return "TacGia{" + "ten=" + ten + ", butDanh=" + butDanh + ", ngaySinh=" + ngaySinh + "} ";
    }

    

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



Do Trung Duc [T2008A]
Do Trung Duc

2021-02-21 07:48:13



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

import java.util.Scanner;

/**
 *
 * @author TrungDuc
 */
public class Producer {
   Scanner scan = new Scanner(System.in);
    private String nameProducer, establishDay, Director;

    public Producer() {
    }

    public Producer(String nameProducer, String establishDay, String Director) {
        this.nameProducer = nameProducer;
        this.establishDay = establishDay;
        this.Director = Director;
    }

    public String getNameProducer() {
        return nameProducer;
    }

    public String getEstablishDay() {
        return establishDay;
    }

    public String getDirector() {
        return Director;
    }

    public void setNameProducer(String nameProducer) {
        this.nameProducer = nameProducer;
    }

    public void setEstablishDay(String establishDay) {
        this.establishDay = establishDay;
    }

    public void setDirector(String Director) {
        this.Director = Director;
    }
    
    public void inputProducer(){
        System.out.println("Nhap ten nha xuat ban");
        nameProducer = scan.nextLine();
        
                System.out.println("Nhap ngay thanh lap nha xuat ban");
        establishDay = scan.nextLine();
        
                System.out.println("Nhap ten dai dien nha xuat ban");
        Director = scan.nextLine();
    }
    
        public void displayProducer(){
        System.out.println("Ten: " + nameProducer + ", Ngay thanh lap: "+ establishDay + ", Nguoi dai dien: "+ Director);
    }

}



Do Trung Duc [T2008A]
Do Trung Duc

2021-02-21 07:47:50



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

import java.util.ArrayList;

public class Main {
     public static void main(String[] args) {
         
         ArrayList<Producer> listProducer = new ArrayList<>();
         ArrayList<Author> listAuthor = new ArrayList<>();
         ArrayList<Book> listBook = new ArrayList<>();
         
         for(int i=0;i<3;i++){
             Producer producer = new Producer();
             producer.inputProducer();
             listProducer.add(producer);
         }
         
        for(int i=0;i<3;i++){
            listProducer.get(i).displayProducer();
         }
        
}
}



vuong huu phu [T2008A]
vuong huu phu

2021-02-02 08:16:17



/*
 * 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 buoi.pkg2;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class NHa_san_xuat {
    String Ten_nha_sx;
    int ngay_thanh_lap;
    int nam_sx;
    String Ten_ng_dai_dien;

Scanner scan = new Scanner(System.in);

    public NHa_san_xuat() {
    }

    public NHa_san_xuat(String Ten_nha_sx, int ngay_thanh_lap, int nam_sx, String Ten_ng_dai_dien) {
        this.Ten_nha_sx = Ten_nha_sx;
        this.ngay_thanh_lap = ngay_thanh_lap;
        this.nam_sx = nam_sx;
        this.Ten_ng_dai_dien = Ten_ng_dai_dien;
    }

    public String getTen_nha_sx() {
        return Ten_nha_sx;
    }

    public int getNgay_thanh_lap() {
        return ngay_thanh_lap;
    }

    public int getNam_sx() {
        return nam_sx;
    }

    public String getTen_ng_dai_dien() {
        return Ten_ng_dai_dien;
    }

    

    public void setTen_nha_sx(String Ten_nha_sx) {
        this.Ten_nha_sx = Ten_nha_sx;
    }

    public void setNgay_thanh_lap(int ngay_thanh_lap) {
        this.ngay_thanh_lap = ngay_thanh_lap;
    }

    public void setNam_sx(int nam_sx) {
        this.nam_sx = nam_sx;
    }

    public void setTen_ng_dai_dien(String Ten_ng_dai_dien) {
        this.Ten_ng_dai_dien = Ten_ng_dai_dien;
    }

   

public void nhap(){
System.out.println();
System.out.print("Ten nsx");
Ten_nha_sx = scan.nextLine();
System.out.print("ngay thanh lap");
ngay_thanh_lap = Integer.parseInt(scan.nextLine());
System.out.print("Nam thanh lap");
nam_sx= Integer.parseInt(scan.nextLine());
System.out.print("ng dai dien");
Ten_ng_dai_dien = scan.nextLine();
}
public void hien_thi(){
System.out.println("Ten nha san xuat: "+Ten_nha_sx);
System.out.println("Ngay thanh lap: "+ngay_thanh_lap);
System.out.println("Nam thanh lap: "+nam_sx);
System.out.println("Ten nguoi dai dien: "+Ten_ng_dai_dien);
}
}



vuong huu phu [T2008A]
vuong huu phu

2021-02-02 08:16:04



/*
 * 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 buoi.pkg2;

import java.util.Scanner;

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

    String But_danh;
    String Ten_tac_gia;
    String ngay_sinh;

    public Tac_gia(String But_danh, String Ten_tac_gia, String ngay_sinh) {
        this.But_danh = But_danh;
        this.Ten_tac_gia = Ten_tac_gia;
        this.ngay_sinh = ngay_sinh;
    }

    public Tac_gia() {
    }

    public String getBut_danh() {
        return But_danh;
    }

    public void setBut_danh(String But_danh) {
        this.But_danh = But_danh;
    }

    public String getTen_tac_gia() {
        return Ten_tac_gia;
    }

    public void setTen_tac_gia(String Ten_tac_gia) {
        this.Ten_tac_gia = Ten_tac_gia;
    }

    public String getNgay_sinh() {
        return ngay_sinh;
    }

    public void setNgay_sinh(String ngay_sinh) {
        this.ngay_sinh = ngay_sinh;
    }
    public void nhap(){
        Scanner scan = new Scanner(System.in);
    System.out.println("Nhap but danh");
    But_danh = scan.nextLine();
    System.out.println("Ten tac gia");
    Ten_tac_gia = scan.nextLine();
    System.out.println("Ngay sinh");
     ngay_sinh=scan.nextLine(); 

    }
    public void hien_thi(){
    System.out.print("But danh: "+But_danh );
    System.out.print("ten tac gia: "+Ten_tac_gia );
    System.out.print("ngay_sinh: "+ngay_sinh );
    }
}



vuong huu phu [T2008A]
vuong huu phu

2021-02-02 08:15:50



/*
 * 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 buoi.pkg2;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Sach {
    String Ten_sach; 
    String Nha_xuat_ban;
    String Ten_tac_gia;
    String But_danh;

Scanner scan = new Scanner(System.in);
public void nhap(){
System.out.println("Nhap ten sach: ");
Ten_sach = scan.nextLine();
System.out.println("Nhap ten nha xuat ban");
Nha_xuat_ban= scan.nextLine();
System.out.println("Nhap ten tac gia");
Ten_tac_gia= scan.nextLine();
System.out.println("Nhap but danh");
But_danh= scan.nextLine();
}
public void hien_thi(){
System.out.format("Ten sach: %s , Ten nha san xuat: %s  , Ten tac gia: %s , But danh: %s",Ten_sach,Nha_xuat_ban,Ten_tac_gia,But_danh);
}

    public Sach() {
    }

    public Sach(String Ten_sach, String Nha_xuat_ban, String Ten_tac_gia, String But_danh) {
        this.Ten_sach = Ten_sach;
        this.Nha_xuat_ban = Nha_xuat_ban;
        this.Ten_tac_gia = Ten_tac_gia;
        this.But_danh = But_danh;
    }

    public String getTen_sach() {
        return Ten_sach;
    }

    public void setTen_sach(String Ten_sach) {
        this.Ten_sach = Ten_sach;
    }

    public String getNha_xuat_ban() {
        return Nha_xuat_ban;
    }

    public void setNha_xuat_ban(String Nha_xuat_ban) {
        this.Nha_xuat_ban = Nha_xuat_ban;
    }

    public String getTen_tac_gia() {
        return Ten_tac_gia;
    }

    public void setTen_tac_gia(String Ten_tac_gia) {
        this.Ten_tac_gia = Ten_tac_gia;
    }

    public String getBut_danh() {
        return But_danh;
    }

    public void setBut_danh(String But_danh) {
        this.But_danh = But_danh;
    }

    public Scanner getScan() {
        return scan;
    }

    public void setScan(Scanner scan) {
        this.scan = scan;
    }
    
}



vuong huu phu [T2008A]
vuong huu phu

2021-02-02 08:15:32



/*
 * 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 buoi.pkg2;

import java.util.Scanner;

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

    public static void main(String[] args) {
        int lua_chon;
        NHa_san_xuat nsx = new NHa_san_xuat();
        Tac_gia tg = new Tac_gia();
        Sach sach = new Sach();
        Scanner scan = new Scanner(System.in);
        do {
            menu();
            System.out.print("Nhap lua chon: ");
            lua_chon = Integer.parseInt(scan.nextLine());
            switch (lua_chon) {
                case 1:
                    nsx.nhap();
                    break;
                case 2:
                    nsx.hien_thi();
                    break;
                case 3:
                    tg.nhap();
                    break;
                case 4:
                    tg.hien_thi();
                    break;
                case 5:
                    sach.nhap();
                    break;
                case 6:
                    sach.hien_thi();
                    break;

            }
        } while (lua_chon != 7);
    }

    static void menu() {
        System.out.println(" 1 nhap nha san xuat: ");
        System.out.println(" 2 hien thi nha san xuat: ");
        System.out.println(" 3 nhap tac gia: ");
        System.out.println(" 4 hien thi tac gia: ");
        System.out.println(" 5 nhap sach: ");
        System.out.println(" 6 hien thi sach: ");
        System.out.println(" 7 thoat");

    }
}



Nguyễn Tiến Đạt [T2008A]
Nguyễn Tiến Đạt

2021-01-30 07:20:01


#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 lesson4.ThuVienAptech;

/**
 *
 * @author MyPC
 */
public class Main {
    public static void main(String[] args) {
        Sach book = new Sach();
        book.input();
        book.display();
        TacGia author = new TacGia();
        author.input();
        author.display();
        NhaXuatBan manu = new NhaXuatBan();
        manu.input();
        manu.display();
    }
}

#NhaXuatBan

/*
 * 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 lesson4.ThuVienAptech;
import java.util.Scanner;

/**
 *
 * @author MyPC
 */
public class NhaXuatBan {
    String foundDay, manuName, representativeName;
    int foundYear;
    
    public NhaXuatBan(){
    }
    public NhaXuatBan(String manuName, String representativeName, String foundDay, int foundYear) {
        this.manuName = manuName;
        this.representativeName = representativeName;
        this.foundDay = foundDay;
        this.foundYear = foundYear;
    }

    public String getManuName() {
        return manuName;
    }

    public void setManuName(String manuName) {
        this.manuName = manuName;
    }

    public String getRepresentativeName() {
        return representativeName;
    }

    public void setRepresentativeName(String representativeName) {
        this.representativeName = representativeName;
    }

    public String getFoundDay() {
        return foundDay;
    }

    public void setFoundDay(String foundDay) {
        this.foundDay = foundDay;
    }

    public int getFoundYear() {
        return foundYear;
    }

    public void setFoundYear(int foundYear) {
        this.foundYear = foundYear;
    }
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Ten nha xuat ban:");
        manuName = scan.nextLine();
        System.out.println("Ngay thanh lap:");
        foundDay = scan.nextLine();
        System.out.println("Ten nguoi dai dien:");
        representativeName = scan.nextLine();
        System.out.println("Nam thanh lap:");
        foundYear = scan.nextInt();
    }

    @Override
    public String toString() {
        return "NhaXuatBan{" + " foundDay=" + foundDay + ", manuName=" + manuName + ", representativeName=" + representativeName + ", foundYear=" + foundYear + '}';
    }
    
    public void display(){
        System.out.println(this);
    }
    
}


#TacGia
/*
 * 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 lesson4.ThuVienAptech;
import java.util.Scanner;

/**
 *
 * @author MyPC
 */
public class TacGia extends NhaXuatBan{
    String authorName, penName, birthDate;
    
    public TacGia(){
    }
    public TacGia(String authorName, String penName, String birthDate) {
        this.authorName = authorName;
        this.penName = penName;
        this.birthDate = birthDate;
    }

    public String getAuthorName() {
        return authorName;
    }

    public void setAuthorName(String authorName) {
        this.authorName = authorName;
    }

    public String getPenName() {
        return penName;
    }

    public void setPenName(String penName) {
        this.penName = penName;
    }

    public String getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(String birthDate) {
        this.birthDate = birthDate;
    }

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Ten tac gia:");
        authorName = scan.nextLine();
        System.out.println("But danh:");
        penName = scan.nextLine();
        System.out.println("Ngay sinh:");
        birthDate = scan.nextLine();
    }

    @Override
    public String toString() {
        return "TacGia{" + " authorName=" + authorName + ", penName=" + penName + ", birthDate=" + birthDate + '}';
    }

    @Override
    public void display() {
        System.out.println(this);
    }
    
    
}

#Sach
/*
 * 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 lesson4.ThuVienAptech;
import java.util.Scanner;

/**
 *
 * @author MyPC
 */
public class Sach extends TacGia{
    String bookName;
    float price;
    
    public Sach(){
        
    }

    public Sach(String penName , String manuName, String bookName, float price) {
        this.penName = penName;
        this.manuName = manuName;
        this.bookName = bookName;
        this.price = price;
    }

    public String getBookName() {
        return bookName;
    }

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

    public float getPrice() {
        return price;
    }

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

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("But danh:");
        penName = scan.nextLine();
        System.out.println("Ten nha xuat ban:");
        manuName = scan.nextLine();
        System.out.println("Ten sach:");
        bookName = scan.nextLine();
        System.out.println("Gia tien:");
        price = scan.nextFloat();
    }

    @Override
    public String toString() {
        return "Sach{" + " penName=" + penName + ", manuName=" + manuName + ", bookName=" + bookName + ", price=" + price + '}';
    }

    @Override
    public void display() {
        System.out.println(this);
    }
    
    
    
}



Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó