PERSON.java public class PERSON { private String name,diachi; private char gioitinh; public PERSON(String _name,String _diachi,char _gioitinh) { this.name=_name; this.diachi=_diachi; this.gioitinh=_gioitinh; } public String getName() { return name; } public char getGioitinh() { return gioitinh; } public String getDiachi() { return diachi; } public String toStringP() { return "\nTen:"+name+"\nDia chi:"+diachi+"\nGioi tinh:"+gioitinh; } }
Class: Author:
AUTHOR.java public class AUTHOR extends PERSON { private String hocvi,chuyennganh; public AUTHOR(String _name,char _gioitinh,String _diachi,String _hocvi,String _chuyennganh) { super(_name, _diachi, _gioitinh); this.hocvi=_hocvi; this.chuyennganh=_chuyennganh; } public String getHocvi() { return hocvi; } public void setHocvi(String _hocvi) { hocvi=_hocvi; } public String getChuyennganh() { return chuyennganh; } public String toString() { return toStringP()+"\nHoc vi:"+hocvi+"\nChuyen nganh:"+chuyennganh; } }
Class Book:
BOOK.java public class BOOK { private int isbn,sotrang; private String tensach,theloai,noidung; private double gia; private int count=0; private AUTHOR _author[]=new AUTHOR[3]; public BOOK(int _isbn,int _sotrang,String _tensach,Double _gia,String _theloai,String _noidung) { this.isbn=_isbn; this.sotrang=_sotrang; this.tensach=_tensach; this.gia=_gia; this.theloai=_theloai; this.noidung=_noidung; } public void addAuthor(AUTHOR __author) { _author[count]=__author; count++; } public void printAuthor() { for (int i = 0; i < count; i++) { System.out.println(_author[i])
; } } public String toString() { return "\nISBN:"+isbn+"\nSo trang:"+sotrang+"\nTen sach:"+tensach+"\nGia:"+gia+"\ nThe loai:"+theloai+"\nNoi dung:"+noidung; } }
Class Main:
Main.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); BOOK b1=new BOOK(123,321,"LTHDT",50000.0,"
CNTT","CNTT"); int soluongtg; System.out.println("Nhap so luong tac gia:"); soluongtg=Integer.parseInt(in. readLine()); String ten,dc,hv,cn; char gt; if (soluongtg <=3) { for (int i = 1; i <= soluongtg; i++) { System.out.println("Nhap ten"); ten=in.readLine(); System.out.println("nhap gioi tinh"); String gt2=in.readLine(); gt=gt2.charAt(0); System.out.println("dia chi"); dc=in.readLine(); System.out.println("Hoc vi"); hv=in.readLine(); System.out.println("chuyen nganh"); cn=in.readLine(); b1.addAuthor(new AUTHOR(ten,gt,dc,hv,cn)); } } else System.out.println("Chi co the nhap 3 tac gia !"); System.out.println(b1.toString ()); b1.printAuthor(); } }
0 comments:
Post a Comment