News Ticker

Menu

Giải Đề Thi Java - Lần 2



Link download đề: Click Download
Link download project: Click Download

Kham Khảo
Class TaiLieu
import java.util.*;

public abstract class TaiLieu {

 private String MaSo, TenNhaSX;
 private int SoBanPhatHanh;
 
 public String getMaSo() {
  return MaSo;
 }
 public void setMaSo(String maSo) {
  MaSo = maSo;
 }
 public String getTenNhaSX() {
  return TenNhaSX;
 }
 public void setTenNhaSX(String tenNhaSX) {
  TenNhaSX = tenNhaSX;
 }
 public int getSoBanPhatHanh() {
  return SoBanPhatHanh;
 }
 public void setSoBanPhatHanh(int soBanPhatHanh) {
  SoBanPhatHanh = soBanPhatHanh;
 }
 
 public TaiLieu() {
  super();
 }
 
 public TaiLieu(String name, String maso, int so_ban_phat_hanh) {
  super();
  this.setTenNhaSX(name);
  this.setMaSo(maso);
  this.setSoBanPhatHanh(so_ban_phat_hanh);
 }
 
 public void NhapThongTin() {
  Scanner sc = new Scanner(System.in);
  
  System.out.print("Nhap Ten Nha San Xuat: ");
  String name = sc.nextLine();
  this.setTenNhaSX(name);
  
  System.out.print("Nhap Ma So: ");
  String ms = sc.nextLine();
  this.setMaSo(ms);
  
  System.out.print("Nhap So Ban Duoc Phat Hanh: ");
  int so_luong = sc.nextInt();
  this.setSoBanPhatHanh(so_luong);
 }
 
 public void XuatThongTin() {
  System.out.println("Ten Nha San Xuat: "+this.getTenNhaSX());
  System.out.println("Ma So Tai Lieu: "+this.getMaSo());
  System.out.println("So Ban Phat Hanh: "+this.getSoBanPhatHanh());
 }
 
}

Class Sach
import java.util.*;

public class Sach extends TaiLieu{

 private String TenTacGia;
 private int So_Trang;
 
 public String getTenTacGia() {
  return TenTacGia;
 }
 public void setTenTacGia(String tenTacGia) {
  TenTacGia = tenTacGia;
 }
 public int getSo_Trang() {
  return So_Trang;
 }
 public void setSo_Trang(int so_Trang) {
  So_Trang = so_Trang;
 }
 
 public Sach() {
  super();
 }
 
 public Sach(String name, String maso, int so_ban_phat_hanh, String tacgia, int trang) {
  super(name,maso,so_ban_phat_hanh);
  this.setTenTacGia(tacgia);
  this.setSo_Trang(trang);
 }
 
 public void NhapThongTin() {
  super.NhapThongTin();
  
  Scanner sc = new Scanner(System.in);
  
  System.out.print("Nhap Ten Tac Gia: ");
  String tg = sc.nextLine();
  this.setTenTacGia(tg);
  
  System.out.print("Nhap So Trang Cua Sach: ");
  int trg = sc.nextInt();
  this.setSo_Trang(trg);
 }
 
 public void XuatThongTin() {
  super.XuatThongTin();
  System.out.println("Ten Tac Gia: "+this.getTenTacGia());
  System.out.println("So Trang: "+this.getSo_Trang());
 }
 
}

Class TapChi
import java.util.Scanner;

public class TapChi extends TaiLieu{

 private int SoPhatHanh, NgayPhatHanh;

 public int getSoPhatHanh() {
  return SoPhatHanh;
 }

 public void setSoPhatHanh(int soPhatHanh) {
  SoPhatHanh = soPhatHanh;
 }

 public int getNgayPhatHanh() {
  return NgayPhatHanh;
 }

 public void setNgayPhatHanh(int ngayPhatHanh) {
  NgayPhatHanh = ngayPhatHanh;
 }
 
 public TapChi() {
  super();
 }
 
 public TapChi(String name, String maso, int so_ban_phat_hanh, int sophathanh, int ngay) {
  super(name,maso,so_ban_phat_hanh);
  this.setSoPhatHanh(sophathanh);
  this.setNgayPhatHanh(ngay);
 }
 
 public void NhapThongTin() {
  super.NhapThongTin();
  Scanner sc = new Scanner(System.in);
  
  System.out.print("Nhap So Phat Han: ");
  int sophathanh = sc.nextInt();
  this.setSoPhatHanh(sophathanh);
  
  System.out.print("Ngay Phat Hanh: ");
  int ngay = sc.nextInt();
  this.setNgayPhatHanh(ngay);
 }
 
 public void XuatThongTin() {
  super.XuatThongTin();
  System.out.println("So Phat Hanh: "+this.getSoPhatHanh());
  System.out.println("Ngay Phat Hanh: "+this.getNgayPhatHanh());
 }
}

Class DanhSachTaiLieu
import java.util.Scanner;

public class DanhSachTaiLieu {
public int total = 0;
 
 TaiLieu[] tailieu = new TaiLieu[100];
 
 void cheat() {
  for(int i=0; i<100; i++)
   tailieu[i] = new TaiLieu() {
   };
 }
 
 public void KiemTra(int key) {
  if(key == 1) {
   tailieu[total] = new Sach();
   Sach sach = new Sach();
   sach.NhapThongTin();
   tailieu[total] = sach;
   total++;
   
  }
  
  else if(key == 2) {
   tailieu[total] = new TapChi();
   TapChi tapchi = new TapChi();
   tapchi.NhapThongTin();
   tailieu[total] = tapchi;
   total++;
  }
  
  else if(key == 3) {
   for(int i=0; i<total; i++)
    tailieu[i].XuatThongTin();
    System.out.println();
  }
 }
 
 public void Search() {
  System.out.println();
  Scanner sc = new Scanner(System.in);
  System.out.print("Nhap Ten Nha San Xuat Can Tim: ");
  String search = sc.nextLine();
  
  for(int i=0; i<total; i++)
   if(tailieu[i].getTenNhaSX().equals(search) == true) tailieu[i].XuatThongTin();
  System.out.println();
 }
 
 public void TaiLieuPhatHanhNhieuNhat() {
  System.out.println();
  int max = tailieu[0].getSoBanPhatHanh();
  int max1 = 0;
  
  for(int i=1; i<total; i++)
   if(max < tailieu[i].getSoBanPhatHanh()) {
     max = tailieu[i].getSoBanPhatHanh();
     max1 = i;
   }
  
  tailieu[max1].XuatThongTin();
  System.out.println();
 }
 
}


Class Test Main
import java.util.Scanner;

public class TestMain {

 
 public static void main(String[] args) {
  DanhSachTaiLieu danhsach = new DanhSachTaiLieu();
  
  Scanner sc = new Scanner(System.in);
  int key;
  
  do
  {
   
  System.out.println("0. Thoat");
  System.out.println("1. Them Sach");
  System.out.println("2. Them Tap Chi");
  System.out.println("3. Hien Thi Danh Sach Tai Lieu");
  System.out.println("4. Tim Kiem Ten Nha Xuat Ban");
  System.out.println("5. Nguoi Co So Phat Hanh Nhieu Nhat");
  
  System.out.print("Ban Muon Chon: ");
  key = sc.nextInt();
  
  switch(key) {
  case 0: break;
  case 1: danhsach.KiemTra(key); break;
  case 2: danhsach.KiemTra(key); break;
  case 3: danhsach.KiemTra(key); break;
  case 4: danhsach.Search(); break;
  case 5: danhsach.TaiLieuPhatHanhNhieuNhat(); break;
  }
  }while(key != 0);
  
 }
}

Share This:

Post Tags:

Welcome To Task Marks

I'm Task Marks. Tôi là chủ trang web này, trang này tôi dùng để chia sẽ tài liệu và những thứ linh tinh khác. Cảm ơn mọi người đã ghé thăm trang web của chúng tôi.Nếu có thắt mắt xin vui lòng liên hệ
Mail: devnguhoc@gmail.com

1 nhận xét to ''Giải Đề Thi Java - Lần 2"

ADD COMMENT

  • To add an Emoticons Show Icons
  • To add code Use [pre]code here[/pre]
  • To add an Image Use [img]IMAGE-URL-HERE[/img]
  • To add Youtube video just paste a video link like http://www.youtube.com/watch?v=0x_gnfpL3RM