Skip to content

Instantly share code, notes, and snippets.

@PabloSanchezMartinez
Last active March 16, 2017 02:08
Show Gist options
  • Save PabloSanchezMartinez/d4e0a698d9277599aebace4299e974cf to your computer and use it in GitHub Desktop.
Save PabloSanchezMartinez/d4e0a698d9277599aebace4299e974cf to your computer and use it in GitHub Desktop.
PRACITCA 3
package bo.edu.ubilapaz;
import java.util.Stack;
//jejejej
public class Main {
public static void main(String[] args) {
Ticket t1 = new Ticket("Mana", "General", 200);
Ticket t2 = new Ticket("Mago de Oz", "Vip", 300);
Ticket t3 = new Ticket("Atajo", "Vip", 100);
Ticket t4 = new Ticket("Octavia", "General", 150);
Ticket t5 = new Ticket("Ricardo Arjona", "Vip", 100);
Ticket t6 = new Ticket("Manowar", "General", 800);
Ticket t7 = new Ticket("Efecto Mandarina", "General", 20);
Ticket t8 = new Ticket("Mana", "General", 200);
Ticket t9 = new Ticket("Manowar", "General", 800);
Ticket t10 = new Ticket("Manowar", "Vip", 1500);
Stack<Ticket> vip = new Stack<Ticket>();
vip.push(t2);
vip.push(t3);
vip.push(t5);
Stack<Ticket> gral = new Stack<Ticket>();
gral.push(t1);
gral.push(t4);
gral.push(t6);
gral.push(t7);
Stack<Ticket> vendidos = new Stack<Ticket>();
vendidos.push(t8);
vendidos.push(t9);
vendidos.push(t10);
mostrar(vip);
int total = recaudado(vendidos);
System.out.println("EL TOTAL RECAUDADO ES: " + total);
ticketsnovendidos(vip, gral);
mas_vendido(vendidos);
}
private static void mas_vendido(Stack<Ticket> vendidos) {
Stack<Ticket> aux = new Stack<Ticket>();
int vip = 0;
int gral = 0;
while (!vendidos.isEmpty()) {
Ticket x = vendidos.pop();
if (x.getTipo() == "Vip")
vip = vip + 1;
else
gral = gral + 1;
aux.push(x);
}
while (!aux.isEmpty()) {
Ticket x = aux.pop();
vendidos.push(x);
}
if (gral > vip)
System.out.println("la entrada mas vendida es GENERAL");
else
System.out.println("la entrada mas vendida es VIP");
}
private static void ticketsnovendidos(Stack<Ticket> vip, Stack<Ticket> gral) {
int total = 0;
total = vip.size() + gral.size();
System.out.println("EL NUMERO DE ENTRADAS SIN VENDER SON: " + total);
}
private static int recaudado(Stack<Ticket> v) {
int total = 0;
Stack<Ticket> aux = new Stack<Ticket>();
while (!v.isEmpty()) {
Ticket x = v.pop();
total = total + x.getCosto();
aux.push(x);
}
while (!aux.isEmpty()) {
Ticket x = aux.pop();
v.push(x);
}
return total;
}
private static void mostrar(Stack<Ticket> pila) {
Stack<Ticket> aux = new Stack<Ticket>();
while (!pila.isEmpty()) {
Ticket x = pila.pop();
System.out.println(x.getNombre() + " " + x.getTipo() + " " + x.getCosto());
aux.push(x);
}
while (!aux.isEmpty()) {
Ticket x = aux.pop();
pila.push(x);
}
}
}
package bo.edu.ubilapaz;
public class Ticket {
String nombre;
String tipo;
int costo;
public Ticket() {
this.nombre = " ";
this.tipo = " ";
this.costo = 0;
}
public Ticket(String nombre, String tipo, int costo) {
this.nombre = nombre;
this.tipo = tipo;
this.costo = costo;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getTipo() {
return tipo;
}
public void setTipo(String tipo) {
this.tipo = tipo;
}
public int getCosto() {
return costo;
}
public void setCosto(int costo) {
this.costo = costo;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment