Sie sind auf Seite 1von 9

BTC3_Cau4 public TaiKhoan(int soTK, double soDu) {

this();

import java.text.ParseException; this.soTK = soTK;

import java.text.SimpleDateFormat; this.soDu = soDu;

import java.util.Date; }

import java.util.Calendar;

public class BTC3_Cau4 { public void setlaiSuatNam(double laiSuatNam){

public static void main(String[] args) { this.laiSuatNam = laiSuatNam;

TaiKhoanSec sec = new }


TaiKhoanSec(123,10000);
public double tienLaiThang(){
sec.setlaiSuatNam(6.5);
return soDu * laiSuatNam /12 /100;
sec.setchiTroi(1000);
}
sec.guitien(3000);
public void ruttien(double soTien){
sec.rutTien(11000);
soDu -= soTien;
System.out.println(sec);
}
}
public void guitien(double soTien){

soDu += soTien;
}
}
class TaiKhoan{
}
protected int soTK =0;
class TaiKhoanSec extends TaiKhoan{
protected double soDu =0, laiSuatNam =0.0;
private double chiTroi;
private Date ngayTao;
public TaiKhoanSec(int soTK, double soDu){
public TaiKhoan(){
super(soTK, soDu);
ngayTao = new Date();
}
}
public void setchiTroi(double chiTroi){

this.chiTroi = chiTroi;
public String getNgayTao() {
}
SimpleDateFormat df = new
public void rutTien(double soTien){
SimpleDateFormat("dd/MM/yyyy");
if(soTien <= soDu + chiTroi)
return df.format(ngayTao);
super.ruttien(soTien);
}
else arr.add(new
NhanVienCongNhat("Nguyen Van A",
System.out.print("Số tiền rút 123,210000.0));
vượt mức quy định! "); arr.add(new NhanVienLamGio("Le Thi
B", 456 ,60000.0, 50.0));
} for(nhanviennn i : arr)
if(i instanceof
public String toString(){ NhanVienCongNhat)
System.out.println("
String t = String.format("%.2f", soDu); Nhan vien cong nhat: \n "+ i);
else
double tienlai = super.tienLaiThang();
System.out.println("Nhan vien lam gio:
if(tienlai <0) \n "+ i);
for ( int i=0; i < arr.size();i++)
t+="\n Tra lai cho ngan hang: " + System.out.printf("Nhan
String.format("%.2f", -tienlai); vien [%d] thuoc lop %s", i,
arr.get(i).getClass().getName());
else

t+="\n Lãi suất tháng: " }


+String.format("%.2f", tienlai);
}
return "Tài khoản sec:\n Số tài khoản: "
+soTK +"\n Số dư: " + t abstract class nhanviennn{
private String hoten;
+"\n Ngày tạo: " private int CMND;
+getNgayTao();
public nhanviennn(String hoten, int
} cMND) {
this.hoten = hoten;
} CMND = cMND;
}
BTC4_Cau3 public String toString() {
return "Họ tên: " + hoten +
import java.util.ArrayList; "\nCMND: "+ CMND;
public class BTC4_Cau3 { }
public abstract double ThuNhapTuan();
public static void main(String[] args) { }
System.out.println("Cac nhan vien class NhanVienCongNhat extends nhanviennn{
duoc xu li rieng biet: "); private double luongtuan;
System.out.println("Cac nhan vien public NhanVienCongNhat(String hoten,
cong nhat: "); int cMND, Double luongtuan) {
NhanVienCongNhat nvcn = new super(hoten, cMND);
NhanVienCongNhat("Nguyen Van A", try {
123,2100000.0); if(luongtuan <0)
System.out.println(nvcn); throw new
System.out.println("Cac nhan vien IllegalAccessException("Lương tuần phải > 0!");
lam gio: "); else
NhanVienLamGio nvlg = new this.luongtuan =
NhanVienLamGio("Le Thi B", 456 ,60000.0, 50.0); luongtuan;
System.out.println(nvlg);
System.out.println("-------------- } catch (Exception e) {
-----------");
System.out.println(" Cac nhan vien System.out.println(e.getMessage() + "Xin
duoc xu li da hinh: "); nhập lai!");
ArrayList <nhanviennn> arr = new }
ArrayList<>();
}
@Override import java.util.Scanner;
public String toString() {
String t = public class BTTHC3_Cau2 {
String.format("%n%s%.2f%s%n%s%.2f%s%n", "Luong
tuan: ", luongtuan," VND", "Tong Cong: ", public static void main(String[] args) {
ThuNhapTuan(), " VND" );
return super.toString() +t; double dai=0, rong=0;
} double canh=0;
public double ThuNhapTuan(){ double a=0, b=0;
return luongtuan; double bk=0;
} int functionID = 0;
Scanner sc = new
} Scanner(System.in);
class NhanVienLamGio extends nhanviennn{ boolean flag = true;
double luonggio; do {
double sogio; ShowMenu();
public NhanVienLamGio(String hoten, int functionID = sc.nextInt();
cMND, Double luonggio, Double sogio) {
super(hoten, cMND);
try { switch (functionID) {
if(luonggio <0)
throw new
IllegalAccessException("Lương giờ phải > 0!"); case 1:
if(0 > sogio||sogio > 60) int x,y;
throw new
IllegalAccessException("Số giờ vượt giới System.out.print("Nhập tọa độ tâm (x,
hạn!"); y): ");
else x= sc.nextInt();
{ y= sc.nextInt();
this.luonggio =
luonggio;
this.sogio = sogio; System.out.print("Nhập chiều dài \t: ");
} dai =
} catch (Exception e) { sc.nextDouble();

System.out.println(e.getMessage() + "Xin System.out.print("Nhập chiều rộng : ");


nhập lai!"); rong =
} sc.nextDouble();
HinhChuNhat hcn = new
} HinhChuNhat(dai, rong);
@Override hcn.setTen("Hình Chữ
public String toString(){ Nhât");
String t = hcn.setX(x);
String.format("%n%s%.2f%s%n%s%.2f%n%s%.2f%s%n", hcn.setY(y);
"Luong gio: ", luonggio," VND", " So gio:" ,
sogio, "Tong Cong: ", ThuNhapTuan(), " VND" ); System.out.println(hcn);
return super.toString() +t; break;
} case 2:
public double ThuNhapTuan(){
if(sogio <=40)
return luonggio*sogio; System.out.print("Nhập tọa độ tâm (x,
else y): ");
return luonggio*sogio x= sc.nextInt();
+(sogio-40)*luonggio*1.5; y= sc.nextInt();

}
} System.out.println("Nhập độ dài cạnh:
");
BTC3_Cau2
canh =
sc.nextDouble();
HinhVuong hv = new
HinhVuong(canh);
hv.setTen("Hình }
Vuông");
hv.setX(x); public static void ShowMenu() {
hv.setY(y);
System.out.println("====================
System.out.println(hv); ==MENU=====================");
break; System.out.println("1. Hình Chữ
case 3: Nhật ");
System.out.println("2. Hình Vuông
System.out.print("Nhập tọa độ tâm (x, ");
y): "); System.out.println("3. Hình
x= sc.nextInt(); Ellipse ");
y= sc.nextInt(); System.out.println("4. Hình Tròn
");
System.out.println("5. Thoát");
System.out.println("Your choise
System.out.println("Nhập a, b: "); [1-5]: ");
a = sc.nextDouble(); System.out.println("--------------
b = sc.nextDouble(); ------------------------------------------");
Ellipse elip = new
Ellipse(a, b); }
elip.setTen("Hình
Ellipse"); }
elip.setX(x); class Hinh{
elip.setY(y); String ten;
int x, y;
System.out.println(elip);
break;
case 4: public void setTen(String ten) {
this.ten = ten;
System.out.print("Nhập tọa độ tâm (x, }
y): ");
x= sc.nextInt();
y= sc.nextInt(); public void setX(int x) {
this.x = x;
}
System.out.println("Nhập bán kính: ");
bk = sc.nextDouble();
HinhTron ht = new public void setY(int y) {
HinhTron(bk); this.y = y;
ht.setTen("Hình }
Tròn");
ht.setX(x);
ht.setY(y); public String toString() {
return ten +"\nTọa độ: " + "(" + x
System.out.println(ht); +(",") +y +(")\n");
break; }
case 5: }
default: class HinhChuNhat extends Hinh{
flag = false; double dai=0, rong=0;
break;
}
public double getDai() {
return dai;
}while(flag == true); }
public double getRong() { }
return rong; public String toString() {
} String str ="";
public HinhChuNhat(double dai, double if( a == b){
rong) { str = "Bán kính: " + a;
this.dai = dai; }
this.rong = rong; else {
} str = "Giá trị canh a:" + a
public double TinhDienTich() { + "\nGiá trị cạnh b: " + b ;
return dai * rong; }
} String t =
public double TinhChuVi() { String.format("%s%.2f%n", "\nDiện tích: "
return (dai + this.rong)*2; ,TinhDienTich());
} String v =
public String toString() { String.format("%s%.2f%n", "Chu vi: "
String str =""; ,TinhChuVi());
if( dai == rong){ return super.toString() + str + t
str = "Cạnh: " + dai; + v;
} }
else { }
str = "Dài: " + dai+ class HinhTron extends Ellipse{
"\nRộng:" + rong ; public HinhTron (double bk) {
} super(bk,bk);
String t = }
String.format("%s%.2f%n", "\nDiện tích: " }
,TinhDienTich()); Book_info
String v = package vd;
String.format("%s%.2f%n", "Chu vi: "
,TinhChuVi()); import java.util.Scanner;
return super.toString() + str + t
+ v; public class info_book {
} private static Book bookobj = null;
}
class HinhVuong extends HinhChuNhat{ public static void main(String[] args) {
public HinhVuong(double canh) { Scanner sc = new
super(canh, canh); Scanner(System.in);
} int functionID = 0;
} boolean flag = true;
class Ellipse extends Hinh{
double a,b; do {
ShowMenu();
public double getA() { functionID = sc.nextInt();
switch (functionID) {
return a; case 1: add();
} break;
public double getB() { case 2: edit();
return b; break;
} case 3: info();
public Ellipse(double a, double b) { break;
super(); case 4:
this.a = a; default:
this.b = b; flag = false;
} break;
public double TinhDienTich(){ }
return a*b *Math.PI; } while(flag == true);
}
} public static void ShowMenu() {
public double TinhChuVi(){ System.out.println("====================
return (a+b)*Math.PI; ==BOOK MANAGER=====================");
System.out.println("1. Add book "); }
System.out.println("2. Edit book "); }
System.out.println("3. Info book ");
System.out.println("4. Exit "); class Book{
System.out.println("Your choise [1-4]: private String ID;
"); private String name;
System.out.println("-------------------- private double price;
------------------------------------"); public Book(String iD, String name,
double price) {
} ID = iD;
public static void add() { this.name = name;
Scanner sc = new Scanner(System.in); this.price = price;
String bookName = ""; }
String bookID = ""; public String getID() {
double bookprice = 0; return ID;
System.out.println("ID : "); }
bookID = sc.next(); public void setID(String iD) {
System.out.println("Book name : "); ID = iD;
bookName = sc.next(); }
System.out.println("Book price : "); public String getName() {
bookprice = sc.nextDouble(); return name;
bookobj = new Book(bookID, bookName, }
bookprice); public void setName(String name) {
this.name = name;
} }
public static void edit() { public double getPrice() {
if(bookobj != null) { return price;
Scanner sc = new }
Scanner(System.in); public void setPrice(double price) {
String bookName = ""; this.price = price;
double bookprice = 0; }
System.out.println("Book name : public void Showinfo() {
"); System.out.println("Book Info :
bookName = sc.next(); ");
System.out.println("Book price : System.out.println("- ID \t\t: " +
"); this.getID());
bookprice = sc.nextDouble(); System.out.println("- Book Name
bookobj.setName(bookName); \t: " + this.getName());
bookobj.setPrice(bookprice); System.out.println("- Price \t: "
} + this.getPrice());
else
{ }
System.out.println("Chưa nhập
thông tin!!!"); }
} PhanSo
}
public static void info() { package vd;
if(bookobj != null) { import java.util.Scanner;
bookobj.Showinfo();
} public class Vdd_PhanSo {
else
{ public static void main(String[] args) {
System.out.println("Chưa nhập Scanner sc = new
thông tin!!!"); Scanner(System.in);
} int tu1, tu2, mau1, mau2;
String pheptinh;
} System.out.print("Nhập tử số phân
public static void exit() { số thứ nhất: ");
System.out.println("info_book.exit()"); tu1 = sc.nextInt();
do { case "-":
System.out.print("Nhập mẫu this.sub(fractionA,
số phân số thứ nhất: "); fractionB);
mau1 = sc.nextInt(); break;
} while ( mau1 == 0); case "x":
case "X":
System.out.print("Nhập tử số phân case "*":
số thứ hai: "); case ".":
tu2 = sc.nextInt(); this.multiply(fractionA,
do { fractionB);
System.out.print("Nhập mẫu break;
số phân số thứ hai: "); case ":":
mau2 = sc.nextInt(); case "/":
} while ( mau2 == 0); this.divide(fractionA,
System.out.print("Nhập phép tính: fractionB);
"); break;
pheptinh = sc.next(); }

Fraction fractionA = new }


Fraction(tu1, mau1); public String print() {
Fraction fractionB = new return this.getNumerator() + "/"+
Fraction(tu2, mau2); this.getDenomirator();
Fraction fractionC = new
Fraction(fractionA, fractionB, pheptinh); // Cộng
System.out.printf("%s" + " "+ private void add(Fraction fractionA,
pheptinh + " " + "%s = %s", fractionA.print(), Fraction fractionB) {
fractionB.print(), fractionC.print());
this.numerator=fractionA.getNumerator()
* fractionB.getDenomirator() +
} fractionA.getDenomirator()*fractionB.getNumerat
or();
}
class Fraction{ this.denomirator=fractionA.getDenomirato
private int numerator, denomirator; r()*fractionB.getDenomirator();
this.ToiGian();
public int getNumerator() {
return numerator; }
} //Hiệu
private void sub(Fraction fractionA,
Fraction fractionB) {
public int getDenomirator() {
return denomirator; this.numerator=fractionA.getNumerator()
} * fractionB.getDenomirator() -
fractionA.getDenomirator()*fractionB.getNumerat
public Fraction(int numerator, int or();
denomirator) {
this.numerator = numerator; this.denomirator=fractionA.getDenomirato
this.denomirator = denomirator; r()*fractionB.getDenomirator();
} this.ToiGian();

public Fraction(Fraction fractionA, }


Fraction fractionB, String operator) { //Tích
fractionA.ToiGian(); private void multiply(Fraction
fractionB.ToiGian(); fractionA, Fraction fractionB) {
switch(operator) {
case "+": this.numerator=fractionA.getNumerator()
this.add(fractionA, * fractionB.getNumerator();
fractionB);
break;
System.out.println("--------------
this.denomirator=fractionA.getDenomirato ----------------------");
r()*fractionB.getDenomirator(); NhanVienTapVu nvtv = new
this.ToiGian(); NhanVienTapVu("Trần Văn C", "3333", "Phạm Văn
} Đồng", "12/03/1965", "VND", 4.0 , 4.0*1390000,
//Thương " Vệ Sinh");
private void divide(Fraction fractionA, System.out.println(nvtv);
Fraction fractionB) { System.out.println("--------------
----------------------");
this.numerator=fractionA.getNumerator()
* fractionB.getDenomirator(); }

this.denomirator=fractionA.getDenomirato }
r()*fractionB.getNumerator(); class Nguoi{
this.ToiGian(); private String hoten, sdt, dc;
} private Date birthday;
//UCLN SimpleDateFormat df = new
private int UCLN (int a, int b) { SimpleDateFormat("dd/MM/yyyy");
int r; public Nguoi(String hoten, String sdt,
while (b>0) { String dc, String birthday) {
r = a % b; this.hoten = hoten;
a = b; this.sdt = sdt;
b = r; this.dc = dc;
try {
} this.birthday =
Return df.parse(birthday);
a; }
public void ToiGian() { catch(ParseException e) {
int usc =
this.UCLN(this.getNumerator(),this.getDenomirat }
or()); }
this.numerator = public String toString() {
this.getNumerator() /usc; return "Họ và tên: " + hoten +
this.denomirator = "\nĐịa chỉ: " + dc + "\nNgày Sinh: "+
this.getDenomirator() /usc; df.format(birthday) + "\nSố điện thoại: "+
} sdt;
}
} }
BTC3_Cau3 class SinhVien extends Nguoi{
private int sonamhoc;
public final static int NAMNHAT =1;
import java.text.ParseException; public final static int NAMHAI =2;
import java.text.SimpleDateFormat; public final static int NAMBAT =3;
import java.util.Date; public final static int NAMTU =4;
public SinhVien(String hoten, String
public class BTC3_Cau3 { sdt, String dc, String birthday, int sonamhoc)
{
public static void main(String[] args) { super(hoten, sdt,dc, birthday);
SinhVien sv = new SinhVien("Nguyễn this.sonamhoc = sonamhoc;
Văn A", "1111", "Nguyễn Kiệm", "32/12/1995", }
SinhVien.NAMTU); public String toString() {
System.out.println(sv); return super.toString() + "\nSố
System.out.println("-------------- năm học: " + sonamhoc;
----------------------"); }
NhanVienVanPhong nvvp = new
NhanVienVanPhong("Lê Thị B", "2222", "Quang }
Trung", "06/07/1970","VND", 4.75, 4.74*139000, class NhanVien extends Nguoi{
"Kế Toán"); private String donvi;
System.out.println(nvvp); private double hesoluong;
private double luong = hesoluong *
1390000;
public NhanVien(String hoten, String
sdt,String dc, String birthday, String donvi,
Double hesoluong, Double luong) {
super(hoten, sdt,dc, birthday);
this.donvi = donvi;
this.hesoluong = hesoluong;
this.luong = luong;
}

public String toString() {


String t =
String.format("%s%.0f%n", "\nLương: ", luong);
return super.toString() + t +
donvi;
}
}
class NhanVienVanPhong extends NhanVien{
private String Chucvu;
public NhanVienVanPhong(String hoten,
String sdt, String dc, String birthday, String
donvi, Double hesoluong,Double luong,String
Chucvu) {
super(hoten, sdt, dc, birthday,
donvi, hesoluong,luong);
this.Chucvu = Chucvu;
}
public String toString() {
return super.toString() + "\nChức
vụ: " + Chucvu;
}

}
class NhanVienTapVu extends NhanVien{
private String Congviec;
public NhanVienTapVu(String hoten,
String sdt, String dc, String birthday, String
donvi, Double hesoluong,Double luong, String
Congviec) {
super(hoten, sdt, dc, birthday,
donvi, hesoluong, luong);
this.Congviec = Congviec;
}
public String toString() {
return super.toString() + "\nCông
việc: " + Congviec;
}

Das könnte Ihnen auch gefallen