Giải Đề Thi 2017 - Phần 3
Bài Kham Khảo
Phần I
Câu 1
Class Thí Sinh
// Code By Vy Nguyễn
public abstract class ThiSinh {
private String SoBaoDanh, HoVaTen, DiaChi;
private int NamSinh, DienThoai;
private float DiemVam, DiemToan, DiemAnh;
public String getSoBaoDanh() {
return SoBaoDanh;
}
public void setSoBaoDanh(String soBaoDanh) {
SoBaoDanh = soBaoDanh;
}
public String getHoVaTen() {
return HoVaTen;
}
public void setHoVaTen(String hoVaTen) {
HoVaTen = hoVaTen;
}
public String getDiaChi() {
return DiaChi;
}
public void setDiaChi(String diaChi) {
DiaChi = diaChi;
}
public int getNamSinh() {
return NamSinh;
}
public void setNamSinh(int namSinh) {
NamSinh = namSinh;
}
public int getDienThoai() {
return DienThoai;
}
public void setDienThoai(int dienThoai) {
DienThoai = dienThoai;
}
public float getDiemVam() {
return DiemVam;
}
public void setDiemVam(float diemVam) {
DiemVam = diemVam;
}
public float getDiemToan() {
return DiemToan;
}
public void setDiemToan(float diemToan) {
DiemToan = diemToan;
}
public float getDiemAnh() {
return DiemAnh;
}
public void setDiemAnh(float diemAnh) {
DiemAnh = diemAnh;
}
public ThiSinh() {
super();
}
public ThiSinh(String ten, String ms, String diachi, int namsinh, int dt, float toan, float van, float anh) {
this.setHoVaTen(ten);
this.setSoBaoDanh(ms);
this.setDiaChi(diachi);
this.setNamSinh(namsinh);
this.setDienThoai(dt);
this.setDiemToan(toan);
this.setDiemVam(van);
this.setDiemAnh(anh);
}
public abstract float tinhTongDiem();
}
Class Chuyên Lý
// Code By Vy Nguyễn
public class ChuyenLy extends ThiSinh{
private float DiemLy;
public float getDiemLy() {
return DiemLy;
}
public void setDiemLy(float diemLy) {
DiemLy = diemLy;
}
public ChuyenLy() {
super();
}
public ChuyenLy(String ten, String ms, String diachi, int namsinh, int dt, float toan, float van, float anh, float ly) {
super(ten,ms,diachi,namsinh,dt,toan,van,anh);
this.setDiemLy(ly);
}
public float tinhTongDiem() {
return (float) (this.getDiemAnh() + this.getDiemToan() + this.getDiemVam() + (this.getDiemLy()*2));
}
}
Class Chuyên Tin
// Code By Vy Nguyễn
public class ChuyenTin extends ThiSinh{
private float DiemTin;
public float getDiemTin() {
return DiemTin;
}
public void setDiemTin(float diemTin) {
DiemTin = diemTin;
}
public ChuyenTin() {
super();
}
public ChuyenTin(String ten, String ms, String diachi, int namsinh, int dt, float toan, float van, float anh, float tin) {
super(ten,ms,diachi,namsinh,dt,toan,van,anh);
this.setDiemTin(tin);
}
public float tinhTongDiem() {
return (float) (this.getDiemAnh() + this.getDiemToan() + this.getDiemVam() + (this.getDiemTin()*2));
}
}
Class Test Thí Sinh
// Code By Vy Nguyễn
public class TestThiSinh {
public static void main(String[] args) {
ChuyenLy ly = new ChuyenLy("Hoang Minh Tuan", "GT1750", "Trai Dat", 1998, 0113, (float) 7.3, 8, (float) 9.5, (float) 9.8);
System.out.println("Diem Cua Thi Sinh Chuyen Ly= " + ly.tinhTongDiem());
ChuyenTin tin = new ChuyenTin("Hoang Minh Tuan", "GT1750", "Trai Dat", 1998, 0113, (float) 7.3, 8, (float) 9.5, 10);
System.out.println("Diem Cua Thi Sinh Chuyen Tin= " + tin.tinhTongDiem());
}
}
Phần II
Câu 1 + Câu 2 + Câu 3 + Câu 4
// Code By Vy Nguyễn
import java.util.*;
public class MangSoNguyen {
public int inPut() {
Scanner sc = new Scanner(System.in);
int n;
do {
n = sc.nextInt();
}while(n < 0);
return n;
}
public void inPut_Arr(int[] a) {
for(int i=0; i<a.length; i++) {
System.out.print("a[" + (i+1) + "]= ");
a[i] = inPut();
}
}
public void outPutDisPlay(int[] a) {
for( int b : a)
System.out.print(b+" ");
}
public boolean ktSoNguyenTo(int n) {
if( n < 2) return false;
else {
for(int i=2; i<=n/2; i++)
if(n % i == 0) return false;
}
return true;
}
public int diemSoNguyenTo(int[] a) {
int count = 0;
for(int i=0; i<a.length; i++)
if(ktSoNguyenTo(a[i]) == true) count++;
return count;
}
public static void main(String[] args) {
MangSoNguyen h = new MangSoNguyen();
System.out.print("Nhap So Luong Phan Tu: ");
int n = h.inPut();
int[] b = new int[n];
System.out.println("======== INPUT ARR ======");
h.inPut_Arr(b);
System.out.println("===== OUTPUT DISPLAY =====");
h.outPutDisPlay(b);
System.out.println("\n====== COUNT SONGUYENTO ========\nCo: "+h.diemSoNguyenTo(b)+" so nguyen to");
}
}
No Comment to " Giải Đề Thi 2017 - Phần 3 "