Created
September 5, 2016 01:20
-
-
Save anonymous/59679165e891e0645fb0454577c2017f to your computer and use it in GitHub Desktop.
UBI - Wilfredo Sillerico Galvez - Practica 2
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 bo.edu.ubilapaz; | |
import java.util.Stack; | |
/** | |
* NOMBRE: Wilfredo Sillerico G. | |
* MATERIA: Estructura de Datos | |
* Práctica Nro.2 | |
* Clase: Main | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
// Definición de las pilas | |
Stack<Ticket> ven1Vip = new Stack<>(); | |
Stack<Ticket> ven1Gral = new Stack<>(); | |
Stack<Ticket> ven2Vip = new Stack<>(); | |
Stack<Ticket> ven2Gral = new Stack<>(); | |
Stack<Ticket> vendidos = new Stack<>(); | |
// Llenado de datos en las pilas de cada ventanilla | |
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); | |
// Definición y llenado de tickets vendidos | |
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); | |
// Muestra el contenido de las pilas | |
System.out.println("Ventanilla 1 VIP"); | |
mostrar(ven1Vip); | |
System.out.println("Ventanilla 1 GRAL"); | |
mostrar(ven1Gral); | |
System.out.println("Ventanilla 2 VIP"); | |
mostrar(ven2Vip); | |
System.out.println("Ventanilla 2 GRAL"); | |
mostrar(ven2Gral); | |
System.out.println("Vendidos"); | |
mostrar(vendidos); | |
// Solución inciso 1 | |
calcularVendidos(vendidos); | |
// Solución inciso 2 | |
int totVip = 0; | |
int totGral = 0; | |
totVip = totVip + cuentaTickets(ven1Vip, ""); | |
totGral= totGral + cuentaTickets(ven1Gral, ""); | |
totVip= totVip + cuentaTickets(ven2Vip, ""); | |
totGral= totGral + cuentaTickets(ven2Gral, ""); | |
System.out.println(""); | |
System.out.println("Tickets sin vender: " + (totVip + totGral)); | |
System.out.println("De VIP: " + totVip); | |
System.out.println("De General: " + totGral); | |
// Solución inciso 3 | |
totVip = 0; | |
totGral = 0; | |
totVip = cuentaTickets(vendidos, "VIP"); | |
totGral = cuentaTickets(vendidos, "GRAL"); | |
System.out.println(""); | |
if (totVip > totGral) { | |
System.out.println("Se vendió más entradas VIP: " + totVip); | |
} else { | |
System.out.println("Se vendió más entradas de General: " + totGral); | |
} | |
} | |
// Muestra el contenido de las pilas | |
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); | |
} | |
} | |
// Calcula la suma de los tickets vendidos | |
public static void calcularVendidos(Stack<Ticket> pila){ | |
Stack<Ticket> aux = new Stack<Ticket>(); | |
double sum = 0.0; | |
while (!pila.isEmpty()){ | |
Ticket a = pila.pop(); | |
sum = sum + a.getCosto(); | |
aux.push(a); | |
} | |
while (!aux.isEmpty()){ | |
Ticket a = aux.pop(); | |
pila.push(a); | |
} | |
System.out.println("Total vendido: " + sum); | |
} | |
// Cuenta la cantidad de tickets de determinado tipo | |
public static int cuentaTickets(Stack<Ticket> pila, String tipo){ | |
Stack<Ticket> aux = new Stack<Ticket>(); | |
int total = 0; | |
while (!pila.isEmpty()){ | |
Ticket a = pila.pop(); | |
if (tipo.equals("")) { | |
total = total + 1; | |
} else { | |
if (a.getTipo().equals(tipo)) { | |
total = total + 1; | |
} | |
} | |
aux.push(a); | |
} | |
while (!aux.isEmpty()){ | |
Ticket a = aux.pop(); | |
pila.push(a); | |
} | |
return(total); | |
} | |
} |
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 bo.edu.ubilapaz; | |
/** | |
* NOMBRE: Wilfredo Sillerico G. | |
* MATERIA: Estructura de Datos | |
* Práctica Nro.2 | |
* Clase: Ticket | |
*/ | |
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