Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4955823

Browse files
committed
Add project configuration files and implement SachGiaoKhoa class with input functionality
1 parent 1a8beba commit 4955823

File tree

11 files changed

+229
-4
lines changed

11 files changed

+229
-4
lines changed

‎Computer-science-Java/Buoi03/CatManager/src/models/Main.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Arrays;
44
import java.util.Comparator;
5+
import java.util.Scanner;
56

67
public class Main {
78
public static void main(String[] args) {
@@ -16,15 +17,14 @@ public static void main(String[] args) {
1617
// o1 ... o2:
1718
Arrays.sort(a, new Comparator<Cat>() {
1819
public int compare(Cat o1, Cat o2) { // trả về x > 0 nếu muốn đổi chỗ
19-
if (o1.getSoChan() < o1.getSoChan())
20-
return 1;
21-
return -1;
20+
return o1.getSoChan() - o2.getSoChan();
2221
}
2322
});
2423

2524
for (int i = 0; i <= 1; i++)
2625
System.out.println(a[i]);
2726

27+
Scanner sc = new Scanner(System.in);
2828

2929

3030
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package test;
22

3+
34
public class A {
5+
6+
public void fun1() {
7+
8+
}
49

510
public static void main(String[] args) {
611
// TODO Auto-generated method stub
7-
12+
A a = new A();
13+
814
}
915

1016
}

‎other/Duong_Sach.zip‎

8.4 KB
Binary file not shown.

‎other/Duong_Sach/.classpath‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
4+
<attributes>
5+
<attribute name="module" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>

‎other/Duong_Sach/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

‎other/Duong_Sach/.project‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Duong_Sach</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=17
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13+
org.eclipse.jdt.core.compiler.release=enabled
14+
org.eclipse.jdt.core.compiler.source=17
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package models;
2+
3+
import java.util.Scanner;
4+
5+
public class Sach {
6+
private String maSach;
7+
private String ngayNhap;
8+
private int donGia;
9+
private int soLuong;
10+
11+
12+
public Sach() {
13+
this.maSach = "";
14+
this.ngayNhap = "";
15+
this.donGia = 0;
16+
this.soLuong = 0;
17+
}
18+
19+
public Sach(String maSach, String ngayNhap, int donGia, int soLuong) {
20+
this.maSach = maSach;
21+
this.ngayNhap = ngayNhap;
22+
this.donGia = donGia;
23+
this.soLuong = soLuong;
24+
}
25+
26+
public void input() {
27+
Scanner sc = new Scanner(System.in);
28+
29+
System.out.print("Nhập mã sách: ");
30+
this.maSach = sc.nextLine();
31+
32+
System.out.print("Nhập ngày nhập: ");
33+
this.ngayNhap = sc.nextLine();
34+
35+
System.out.print("Nhập đơn giá: ");
36+
this.donGia = sc.nextInt();
37+
38+
System.out.print("Nhập số lượng: ");
39+
this.soLuong = sc.nextInt();
40+
41+
}
42+
43+
44+
45+
@Override
46+
public String toString() {
47+
return "Sach [maSach=" + maSach + ", ngayNhap=" + ngayNhap + ", donGia=" + donGia + ", soLuong=" + soLuong
48+
+ "]";
49+
}
50+
51+
52+
53+
public String getMaSach() {
54+
return maSach;
55+
}
56+
57+
public void setMaSach(String maSach) {
58+
this.maSach = maSach;
59+
}
60+
61+
public String getNgayNhap() {
62+
return ngayNhap;
63+
}
64+
65+
public void setNgayNhap(String ngayNhap) {
66+
this.ngayNhap = ngayNhap;
67+
}
68+
69+
public int getDonGia() {
70+
return donGia;
71+
}
72+
73+
public void setDonGia(int donGia) {
74+
this.donGia = donGia;
75+
}
76+
77+
public int getSoLuong() {
78+
return soLuong;
79+
}
80+
81+
public void setSoLuong(int soLuong) {
82+
this.soLuong = soLuong;
83+
}
84+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package models;
2+
3+
import java.util.Scanner;
4+
5+
public class SachGiaoKhoa extends Sach {
6+
private String tinhTrang;
7+
8+
public SachGiaoKhoa() {
9+
super();
10+
this.tinhTrang = "mới";
11+
}
12+
13+
public SachGiaoKhoa(String maSach, String ngayNhap, int donGia, int soLuong, String tinhTrang) {
14+
super(maSach, ngayNhap, donGia, soLuong);
15+
this.tinhTrang = tinhTrang;
16+
}
17+
18+
public double tinhThanhTien() {
19+
if (tinhTrang.equalsIgnoreCase("mới")) {
20+
return getSoLuong() * getDonGia();
21+
} else if (tinhTrang.equalsIgnoreCase("cũ")) {
22+
return getSoLuong() * getDonGia() * 0.5;
23+
} else {
24+
return 0;
25+
}
26+
}
27+
28+
public void input() {
29+
super.input();
30+
31+
Scanner sc = new Scanner(System.in);
32+
System.out.print("Nhập tình trạng sách (mới/cũ): ");
33+
this.tinhTrang = sc.nextLine();
34+
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return super.toString() + ", tinhTrang=" + tinhTrang + ", thanhTien=" + tinhThanhTien();
40+
}
41+
42+
public String getTinhTrang() {
43+
return tinhTrang;
44+
}
45+
46+
public void setTinhTrang(String tinhTrang) {
47+
this.tinhTrang = tinhTrang;
48+
}
49+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /