online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
/****************************************************************************** EN LA PC 4 (2022-1) VULEVEN A PREGUNTAR SOBRE ESTA PREGUNTA *******************************************************************************/ import java.util.ArrayList; import java.util.Random; //class ListaApp{ class Main{ static ArrayList <Item> lista = new ArrayList<>(); static Random rand = new Random(); static char lNombre = 'A'; public static void main(String[] args){ inicio(); System.out.println("----------------------------"); mercado(); System.out.println("----------------------------"); informeFinal(); } static int random(int m, int n){ return m + rand.nextInt(n-m+1); } static void inicio(){ // CREA LISTA DE ENTRE 6 A 9 ELEMENTOS QUE TIENEN "nombre, cantidad y precio" int n = random(6, 9); int i=0; for(; i<n; i++) lista.add(new Item(Character.toString(lNombre++), random(1, 10), random(1, 10))); // INICIA TEXTO A IMPRIMIR System.out.println("Lista de Compras Inicial: \nItem \tNombre \tUnidad \tCant. \t PreIni\tCostoIni"); i=1; float costoIni, sCostoIni = 0; for(Item it: lista){ costoIni = it.getCostoIni(); System.out.printf("%2d \t%4s \t%5s \t%2d \t%6.2f \t%6.2f\n", i++, it.nombre, it.unidad, it.cantidad, it.preIni, costoIni); sCostoIni += costoIni; } // TOTAL System.out.printf("Total:\t\t\t\t\t %6.2f\n", sCostoIni); } static void mercado(){ System.out.println("\nCambios en el mercado:"); System.out.println("item " + 2 + ": se eliminó"); Item it = lista.remove(2-1); // remove Item 2 System.out.printf("%2d\t%4s\t%5s\t%2d\t%6.2f\n", 2, it.nombre, it.unidad, it.cantidad, it.preIni); System.out.println("\nitem " + 3 + ": se insertó"); it = new Item(Character.toString(lNombre++), random(1, 10), random(1, 10)); lista.add(3-1, it); // inserta item en posición 3 System.out.printf("%2d\t%4s\t%5s\t%2d\t%6.2f\n", 3, it.nombre, it.unidad, it.cantidad, it.preIni); System.out.println("\nitem " + 4 + ": se modificó la unidad a Bolsa"); // ANTES DE MODIFICACION it = lista.get(4-1); System.out.printf("%2d\t%4s\t%5s\t%2d\t%6.2f\n", 4, it.nombre, it.unidad, it.cantidad, it.preIni); // DESPUES DE MODIFICACION it.unidad = "Bolsa"; // Modifica item 4 System.out.printf("%2d\t%4s\t%5s\t%2d\t%6.2f\n", 4, it.nombre, it.unidad, it.cantidad, it.preIni); lista.set(4-1, it); for(Item lis: lista) lis.preFinal += lis.preIni + random(-2, 2); // cálculo de precios Finales } static void informeFinal(){ System.out.println(); System.out.println("Lista de Compras Final:"); System.out.println("Item \tNombre \tUnidad \tCant. \tPreIni \tPreFin \t C.Ini C.Final\tC.Final-C.Ini "); int i = 1; float costoIni, sCostoIni = 0, costoFinal, sCostoFinal = 0, dif, sDif = 0; for(Item it: lista) { costoIni = it.getCostoIni(); costoFinal = it.getCostoFinal(); dif = costoFinal - costoIni; System.out.printf("%2d\t%4s\t%6s\t %2d\t%6.2f\t %6.2f\t %6.2f\t %6.2f\t %6.2f\n", i++, it.nombre, it.unidad, it.cantidad, it.preIni, it.preFinal, costoIni, costoFinal, dif); sCostoIni += costoIni; sCostoFinal += costoFinal; } System.out.printf("Total:\t\t\t\t\t\t %6.2f\t %6.2f\t %6.2f\n", sCostoIni, sCostoFinal, sCostoFinal-sCostoIni); } } class Item{ String nombre; String unidad; int cantidad; float preIni; // precio Inicial float preFinal; // precio Final Item(String nombre, int cantidad, float preIni){ this.nombre = nombre; unidad = "Kg."; this.cantidad = cantidad; this.preIni = preIni; } float getCostoIni(){ return cantidad*preIni; } float getCostoFinal(){ return cantidad*preFinal; } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue