Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/misc.xml

This file was deleted.

20 changes: 0 additions & 20 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

6 changes: 6 additions & 0 deletions Bai1/Bai1/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
28 changes: 28 additions & 0 deletions Bai1/Bai1/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Bai1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1671125272454</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
12 changes: 12 additions & 0 deletions Bai1/Bai1/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
Binary file added Bai1/Bai1/bin/Class/PhanSo.class
Binary file not shown.
Binary file added Bai1/Bai1/bin/Test/TestClass.class
Binary file not shown.
114 changes: 114 additions & 0 deletions Bai1/Bai1/src/Class/PhanSo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package Class;

import java.util.Scanner;

public class PhanSo {
// thuoc tinh
private int tuSo;
private int mauSo;

// phuong thuc
// ham khoi tao khong doi so
public PhanSo() {
tuSo = 0;
mauSo = 1;
}

// ham khoi tao co doi so
public PhanSo(int tuSo, int mauSo) {
this.tuSo = tuSo;
this.mauSo = mauSo;
}

// ham nhap phan so
public void nhapPS(Scanner sc) {
int a;
int b;

do {
System.out.print("\tNhap vao tu so: ");
a = sc.nextInt();

System.out.print("\tNhap vao mau so: ");
b = sc.nextInt();

// kiem tra
if (b == 0) {
System.out.println("Mau so khong duoc bang 0. Hay nhap lai!");
} else {
tuSo = a;
mauSo = b;
}
} while (b == 0);
}

// ham hien thi
public void hienThiPS() {
if (tuSo * mauSo < 0) {
System.out.println("\t-" + Math.abs(tuSo) + "/" + Math.abs(mauSo));
} else {
System.out.println("\t" + Math.abs(tuSo) + "/" + Math.abs(mauSo));
}
}

// ham cong
public PhanSo congPS(PhanSo ps2) {
int a = tuSo * ps2.mauSo + ps2.tuSo * mauSo;
int b = mauSo * ps2.mauSo;

return new PhanSo(a, b);
}

// ham tru
public PhanSo truPS(PhanSo ps2) {
int a = tuSo * ps2.mauSo - ps2.tuSo * mauSo;
int b = mauSo * ps2.mauSo;

return new PhanSo(a, b);
}

// ham nhan
public PhanSo nhanPS(PhanSo ps2) {
int a = tuSo * ps2.tuSo;
int b = mauSo * ps2.mauSo;

return new PhanSo(a, b);
}

// ham chia
public PhanSo chiaPS(PhanSo ps2) {
int a = tuSo * ps2.mauSo;
int b = mauSo * ps2.tuSo;

return new PhanSo(a, b);
}

// ham tim uscln
private int timUSCLN(int a, int b) {
int r = a % b;

while (r != 0) {
a = b;
b = r;
r = a % b;
}

return b;
}

// ham kiem tra phan so toi gian hay chua
public boolean kiemTraToiGian() {
if (timUSCLN(tuSo, mauSo) == 1) {
return true;
}
return false;
}

// ham toi gian
public void toiGianPS() {
int x = timUSCLN(tuSo, mauSo);

tuSo /= x;
mauSo /= x;
}
}
35 changes: 35 additions & 0 deletions Bai1/Bai1/src/Test/TestClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package Test;

import java.util.Scanner;

import Class.PhanSo;

public class TestClass {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
PhanSo ps1=new PhanSo();
PhanSo ps2=new PhanSo();
PhanSo psTong =new PhanSo();

// nhap phan so
System.out.println("Nhap vao phan so thu nhat:");
ps1.nhapPS(sc);
System.out.println("Nhap vao phan so thu hai:");
ps2.nhapPS(sc);

// tinh tong 2 phan so
psTong=ps1.congPS(ps2);

// hien thi phan so
System.out.println("\nPhan so thu nhat la:");
ps1.hienThiPS();
System.out.println("\nPhan so thu hai la:");
ps2.hienThiPS();
System.out.println("\nPhan so tong la:");
psTong.hienThiPS();

sc.close();
}

}
10 changes: 10 additions & 0 deletions Bai10/Bai10/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
28 changes: 28 additions & 0 deletions Bai10/Bai10/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Bai10</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1671125272482</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
12 changes: 12 additions & 0 deletions Bai10/Bai10/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
Binary file added Bai10/Bai10/bin/BuildClass/BienLai.class
Binary file not shown.
Binary file added Bai10/Bai10/bin/BuildClass/KhachHang.class
Binary file not shown.
Binary file added Bai10/Bai10/bin/BuildClass/QuanLy.class
Binary file not shown.
Binary file added Bai10/Bai10/bin/UseClass/Using.class
Binary file not shown.
50 changes: 50 additions & 0 deletions Bai10/Bai10/src/BuildClass/BienLai.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package BuildClass;

import java.util.Scanner;

public class BienLai extends KhachHang {
// Thuoc tinh
private int chiSoMoi;
private int chiSoCu;
private double tien;

// Phuong thuc
// Ham khoi tao khong doi so
public BienLai() {

}

// Ham khoi tao co doi so
public BienLai(int chiSoMoi, int chiSoCu, double tien) {
this.chiSoMoi = chiSoMoi;
this.chiSoCu = chiSoCu;
this.tien = tien;
}

public BienLai(String tenChuHo, int chiSoMoi, int chiSoCu, double tien) {
this.tenChuHo = tenChuHo;
this.chiSoMoi = chiSoMoi;
this.chiSoCu = chiSoCu;
this.tien = tien;
}

// Ham nhap
public void nhapThongTin(Scanner sc) {
super.nhapThongTin(sc);
System.out.print("\tNhap chi so moi: ");
chiSoMoi = sc.nextInt();
sc.nextLine();
System.out.print("\tNhap chi so cu: ");
chiSoCu = sc.nextInt();
sc.nextLine();
tien = (chiSoMoi - chiSoCu) * 750;
}

// Ham hien thi
public void hienThiThongTin() {
super.hienThiThongTin();
System.out.println("\tChi so moi: " + chiSoMoi);
System.out.println("\tChi so cu: " + chiSoCu);
System.out.println("\tTien: : " + tien);
}
}
41 changes: 41 additions & 0 deletions Bai10/Bai10/src/BuildClass/KhachHang.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package BuildClass;

import java.util.Scanner;

public class KhachHang {
// Thuoc tinh
protected String tenChuHo;
protected int soNha;
protected String maCongTo;

// Phuong thuc
// Ham khoi tao khong doi so
public KhachHang() {

}

// Ham khoi tao co doi so
public KhachHang(String tenChuHo, int soNha, String maCongTo) {
this.tenChuHo = tenChuHo;
this.soNha = soNha;
this.maCongTo = maCongTo;
}

// Ham nhap
public void nhapThongTin(Scanner sc) {
System.out.print("\tNhap ten chu ho: ");
tenChuHo = sc.nextLine();
System.out.print("\tNhap so nha: ");
soNha = sc.nextInt();
sc.nextLine();
System.out.print("\tNhap ma cong to: ");
maCongTo = sc.nextLine();
}

// Hm hien thi
public void hienThiThongTin() {
System.out.println("\tTen chu ho: " + tenChuHo);
System.out.println("\tSo nha: " + soNha);
System.out.println("\tMa cong to: " + maCongTo);
}
}
Loading