From d87b15f15eac86080edd8e7dd9644725e8bec243 Mon Sep 17 00:00:00 2001 From: niksoftar7 Date: Fri, 13 Sep 2024 14:04:30 -0500 Subject: [PATCH 1/2] Refactor complete for quiz --- README.md | 72 ++++++++++------------------- src/AgeValidation.java | 16 +++++-- src/Store.java | 77 +++++++++++++++++++++++++++---- src/TaxCalculation.java | 47 +++++++++++++++---- trabajo.java | 100 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+), 69 deletions(-) create mode 100644 trabajo.java diff --git a/README.md b/README.md index 697a0cd..7489107 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,34 @@ -# 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 +QUIZ DOS (tax) +### **documentación:** -- 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 +- **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. ---- -## SDLC Approach +QUIZ TRES (age) +### **documentación:** -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. +- **Fase 1: Análisis de Requisitos:** + - se realiza la creacion de la constante limite de edad +- **Fase 2: Diseño:** + - Diseñamos arreglos para poder albergar correctamente la informacion con un orden especí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..7ec6808 100644 --- a/src/AgeValidation.java +++ b/src/AgeValidation.java @@ -1,13 +1,21 @@ +import java.util.Scanner; + public class AgeValidation { public static void main(String[] args) { - int age = 18; - - if (age >= 18) { + + final int AGELIMIT = 18; + Scanner input = new Scanner(System.in); + int age = input.nextInt(); + if (age> AGELIMIT) { System.out.println("Access granted"); } - if (age < 18) { + else if (age < AGELIMIT && age > AGELIMIT) { 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..5a69248 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(); } } diff --git a/trabajo.java b/trabajo.java new file mode 100644 index 0000000..ea48001 --- /dev/null +++ b/trabajo.java @@ -0,0 +1,100 @@ +import java.util.Scanner; + +public class trabajo { + public static void main(String[] args) { + + //Bienvenida al programa + Scanner input = new Scanner(System.in); + System.out.println("bienvenidos al programa de gestion de notas del curso"); + System.out.println("_____________________________________________________"); + + //se pregunta cuantos estudiantes van a registrar en el programa + System.out.println("ingrese la cantidad de estudiantes que van a registrar"); + + //se inicializan las variables para que funcionen correctamente con la proxima estructura + int flag = 0 , numberStudents = 0; + + //se utiliza esta estructura para poder recibir un numero valido + while ( flag == 0) { + numberStudents = input.nextInt(); + + //si el numero es correcto sale del bucle + if (numberStudents > 0) { + flag = 1; + } + + //si el numero no es correcto continua en el bucle + else{ + flag=0; + System.out.println("el numero ingresado no es valido, ingrese un numero que sea valido"); + } + + } + + //digo a cuantas personas se le va a almacenar informacion + String [] subjects = {"calculo" , "ingles" , "programacion"}; + String[] name = new String[numberStudents]; + int[] id = new int[numberStudents]; + double[] [] qualifications = new double[numberStudents] [subjects.length] ; + double[] average = new double[numberStudents]; + String[] status = new String[numberStudents]; + + + //se utiliza el for para que el programa se ejecute segun la cantidad de usuarios que allan + for (int i = 0; i< numberStudents ; i++) { + + + //se pide el nombre del estudiante + System.out.println("digite el nombre del estudiante " + (i+1)); + input.nextLine(); + name[i] = input.nextLine(); + + //se pide la identificacion del estudiante + System.out.println("digite la identificacion del estudiante " + (i+1)); + id[i] = input.nextInt(); + + //se almacenan los datos en las matrices + //la letra "s" va a significar sumador + for(int s = 0; s < subjects.length ; s++ ){ + System.out.println("ingrese la nota de " + subjects[s]+" del estudiante "+ name[i]); + qualifications[i][s] = input.nextDouble(); + flag=0; + while (flag==0) { + + //si la calificacion cumple la condicion sale del bucle + if (qualifications[i][s] >= 0 && qualifications[i][s] <=5) { + flag=1; + } + + //si no continua hasta que la calificacion sea valida + else{ + System.out.println("ingrese una nota valida"); + System.out.println("ingrese la nota numero " + (s+1)+" del estudiante "+ name[i]); + qualifications[i][s] = input.nextDouble(); + } + + } + + } + //definimos la variable promedio y le damos un valor + average[i] = (qualifications[i][0]+qualifications[i][1]+qualifications[i][2])/subjects.length; + + //creamos una condición para indicar si ha sido aprobado o no. + if (average[i]>=3 && average[i]<=5){ + status[i]="aprobado :)"; + } + else{ + status[i]="yucas parce :("; + + } + + } + + //imprimimos todos los datos obtenidos en orden. + for(int i=0;i Date: Tue, 17 Sep 2024 07:21:45 -0500 Subject: [PATCH 2/2] feat(decisiones ): new project --- src/decisiones.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/decisiones.java diff --git a/src/decisiones.java b/src/decisiones.java new file mode 100644 index 0000000..c8b46cd --- /dev/null +++ b/src/decisiones.java @@ -0,0 +1,19 @@ +import java.util.Scanner; + +public class decisiones { + public static void main(String[] args) { + Scanner decide = new Scanner(System.in); + System.out.println("elije un numero entre uno y dos"); + int number = decide.nextInt(); + if (number<1 || number>2){ + System.out.println("recuerde ingresar un numero valido"); + } + else if(number==1) { + System.out.println("Cevaztiam barre"); + } else { + System.out.println("Cevanstiam Duerme"); + } + decide.close(); + + } +}