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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions BT-Java/Buoi3/Bai1-Calculator/BTVN-Java-Buoi3-Lan1.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file not shown.
Binary file not shown.
41 changes: 41 additions & 0 deletions BT-Java/Buoi3/Bai1-Calculator/src/service/CalculatorService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package service;

public class CalculatorService {
private double a;
private double b;
public CalculatorService(){

}
public CalculatorService(double a, double b){
this.a = a;
this.b = b;
}

public double getA() {
return a;
}
public double getB(){
return b;
}
public void setA(double a) {
this.a = a;
}
public void setB(double b){
this.b = b;
}
public static double cong(double a, double b){
return a + b;
}
public static double tru(double a, double b){
return a - b;
}
public static double nhan(double a, double b){
return a * b;
}
public static double chia(double a, double b){
if(b == 0){
System.out.println("Loi: Phep toan khong chia duoc cho 0!!!");
}
return a/b;
}
}
57 changes: 57 additions & 0 deletions BT-Java/Buoi3/Bai1-Calculator/src/view/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package view;

import service.CalculatorService;
import java.util.Scanner;

public class Calculator {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
boolean check = true;
double so1, so2, ketqua;
while(check){
System.out.println("1. Phep cong");
System.out.println("2. Phep tru");
System.out.println("3. Phep nhan");
System.out.println("4. Phep chia");
System.out.println("0. Thoat!");
System.out.println("Chon so: ");
int choice = scanner.nextInt();
switch (choice){
case 1:
System.out.println("Nhap a: ");
so1 = scanner.nextDouble();
System.out.println("Nhap b: ");
so2 = scanner.nextDouble();
ketqua = CalculatorService.cong(so1, so2);
System.out.println("Ket qua: " + ketqua);
break;
case 2:
System.out.println("Nhap a: ");
so1 = scanner.nextDouble();
System.out.println("Nhap b: ");
so2 = scanner.nextDouble();
ketqua = CalculatorService.tru(so1, so2);
System.out.println("Ket qua: " + ketqua);
break;
case 3:
System.out.println("Nhap a: ");
so1 = scanner.nextDouble();
System.out.println("Nhap b: ");
so2 = scanner.nextDouble();
ketqua = CalculatorService.nhan(so1, so2);
System.out.println("Ket qua: " + ketqua);
break;
case 4:
System.out.println("Nhap a: ");
so1 = scanner.nextDouble();
System.out.println("Nhap b: ");
so2 = scanner.nextDouble();
ketqua = CalculatorService.chia(so1, so2);
System.out.println("Ket qua: " + ketqua);
break;
case 0:
check = false;
}
}
}
}
11 changes: 11 additions & 0 deletions BT-Java/Buoi3/Bai2-PrimeChecker/BTVN-Java-Buoi3-Lan2.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package service;
public class PrimeCheckerService {
private int a;
public PrimeCheckerService(){}
public PrimeCheckerService(int a){
this.a = a;
}
public static boolean isPrime(int a){
for(int i = 2; i <= Math.sqrt(a); i++){
if(a%i == 0){
return false;
}
}
return a>1;
}
}
18 changes: 18 additions & 0 deletions BT-Java/Buoi3/Bai2-PrimeChecker/src/view/PrimeChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package view;

import java.util.Scanner;
import service.PrimeCheckerService;
public class PrimeChecker {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Nhap 1 so nguyen duong: ");
int a = scanner.nextInt();
if( a < 0 ){
System.out.println(a + " la so am");
} else if (PrimeCheckerService.isPrime(a)) {
System.out.println(a + " la so nguyen to");
} else{
System.out.println(a + " khong phai la so nguyen to");
}
}
}
11 changes: 11 additions & 0 deletions BT-Java/Buoi3/Bai3-SecondLargestNumber/BTVN-Java-Buoi3-Lan3.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file not shown.
34 changes: 34 additions & 0 deletions BT-Java/Buoi3/Bai3-SecondLargestNumber/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.util.Scanner;

public class Main {
public static int findSecondLargest(int[] numbers){
int firstLargest = numbers[0];
int secondLargest = Integer.MIN_VALUE;
for(int i = 1; i < numbers.length; i++){
if(numbers[i] > firstLargest){
firstLargest = numbers[i];
}
}
for(int i = 0; i < numbers.length; i++){
if(numbers[i] > secondLargest && numbers[i] < firstLargest){
secondLargest = numbers[i];
}
}
return secondLargest;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Nhap n: ");
int n = scanner.nextInt();
if(n<2){
System.out.println("Loi so luong phan tu: " + Integer.MIN_VALUE);
}else{
System.out.println("Nhap phan tu trong mang: ");
int[] numbers = new int[n];
for(int i = 0; i < numbers.length; i++){
numbers[i] = scanner.nextInt();
}
System.out.println("So lon thu hai la: " + findSecondLargest(numbers));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file not shown.
18 changes: 18 additions & 0 deletions BT-Java/Buoi3/Bai4-SumDuplicateElementCalculator/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class Main {
public static void calculateCommonElementsSum(int[] array1, int[] array2){
for(int i = 0; i < array1.length; i++){
for(int j = 0; j < array2.length; j++){
if(array1[i] == array2[j]){
int ketqua = array1[i] + array2[j];
System.out.println("Tong 2 so " + array1[i] + " la: " + ketqua);;
break;
}
}
}
}
public static void main(String[] args) {
int[] array1 = {1, 2, 3, 4, 5};
int[] array2 = {3, 4, 5, 6, 7};
calculateCommonElementsSum(array1, array2);
}
}