From b6fa2c7bc8036fb7acda492e106cef441203f291 Mon Sep 17 00:00:00 2001 From: Juan Jose Date: Fri, 13 Sep 2024 14:03:17 -0500 Subject: [PATCH 1/2] refactorizacion completa para el cuestionario --- README.md | 69 +++++++----------------------------- src/AgeValidation.java | 15 +++++--- src/Store.java | 77 ++++++++++++++++++++++++++++++++++++----- src/TaxCalculation.java | 47 ++++++++++++++++++++----- 4 files changed, 131 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index 697a0cd..18f44be 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,15 @@ -# Refactorization Quiz: Applying the SDLC Process - -## Overview - -This quiz is designed to test your ability to refactor code using **professional best practices**. Working in **pairs**, you will refactor provided code by improving its readability, efficiency, and scalability. You will also apply the **Software Development Life Cycle (SDLC)**, using structured phases to enhance the code. Each group will fork the repository, refactor the code, and submit a pull request with their improvements. - ---- - -## Objectives - -- Apply concepts from **Unit 1: Data Storage and Control Flow**: - - Writing variables and constants - - Arithmetic operators - - Input/output system - - Conditional operators - - Control structures - - Avoiding magic numbers - - Lists of data with arrays - - Basic SDLC principles - ---- - -## SDLC Approach - -You must follow the **SDLC process** to refactor the code: - -1. **Phase 1: Requirements Analysis** – Understand the original code, identify its weaknesses, and define improvement requirements. -2. **Phase 2: Design** – Plan how to improve the code structure, renaming variables, optimizing logic, and making it more efficient. -3. **Phase 3: Implementation** – Refactor the code following your design plan, ensuring better readability and efficiency. -4. **Phase 4: Testing** – Test the refactored code with multiple inputs to ensure correctness and improvements. -5. **Phase 5: Documentation & Maintenance** – Write clear comments, and submit your final version, ensuring the code is easy to maintain. - ---- - -## Instructions - -1. **Repository Forking**: - - Fork the repository to create a copy in your GitHub account. - - Clone the repository to your local machine. - -2. **Analyze the Code**: - - Carefully read the provided code. - - Identify magic numbers, unclear variable names, or inefficient logic. - -3. **Refactor the Code**: - - Improve the variable names, replace magic numbers with constants, and optimize the control structures. - - Make sure to add comments explaining the logic and changes you made. - - Apply **arrays** where repetition of variables exists. - -4. **Test the Refactored Code**: - - Run the program with different inputs to validate that the refactored code functions as expected. - - Ensure the program handles errors gracefully (e.g., invalid input, edge cases). - -5. **Submit Your Work**: - - 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. +QUIZ DOS (tax) +### **documentación:** + +- **Fase 1: Análisis de Requisitos:** + - se reemplazaron todos los numeros magicos para dar logica al programa. +- **Fase 2: Diseño:** + - Diseñamos arreglos para poder albergar correctamente la informacion con un orden ekspecóifico. +- **Fase 3: Implementación:** + - implementamos el calculo dinamico mediante la utilización de bucles facilitanto y mejorando la eficiencia. +- **Fase 4: Pruebas:** + - se realizaron pruebas concretas. +- **Fase 5: Documentación:** + - se añadieron comentarios para facilitar pues el manejo de la informacion. diff --git a/src/AgeValidation.java b/src/AgeValidation.java index 40e0198..f5d84b2 100644 --- a/src/AgeValidation.java +++ b/src/AgeValidation.java @@ -1,13 +1,20 @@ +import java.util.Scanner; + public class AgeValidation { public static void main(String[] args) { - int age = 18; - - if (age >= 18) { + final int AGELIMITD = 18; + Scanner input = new Scanner(System.in); + int age = input.nextInt(); + if (age> AGELIMITD) { System.out.println("Access granted"); } - if (age < 18) { + else if (age < AGELIMITD && age > AGELIMITD) { System.out.println("Access denied"); } + else{ + System.out.println("invalid number"); + } + input.close(); } } diff --git a/src/Store.java b/src/Store.java index 2a4729a..b391478 100644 --- a/src/Store.java +++ b/src/Store.java @@ -1,19 +1,78 @@ +import java.util.Scanner; + 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; + //importe un scanner + Scanner input = new Scanner(System.in); + //pido cuantos usuarios van a usar el programa + System.out.println("ingrese la cantidad de usuarios que van a usar el programa"); + int numberUsers = input.nextInt(); + //hago arreglos paraalmacenar los precios y el total + int[] price = {15 , 10 , 5}; + int[] total = new int[numberUsers]; + //para que repita segun la cantidad de usuarios + for(int i=0; i 50) { System.out.println("Good sales performance"); } else { System.out.println("Low sales performance"); } + input.close(); } } diff --git a/src/TaxCalculation.java b/src/TaxCalculation.java index 3417866..76e618e 100644 --- a/src/TaxCalculation.java +++ b/src/TaxCalculation.java @@ -1,15 +1,46 @@ +import java.util.Scanner; + 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; + Scanner input = new Scanner(System.in); + //se realizó la definición de constantes + final double TAX_RATE_HIGH = 0.15; + final double TAX_RATE_LOW = 0.10; + final int TAX_THRESHOLD = 50; + System.out.println("ingrese la cantidad de precios que desea verificar "); + + //se crearon arrays necesarios para guardar la informacion + int quantityprices = input.nextInt(); + double[] prices = new double[quantityprices]; + double[] tax = new double[quantityprices]; + + //mendiante la utuilización de bucles se dinamizó el programa + for (int i=0 ; i=200){ + tax[i] = prices[i] * TAX_RATE_LOW; + } + + + } + double totalTax = 0; + for (int i=0; i 50) { - System.out.println("High total tax: " + totalTax); + //fianlmente se indicó los resultados + if (totalTax > TAX_THRESHOLD) { + System.out.println(" is a High total tax: " + totalTax); } else { - System.out.println("Low tax"); + System.out.println("is a Low tax"); } + input.close(); } } From 7e3bc124dbcca7205f8d29519ac7422111db1cf9 Mon Sep 17 00:00:00 2001 From: Frescghzt Date: Tue, 17 Sep 2024 07:21:50 -0500 Subject: [PATCH 2/2] feat(primos): new prime numbers program --- src/AgeValidation.java | 7 ++++--- src/primos.java | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/primos.java diff --git a/src/AgeValidation.java b/src/AgeValidation.java index f5d84b2..7ec6808 100644 --- a/src/AgeValidation.java +++ b/src/AgeValidation.java @@ -2,14 +2,15 @@ public class AgeValidation { public static void main(String[] args) { - final int AGELIMITD = 18; + + final int AGELIMIT = 18; Scanner input = new Scanner(System.in); int age = input.nextInt(); - if (age> AGELIMITD) { + if (age> AGELIMIT) { System.out.println("Access granted"); } - else if (age < AGELIMITD && age > AGELIMITD) { + else if (age < AGELIMIT && age > AGELIMIT) { System.out.println("Access denied"); } else{ diff --git a/src/primos.java b/src/primos.java new file mode 100644 index 0000000..71a2f56 --- /dev/null +++ b/src/primos.java @@ -0,0 +1,17 @@ +import java.util.Scanner; + +public class primos { + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + System.out.println("ingrese el numero que decea saber si es par"); + int number = input.nextInt(); + if((number%2) == 0){ + System.out.println("es par"); + }else{ + System.out.println("es impar"); + } + + input.close(); + } + +}