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
69 changes: 13 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

16 changes: 12 additions & 4 deletions src/AgeValidation.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
77 changes: 68 additions & 9 deletions src/Store.java
Original file line number Diff line number Diff line change
@@ -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<numberUsers; i++){
//declaro una bandera y un subtotal
int flag = 0, subTotal = 0;
//digo que usuario es
System.out.println("usuario "+ (i+1));
while (flag ==0) {
//pido al usuario lo que decea almacenar
System.out.println("que decea agregar");
System.out.println(" codigo precio");
System.out.println(" 1 15");
System.out.println(" 2 10");
System.out.println(" 3 5");
//dependiendo el codigo almacena la info
int code = input.nextInt();
switch (code) {
case 1:
System.out.println("cuantas unidades va a almacenar");
int unity = input.nextInt();
subTotal += unity*price[(code-1)];
break;
case 2:
System.out.println("cuantas unidades va a almacenar");
unity = input.nextInt();
subTotal += unity*price[(code-1)];
break;

case 3:
System.out.println("cuantas unidades va a almacenar");
unity = input.nextInt();
subTotal += unity*price[(code-1)];
break;

//si da un codigo mayor o menor a esos no lo deja continuar
default:
System.out.println("codigo no valido");
break;

}
//le dice si quiere continuar o salir del usuario
System.out.println("si decea agregar otro articulo escriba 0");
System.out.println("si no escriba otro numero");
flag = input.nextInt();
}
//almacena la informacion de cada usuario
total[i]=subTotal;



}
int totalSales = 0;
//suma todos los usuarios
for(int i = 0; i<numberUsers; i++){
totalSales+=total[i];

}
//le dice si cumplio el requerimiento o no
System.out.println("su total del dia es: "+totalSales);
if (totalSales > 50) {
System.out.println("Good sales performance");
} else {
System.out.println("Low sales performance");
}
input.close();
}
}
47 changes: 39 additions & 8 deletions src/TaxCalculation.java
Original file line number Diff line number Diff line change
@@ -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<quantityprices ; i++){
System.out.println("ingresa el precio numero " + (i+1));
prices[i] = input.nextDouble();

if (prices[i]<200 ){
tax[i] = prices[i] * TAX_RATE_HIGH;

}
else if (prices[i]>=200){
tax[i] = prices[i] * TAX_RATE_LOW;
}


}
double totalTax = 0;
for (int i=0; i <quantityprices; i++){
totalTax += tax[i];
}
System.out.println("el impuesto total es "+totalTax);

if (totalTax > 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();
}
}
17 changes: 17 additions & 0 deletions src/primos.java
Original file line number Diff line number Diff line change
@@ -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();
}

}