Development of exercises 11 to 20 of programming 1 in Java.

11. It is necessary to develop a program that allows obtaining the final value of a car, entering its base value and knowing that a discount of 10% can be applied to the base value if the car is worth $ 20,000,000 or less, 15% if the car it is worth between $ 20,000,000 and $ 30,000,000, and 20% if the car is worth more than $ 30,000,000. 

import java.text.DecimalFormat;
import javax.swing.JOptionPane;

public class Index {
    
    public static void main(String[] args){
        long precioCoche, descuento, total;
        int porcentajeDescuento = 0;
        
        DecimalFormat formatter = new DecimalFormat("#,###");
        
        precioCoche = Long.parseLong(JOptionPane.showInputDialog(null, "Ingrese el precio del carro: "));
        
        if(precioCoche <= 20000000.0){
            porcentajeDescuento = 10;
        }else if(precioCoche >= 20000000.0 && precioCoche <= 30000000.0){
            porcentajeDescuento = 15;
        }else if(precioCoche > 30000000.0){
            porcentajeDescuento = 20;
        }
        
        descuento = (precioCoche * porcentajeDescuento) / 100;
        
        JOptionPane.showMessageDialog(null, "Descuento de: $ " + formatter.format(descuento) + " COP. \nPrecio final del auto: $" + formatter.format(precioCoche - descuento)  + " COP");
    }
}

12. Create a program to calculate and print the price of a piece of land from which the following data are entered: length in meters, width in meters and price per hectare. If the land has more than 50 hectares, a discount of 17% can be made, if it has more than 100 hectares the discount is 25%.

import java.text.DecimalFormat;
import javax.swing.JOptionPane;

public class Index {
    
    public static void main(String[] args){
        double largoMetros, anchoMetros, precioHectarea, areaTerreno, hectareas, precioTotal, descuento;
        int porcentajeDescuento = 0;
        
        DecimalFormat formatter = new DecimalFormat("#,###");
        
        largoMetros = Double.parseDouble(
            JOptionPane.showInputDialog(null, "Ingrese el largo del terreno en metros: ")
        );
        
        anchoMetros = Double.parseDouble(
            JOptionPane.showInputDialog(null, "Ingrese el ancho del terreno en metros: ")
        );
        
        precioHectarea = Double.parseDouble(
            JOptionPane.showInputDialog(null, "Ingrese el precio por hectarea: ")
        );
        
        areaTerreno = largoMetros * anchoMetros;
        hectareas = areaTerreno / 10000.0;
        
        precioTotal = hectareas * precioHectarea;
        
        if(hectareas >= 50 && hectareas <= 100){
            porcentajeDescuento = 17;
        }else if(hectareas > 100){
            porcentajeDescuento = 25;
        }
        
        descuento = (precioTotal * porcentajeDescuento) / 100;
        
        JOptionPane.showMessageDialog(
            null, 
            "Se aplico un descuento de: $"+ formatter.format(descuento) + "\n"
            + "El precio del terreno es de: $" + formatter.format(precioTotal - descuento)
        );
    }
}

13. Construct a program such that, given as data the category of the worker, the value of the worker's workday and the number of days worked, calculate the corresponding increase taking into account the following table. Print the worker's category and their new salary.

CATEGORIA AUMENTO
1 15%
2 10%
3 8%
4 5%
import java.text.DecimalFormat;
import javax.swing.JOptionPane;

public class Index {
    
    public static void main(String[] args){
        double valorDiaTrabajo, salario, aumento;
        int diasTrabajados, categoria;
        int porcentajeAumento = 0;
        
        DecimalFormat formatter = new DecimalFormat("#,###");
        
        categoria = Integer.parseInt(
            JOptionPane.showInputDialog(null, "Ingrese la categoría del trabajados (1,2,3 o 4): ")
        );
        
        diasTrabajados = Integer.parseInt(
            JOptionPane.showInputDialog(null, "Ingrese el número de dias trabajados: ")
        );
        
        valorDiaTrabajo = Double.parseDouble(
            JOptionPane.showInputDialog(null, "Ingrese el salario por dia del trabajador: ")
        );
        
        switch(categoria){
            case 1:
                porcentajeAumento = 15;
                break;
            case 2:
                porcentajeAumento = 10;
                break;
            case 3:
                porcentajeAumento = 8;
                break;
            case 4:
                porcentajeAumento = 5;
                break;
        }
        
        salario = (diasTrabajados * valorDiaTrabajo);
        aumento = (salario * porcentajeAumento) / 100;
        
        JOptionPane.showMessageDialog(
            null, 
            "El salario del trabajador es de: $" + formatter.format(salario + aumento)
        );
    }
}

14. A bookstore sells books with the following conditions: If the client is type 1, 30% is discounted, if the client is type 2, 20% is discounted, if the client is type 3, 10% is discounted. . When the customer makes a purchase, the following data is recorded: Customer name, customer type, number of books and cost per book (ALL books are considered to be of the same value). Create a program that reads this data and prints name, total to pay, discount and net to pay.

import java.text.DecimalFormat;
import javax.swing.JOptionPane;

public class Index {
    
    public static void main(String[] args){
        String nombreCliente;
        double costoPorLibro, descuento, total;
        int tipoCliente, cantidadLibros, porcentajeDescuento;
        
        DecimalFormat formatter = new DecimalFormat("#,###");
        
        nombreCliente = JOptionPane.showInputDialog(null, "Ingrese el nombre del cliente: ");
        
        tipoCliente = Integer.parseInt(
            JOptionPane.showInputDialog(null, "Ingrese el tipo de cliente (1,2 o 3): ")
        );
        
        cantidadLibros = Integer.parseInt(
            JOptionPane.showInputDialog(null, "Ingrese el número de libros que se llevarán:")
        );
        
        costoPorLibro = Double.parseDouble(
            JOptionPane.showInputDialog(null, "Ingrese el precio por libro: ")
        );
        
        switch(tipoCliente){
            case 1:
                porcentajeDescuento = 30;
                break;
            case 2:
                porcentajeDescuento = 20;
                break;
            case 3:
                porcentajeDescuento = 10;
                break;
            default:
                porcentajeDescuento = 0;
                break;
        }
        
        total = (cantidadLibros * costoPorLibro);
        descuento = (total * porcentajeDescuento) / 100;
        
        JOptionPane.showMessageDialog(
            null, 
            "Factura a nombre de: " + nombreCliente + "\n"
            + "Tipo de cliente: " + tipoCliente + "\n"
            + "Total de libros: " + cantidadLibros + "\n"
            + "Costo por libro: $" + formatter.format(costoPorLibro) + "\n"
            + "Subtotal: $" + formatter.format(total) + "\n"
            + "Descuento: - $" + formatter.format(descuento) + "\n"
            + "Total a pagar: $" + formatter.format(total - descuento)
        );
    }
}

15. Make a program that determines the payment to be made for the entrance to a show where you can buy only up to four tickets, where if you buy two tickets you are discounted 10%, when you buy three tickets 15% and when you buy four tickets are discounted 20%. The value of the ticket is $ 60,000. If the number of tickets is greater than 4, the program must show that a maximum of 4 tickets can be purchased. If the number of tickets is less than 1, the program must show that at least 1 ticket must be purchased.

import java.text.DecimalFormat;
import javax.swing.JOptionPane;

public class Index {
    public static final double PRECIO_ENTRADA = 60000.0;
    
    public static void main(String[] args){
        double total, descuento;
        int porcentajeDescuento;
        int numeroEntradas = 0;
        boolean esValido = false;
        
        DecimalFormat formatter = new DecimalFormat("#,###");
        
        while(!esValido){
            numeroEntradas = Integer.parseInt(
                JOptionPane.showInputDialog(null, "Ingrese el número de tiquetes a comprar (minimo 1 y máximo 4 tiquetes):")
            );
            
            if(numeroEntradas >= 1 && numeroEntradas <= 4){
                esValido = true;
            }else{
                JOptionPane.showMessageDialog(
                    null, 
                    "El número de tiquetes que desea comprar es inválido, debe comprar como minimo 1 y máximo 4. Intente nuevamente", 
                    "Error", 
                    JOptionPane.ERROR_MESSAGE
                );
            }
        }
        
        switch(numeroEntradas){
            case 4:
                porcentajeDescuento = 20;
                break;
            case 3:
                porcentajeDescuento = 15;
                break;
            case 2:
                porcentajeDescuento = 10;
                break;
            default:
                porcentajeDescuento = 0;
                break;
        }
        
        total = numeroEntradas * PRECIO_ENTRADA;
        descuento = (total * porcentajeDescuento) / 100;
        
        JOptionPane.showMessageDialog(null, 
            "Entradas: " + numeroEntradas + "\n"
            + "Subtotal: $" + formatter.format(total) + "\n"
            + "Descuento: - $" + formatter.format(descuento) + "\n"
            + "Total a pagar: $" + formatter.format(total - descuento)
        );
        
    }
}

17. You want to develop a program that, by entering an amount of money expressed in pesos, indicates how many bills and coins you can have at least to complete this value. The amount entered must be a multiple of $ 50, and you must work with current denominations.

import javax.swing.JOptionPane;

public class Index {
    public static final double PRECIO_ENTRADA = 60000.0;
    
    public static void main(String[] args){
        int montoDinero = 0;
        boolean esValido = false;
        final int[] valor_denominaciones = new int[]{
            50000, 20000 , 10000 , 5000 , 2000 , 1000 , 500, 200 , 100 , 50
        };
        final String[] denominaciones = new String[]{
            "$50.000" , "$20.000" , "$10.000" , "$5.000" , "$2.000" , "$1.000" , "500" , "200" , "100" , "50"
        };
        
        while(!esValido){
            montoDinero = Integer.parseInt(JOptionPane.showInputDialog(null, "Ingrese la cantidad de dinero en pesos (multiplo de 50): "));
            
            if((montoDinero % 50) == 0){
                esValido = true;
            }else{
                JOptionPane.showMessageDialog(
                    null, 
                    "El número ingresado no es multiplo de 50, por favor ingrese nuevamente la cantidad", 
                    "Error", 
                    JOptionPane.ERROR_MESSAGE
                );
            }
        }

        int[] cantidad = new int[valor_denominaciones.length];

        String mensaje = "El valor de $" + montoDinero + " COP distribuido en diferentes valores: \n\n";
        
        for(int i = 0 ; i < cantidad.length ; i++){
            cantidad[i] = montoDinero / valor_denominaciones[i];
            montoDinero %= valor_denominaciones[i];

            if(cantidad[i] != 0){
                mensaje += cantidad[i] + " de " + denominaciones[i] + "\n";
            }
        }
        
        JOptionPane.showMessageDialog(null, mensaje);
    }
}

Sponsors