Skip to content

Commit b61bb2a

Browse files
committed
Initial Project
0 parents  commit b61bb2a

19 files changed

+2366
-0
lines changed

JavaOOP/Exercises/BankAccount.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package Exercises;
2+
3+
public class BankAccount {
4+
private String accountNumber;
5+
private double balance;
6+
private String ownerName;
7+
8+
public BankAccount(String accountNumber, double balance, String owerName) {
9+
this.accountNumber = accountNumber;
10+
this.balance = balance;
11+
this.ownerName = owerName;
12+
13+
}
14+
15+
public void deposit(double money) {
16+
this.balance += money;
17+
System.out.println("Ban da nap " + money);
18+
}
19+
20+
public void withdraw(double money) {
21+
if (this.balance >= 0 && money <= this.balance) {
22+
this.balance -= money;
23+
System.out.println("So du con lai la: " + this.balance);
24+
25+
} else {
26+
System.out.println("So du khong du hoac thao tac khong hop le");
27+
28+
}
29+
}
30+
31+
public void checkBalance() {
32+
System.out.println("|--------------|");
33+
System.out.println("Thong tin tai khoan: cua khach hang: " + this.ownerName);
34+
System.out.println("So tai khoan: " + accountNumber);
35+
System.out.println("So du hien tai la: " + this.balance);
36+
System.out.println("|--------------|");
37+
38+
}
39+
40+
public static void main(String[] args) {
41+
BankAccount bankaccount = new BankAccount("id11222", 50000, "Eury");
42+
bankaccount.checkBalance();
43+
44+
}
45+
46+
}

JavaOOP/Exercises/Book.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package Exercises;
2+
3+
public class Book {
4+
private String title;
5+
private String author;
6+
private String pages;
7+
private String isOpen;
8+
9+
public Book(String title, String author, String pages, String isOpen) {
10+
this.title = title;
11+
this.author = author;
12+
this.pages = pages;
13+
14+
}
15+
16+
// is open
17+
public void open() {
18+
System.out.println("Book shop is Open");
19+
}
20+
21+
public void close() {
22+
System.out.println("Book shop is close");
23+
}
24+
25+
public void getInfo() {
26+
System.out.println(
27+
"Day la sach co ten " + this.title + ", Tac gia: " + this.author + ", So trang: " + this.pages);
28+
}
29+
30+
public static void main(String[] agrs) {
31+
Book book = new Book(null, null, null, null);
32+
}
33+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package Exercises.Encapsulation;
2+
3+
public class Employee {
4+
private String id;
5+
private String name;
6+
private double salary;
7+
8+
public Employee(String id, String name, double salary) {
9+
this.id = id;
10+
this.name = name;
11+
this.salary = salary;
12+
}
13+
14+
// getter
15+
public String getId() {
16+
return this.id;
17+
}
18+
19+
public String getName() {
20+
return this.name;
21+
}
22+
23+
public double getSalary() {
24+
return this.salary;
25+
}
26+
27+
// setter
28+
29+
public void setId(String id) {
30+
if (this.id == null) {
31+
this.id = id;
32+
}
33+
}
34+
35+
public void setName(String name) {
36+
if (this.name == null) {
37+
this.name = name;
38+
}
39+
40+
}
41+
42+
public void setSalary(double salary) {
43+
if (this.salary > 0) {
44+
this.salary = salary;
45+
}
46+
}
47+
48+
public void displayInfo() {
49+
System.out.println("Thong tin nguoi dung: ");
50+
System.out.println("id: " + this.id);
51+
System.out.println("name: " + this.name);
52+
System.out.println("Salary: " + this.salary);
53+
54+
}
55+
56+
public static void main(String[] args) {
57+
Employee employee = new Employee("id1", "Violet", 999999);
58+
employee.displayInfo();
59+
}
60+
}
1022 Bytes
Binary file not shown.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package Exercises.Encapsulation;
2+
3+
public class Rectangle {
4+
private double width;
5+
private double height;
6+
7+
public Rectangle(double width, double height) {
8+
this.width = width;
9+
this.height = height;
10+
11+
}
12+
13+
// getter
14+
public double getWidth() {
15+
return width;
16+
}
17+
18+
public double getHeight() {
19+
return height;
20+
}
21+
22+
// setter
23+
public void setWidth(double width) {
24+
if (this.width >= 0) {
25+
this.width = width;
26+
}
27+
28+
}
29+
30+
public void setHeight(double height) {
31+
if (this.height >= 0) {
32+
this.height = height;
33+
}
34+
}
35+
36+
public double calculateArea() {
37+
return this.height * this.width;
38+
39+
}
40+
41+
public double calculatePerimeter() {
42+
return 2 * (this.height + this.width);
43+
}
44+
45+
public static void main(String[] args) {
46+
Rectangle rectangle = new Rectangle(5, 6);
47+
System.out.println(rectangle.calculateArea());
48+
System.out.println(rectangle.calculatePerimeter());
49+
50+
}
51+
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package Exercises.Encapsulation;
2+
3+
public class Rectangle {
4+
private double width;
5+
private double height;
6+
7+
public Rectangle(double width, double height) {
8+
this.width = width;
9+
this.height = height;
10+
11+
}
12+
13+
// getter
14+
public double getWidth() {
15+
return width;
16+
}
17+
18+
public double getHeight() {
19+
return height;
20+
}
21+
22+
// setter
23+
public void setWidth(double width) {
24+
if (this.width >= 0) {
25+
this.width = width;
26+
}
27+
28+
}
29+
30+
public void setHeight(double height) {
31+
if (this.height >= 0) {
32+
this.height = height;
33+
}
34+
}
35+
36+
public double calculateArea() {
37+
return this.height * this.width;
38+
39+
}
40+
41+
public double calculatePerimeter() {
42+
return 2 * (this.height + this.width);
43+
}
44+
45+
public static void main(String[] args) {
46+
Rectangle rectangle = new Rectangle(5, 6);
47+
System.out.println(rectangle.calculateArea());
48+
System.out.println(rectangle.calculatePerimeter());
49+
50+
}
51+
52+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package Exercises.Inheritance.BaiTap4_1;
2+
3+
public class Car extends Vehicle {
4+
private int doors;
5+
private String fuelType;
6+
7+
public Car(String brand, int year, double speed, int doors, String fuelType) {
8+
super(brand, year, speed);
9+
this.doors = doors;
10+
this.fuelType = fuelType;
11+
}
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package Exercises.Inheritance.BaiTap4_1;
2+
3+
public class Motorcycle extends Vehicle {
4+
private int engineSize;
5+
6+
public Motorcycle(String brand, int year, double speed, int engineSize) {
7+
super(brand, year, speed);
8+
this.engineSize = engineSize;
9+
}
10+
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package Exercises.Inheritance.BaiTap4_1;
2+
3+
public class Vehicle {
4+
protected String brand;
5+
protected int year;
6+
protected double speed;
7+
8+
public Vehicle(String brand, int year, double speed) {
9+
this.brand = brand;
10+
this.year = year;
11+
this.speed = speed;
12+
13+
}
14+
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package Exercises.Inheritance.BaiTap4_2;
2+
3+
import java.lang.Math;
4+
5+
public class Circle extends Shape {
6+
private double radius = 0.0;
7+
8+
public Circle(String color, double radius) {
9+
super(color);
10+
this.radius = radius;
11+
}
12+
13+
@Override
14+
public double calculateArea() {
15+
return Math.PI * this.radius * this.radius;
16+
}
17+
18+
}

0 commit comments

Comments
 (0)