Created
July 27, 2022 22:47
-
-
Save dragonnomada/8899f81e096013a8557aa1458c419999 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class TiendaFrutas { | |
public static void main(String[] args) { | |
double kilosManzana = 0.0; | |
double precioManzana = 0.0; | |
double totalKilosVendidos = 0.0; | |
double totalDineroAcumulado = 0.0; | |
int totalVentasRealizadas = 0; | |
Scanner escaner = new Scanner(System.in); | |
while (true) { | |
System.out.printf("Total de Ventas: %d %n", totalVentasRealizadas); | |
System.out.printf("Total Vendido: %.2f %n", totalDineroAcumulado); | |
System.out.printf("Kilos Vendidos: %.2f %n", totalKilosVendidos); | |
System.out.println("------------------------------------"); | |
System.out.printf("Kilos Manzana Disponibles: %.2f %n", kilosManzana); | |
System.out.printf("Precio de la Manzana: %.2f %n", precioManzana); | |
System.out.println("------------------------------------"); | |
System.out.println("Selecciona una opción:"); | |
System.out.println("1. Fijar precio de Manzana"); | |
System.out.println("2. Fijar kilos de Manzana"); | |
System.out.println("3. Realizar venta de Manzana"); | |
System.out.println("4. Salir"); | |
System.out.print("Opción: "); | |
int opcion = escaner.nextInt(); | |
switch(opcion) { | |
case 1: | |
System.out.print("¿Cuál es el precio de la manzana? "); | |
precioManzana = escaner.nextDouble(); | |
System.out.println("Se actualizó el precio de la manzana"); | |
break; | |
case 2: | |
System.out.print("¿Cuántos kilos hay de manzana? "); | |
kilosManzana = escaner.nextDouble(); | |
System.out.println("Se actualizaron los kilos de manzana"); | |
break; | |
case 3: | |
System.out.print("¿Cuántos kilos de manzana desea vender? "); | |
double kilosManzanaVenta = escaner.nextDouble(); | |
if (kilosManzanaVenta <= kilosManzana) { | |
// La venta es posible | |
double totalVenta = kilosManzanaVenta * precioManzana; | |
// Actualizamos los valores | |
kilosManzana = kilosManzana - kilosManzanaVenta; | |
totalKilosVendidos = totalKilosVendidos + kilosManzanaVenta; | |
totalDineroAcumulado = totalDineroAcumulado + totalVenta; | |
totalVentasRealizadas = totalVentasRealizadas + 1; | |
System.out.printf("Se vendieron %.2f kilos de manzana a %.2f %n", kilosManzanaVenta, totalVenta); | |
} else { | |
// La venta no es posible | |
System.out.printf("No se pueden vender %.2f kilos de manzana %n", kilosManzanaVenta); | |
} | |
break; | |
case 4: | |
escaner.close(); | |
System.exit(0); | |
break; | |
default: | |
System.out.println("Opción no válida"); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment