From 599d563c47633a02f3578e9d306182e60d598add Mon Sep 17 00:00:00 2001 From: Jezz27 Date: Fri, 13 Sep 2024 13:59:56 -0500 Subject: [PATCH] Quiz refactor 192342 Jesus Zapata --- README.md | 1 + src/AgeValidation.java | 26 +++++++++++++++++++------- src/Quiz2.java | 35 +++++++++++++++++++++++++++++++++++ src/Quiz3.java | 28 ++++++++++++++++++++++++++++ src/Store.java | 19 ------------------- src/TaxCalculation.java | 15 --------------- 6 files changed, 83 insertions(+), 41 deletions(-) create mode 100644 src/Quiz2.java create mode 100644 src/Quiz3.java delete mode 100644 src/Store.java delete mode 100644 src/TaxCalculation.java diff --git a/README.md b/README.md index 697a0cd..add6ce1 100644 --- a/README.md +++ b/README.md @@ -56,3 +56,4 @@ You must follow the **SDLC process** to refactor the code: - Once you complete the refactorization, push your changes to your forked repository. - Create a pull request (PR) to the original repository, explaining the improvements you made and how you followed the **SDLC** approach. +//Haider Carreño 192350 \ No newline at end of file diff --git a/src/AgeValidation.java b/src/AgeValidation.java index 40e0198..7586daf 100644 --- a/src/AgeValidation.java +++ b/src/AgeValidation.java @@ -1,13 +1,25 @@ +import java.util.Scanner; + public class AgeValidation { + // 1 defino constantes + private static final int AGE_LIMIT = 18; // edad limite para el acceso + public static void main(String[] args) { - int age = 18; + // 2 manejo la entrada del usuario + Scanner scanner = new Scanner(System.in); - if (age >= 18) { - System.out.println("Access granted"); + System.out.print("Enter your age: "); + int age = scanner.nextInt(); // lee edad del usuario + + // 3 estructura if-else para validar la edad + if (age >= AGE_LIMIT) { + System.out.println("Access granted"); // si la edad es mayor o igual al limite acceso concedido + } else { + System.out.println("Access denied"); // si la edad es menor al limite acceso denegado } + + // cerrar el Scanner + scanner.close(); - if (age < 18) { - System.out.println("Access denied"); - } } -} +} \ No newline at end of file diff --git a/src/Quiz2.java b/src/Quiz2.java new file mode 100644 index 0000000..b57dfe7 --- /dev/null +++ b/src/Quiz2.java @@ -0,0 +1,35 @@ +public class Quiz2 { + + // 1 Reemplazar numeros magicos con nombres de constantes + static final int PRODUCT_1_PRICE = 15; + static final int PRODUCT_2_PRICE = 10; + static final int PRODUCT_3_PRICE = 5; + static final int QUANTITY_1 = 2; + static final int QUANTITY_2 = 3; + static final int QUANTITY_3 = 4; + static final int SALES_THRESHOLD = 50; + + public static void main(String[] args) { + + // 2 Diseño e Implementacion + // Arrays para almacenar precios y cantidades de productos + int[] productPrices = {PRODUCT_1_PRICE, PRODUCT_2_PRICE, PRODUCT_3_PRICE}; + int[] productQuantities = {QUANTITY_1, QUANTITY_2, QUANTITY_3}; + + // variable de las ventas totales de la tienda + int totalSales = 0; + + // calcular ventas totales usando ciclo repetitivo for + for (int i = 0; i < productPrices.length; i++) { + totalSales += productPrices[i] * productQuantities[i]; + } + + // 4 Comprobar resultados de las ventas + if (totalSales > SALES_THRESHOLD) { + System.out.println("Good sales performance"); + } else { + System.out.println("Low sales performance"); + } + } +} + diff --git a/src/Quiz3.java b/src/Quiz3.java new file mode 100644 index 0000000..c0bf65c --- /dev/null +++ b/src/Quiz3.java @@ -0,0 +1,28 @@ +public class Quiz3 { + + // Fase 1 Reemplazo numeros magicos por constantes + static final double TAX_RATE_HIGH = 0.15; + static final double TAX_RATE_LOW = 0.10; + static final double TAX_THRESHOLD = 50.0; + + public static void main(String[] args) { + + // Fase 2 Diseño y arrays para almacenar los precios de los productos y los tipos + double[] productPrices = {100, 200}; + double[] taxRates = {TAX_RATE_HIGH, TAX_RATE_LOW}; + + // Fase 3: Aplicación y calculo de los impuestos + double totalTax = 0; + for (int i = 0; i < productPrices.length; i++) { + totalTax += productPrices[i] * taxRates[i]; + } + + // Fase 4 Comprobar si el impuesto total supera el limite + if (totalTax > TAX_THRESHOLD) { + System.out.println("High total tax: " + totalTax); + } else { + System.out.println("Low tax"); + } + } +} + diff --git a/src/Store.java b/src/Store.java deleted file mode 100644 index 2a4729a..0000000 --- a/src/Store.java +++ /dev/null @@ -1,19 +0,0 @@ -public class Store { - public static void main(String[] args) { - int p1 = 15; - int p2 = 10; - int p3 = 5; - - int total1 = p1 * 2; - int total2 = p2 * 3; - int total3 = p3 * 4; - - int totalSales = total1 + total2 + total3; - - if (totalSales > 50) { - System.out.println("Good sales performance"); - } else { - System.out.println("Low sales performance"); - } - } -} diff --git a/src/TaxCalculation.java b/src/TaxCalculation.java deleted file mode 100644 index 3417866..0000000 --- a/src/TaxCalculation.java +++ /dev/null @@ -1,15 +0,0 @@ -public class TaxCalculation { - public static void main(String[] args) { - double productPrice1 = 100; - double productPrice2 = 200; - double tax1 = productPrice1 * 0.15; - double tax2 = productPrice2 * 0.10; - double totalTax = tax1 + tax2; - - if (totalTax > 50) { - System.out.println("High total tax: " + totalTax); - } else { - System.out.println("Low tax"); - } - } -}