Created
August 31, 2016 03:15
-
-
Save alvareztech/62200a8fb619fd154da56864ac2cfc18 to your computer and use it in GitHub Desktop.
Estructura de datos>Pilas>Práctica 2>Solución 1
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
package tech.alvarez; | |
import java.util.Stack; | |
public class Main { | |
public static void main(String[] args) { | |
Stack<Ticket> ven1Vip = new Stack<Ticket>(); | |
Stack<Ticket> ven1Gral = new Stack<Ticket>(); | |
Stack<Ticket> ven2Vip = new Stack<Ticket>(); | |
Stack<Ticket> ven2Gral = new Stack<Ticket>(); | |
Stack<Ticket> vendidos = new Stack<Ticket>(); | |
Ticket t1 = new Ticket("VIP", 500.0, "Angeles Azules"); | |
Ticket t2 = new Ticket("GRAL", 100.0, "Angeles Azules"); | |
Ticket t3 = new Ticket("VIP", 500.0, "Angeles Azules"); | |
Ticket t4 = new Ticket("VIP", 500.0, "Angeles Azules"); | |
Ticket t5 = new Ticket("GRAL", 50.0, "Kjarkas"); | |
Ticket t6 = new Ticket("VIP", 400.0, "Kjarkas"); | |
Ticket t7 = new Ticket("VIP", 400.0, "Kjarkas"); | |
ven1Vip.push(t1); | |
ven1Vip.push(t3); | |
ven1Gral.push(t2); | |
ven2Vip.push(t4); | |
ven2Vip.push(t6); | |
ven2Vip.push(t7); | |
ven2Gral.push(t5); | |
Ticket t8 = new Ticket("GRAL", 50.0, "Kjarkas"); | |
Ticket t9 = new Ticket("VIP", 500.0, "Angeles Azules"); | |
Ticket t10 = new Ticket("VIP", 400.0, "Kjarkas"); | |
vendidos.push(t8); | |
vendidos.push(t9); | |
vendidos.push(t10); | |
System.out.println("VEN1 VIP"); | |
mostrar(ven1Vip); | |
System.out.println("VEN1 GRAL"); | |
mostrar(ven1Gral); | |
System.out.println("VEN2 VIP"); | |
mostrar(ven2Vip); | |
System.out.println("VEN2 GRAL"); | |
mostrar(ven2Gral); | |
System.out.println("VENDIDOS"); | |
mostrar(vendidos); | |
// Solucion 1 | |
calcularVendidos(vendidos); | |
// Solucion 2 | |
// Solucion 3 | |
} | |
public static void mostrar(Stack<Ticket> pila) { | |
Stack<Ticket> aux = new Stack<Ticket>(); | |
while (!pila.isEmpty()) { | |
Ticket a = pila.pop(); | |
System.out.println(" Ticket: " + a.getTipo() + " " + a.getCosto() + " " + a.getNombreConcierto()); | |
aux.push(a); | |
} | |
while(!aux.isEmpty()) { | |
Ticket a = aux.pop(); | |
pila.push(a); | |
} | |
} | |
public static void calcularVendidos(Stack<Ticket> pila) { | |
double sum = 0.0; | |
while (!pila.isEmpty()) { | |
Ticket a = pila.pop(); | |
sum = sum + a.getCosto(); | |
} | |
System.out.println("Total vendido: " + sum); | |
} | |
} |
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
package tech.alvarez; | |
public class Ticket { | |
private String tipo; | |
private double costo; | |
private String nombreConcierto; | |
public Ticket(String tipo, double costo, String nombreConcierto) { | |
this.tipo = tipo; | |
this.costo = costo; | |
this.nombreConcierto = nombreConcierto; | |
} | |
public String getTipo() { | |
return tipo; | |
} | |
public void setTipo(String tipo) { | |
this.tipo = tipo; | |
} | |
public double getCosto() { | |
return costo; | |
} | |
public void setCosto(double costo) { | |
this.costo = costo; | |
} | |
public String getNombreConcierto() { | |
return nombreConcierto; | |
} | |
public void setNombreConcierto(String nombreConcierto) { | |
this.nombreConcierto = nombreConcierto; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment