Llenar un array hasta un lugar determinado
Publicado por franco (1 intervención) el 08/12/2014 22:52:14
Hola gente, como estan? aca estoy hacindo un programa de boleteria. Y me trabe en la muestra de las butacas disponibles en un teatro. La cuestion es que cuando pongo la opcion de mostrar las butacas por segunda vez, se me limpian las butacas vendidas, porque parce que toma la variable inicializada en cero nuevamente. A ver si me puedn dar una mano, les agradeceria.
------------------------------------------------
import java.util.Arrays;
import java.util.Scanner;
import java.io.*;
public class Boletos {
public static void main(String[] args) {
Scanner miscanner = new Scanner(System.in);
int op = 0;
char matriz[][] = new char[8][5];
int precioObra = 0;
int precioPremium = 0;
int precioVip = 0;
int totalStandar = 0;
int totalPremium = 0;
int totalVip = 0;
int tipoBoleto = 0;
int cantBoleto = 0;
int standar = 0;
int premium = 0;
int vip = 0;
int contStandar = 0;
int contPremium = 0;
int contVip = 0;
while (op != 3) {// REPITE HASTA Q ES FALSO
// menu principal
System.out.println("****************************");
System.out.println("*BIENVENIDOS AL TEATRO JAVA*");
System.out.println("****************************");
System.out.println("");
System.out.println("1.Detalles de la obra");
System.out.println("2.Venta de entradas");
System.out.println("3.Salir");
System.out.println("");
System.out.print("Ingrese una opción: ");
System.out.println("");
op = miscanner.nextInt();
switch (op) {
case 1:
while (op != 4) {
System.out.println("");
System.out.println("DETALLES DE LA OBRA");
System.out.println("''''''''''''''''''''");
System.out.println("1. Nombre de la obra: ");
System.out.println("2. Actores principales: ");
System.out.println("3. Fecha y hora de función");
System.out.println("4. Volver atras");
op = miscanner.nextInt();
String nombreObra = "";
String actoresObra = "";
String fechaObra = "";
switch (op) {// OPCION 1
case 1:
System.out.println("Nombre de la obra: ");
nombreObra = miscanner.next();
System.out.println("");
break;
case 2:
System.out.println("Actores principales: ");
actoresObra = miscanner.next();
System.out.println("");
break;
case 3:
System.out.println("Fecha y hora del show: ");
fechaObra = miscanner.next();
System.out.println("");
break;
case 4:
System.out.println("Volver... ");
System.out.println("");
break;
default:
System.out.println("");
System.out.println("#" + op + " Opcion invalida");
System.out.println("");
break;
}
}
break;
case 2:
while (op != 4) {
System.out.println("");
System.out.println("VENTA DE ENTRADAS");
System.out.println("'''''''''''''''''");
System.out.println("1. Venta de boletos: ");
System.out.println("2. Disponibilidad de butacas: ");
System.out.println("3. Listado de precio de boletos ");
System.out.println("4. Volver atras");
op = miscanner.nextInt();
switch (op) {
// abre Sub menú dentro de opción #1 del menu Principal
case 1:
System.out
.println("¿Qué tipo de boleto desea adquirir?");
System.out.println(" 1. Standar: ");
System.out.println(" 2. Premium: ");
System.out.println(" 3. Vip: ");
tipoBoleto = miscanner.nextInt();
if (tipoBoleto == 1) {
if (standar < 15) {
System.out
.println("¿Qué cantidad de boletos Standar? ");
System.out.println("Quedan disponibles: "
+ (15 - standar));
cantBoleto = miscanner.nextInt();
standar = standar + cantBoleto;
totalStandar = (cantBoleto * precioObra);
System.out.println("Total: $" + totalStandar);
} else {
System.out
.println("Sin boletos Standar disponibles.");
}
} else if (tipoBoleto == 2) {
if (premium < 15) {
System.out
.println("¿Qué cantidad de boletos Premium? ");
System.out.println("Quedan disponibles: "
+ (15 - premium));
cantBoleto = miscanner.nextInt();
premium = premium + cantBoleto;
totalPremium = (cantBoleto * precioPremium);
System.out.println("Total: $" + totalPremium);
} else {
System.out
.println("Sin boletos Premium disponibles.");
}
} else if (tipoBoleto == 3) {
if (vip < 10) {
System.out
.println("¿Qué cantidad de boletos Vip? ");
System.out.println("Quedan disponibles: "
+ (10 - vip));
cantBoleto = miscanner.nextInt();
vip = vip + cantBoleto;
totalVip = (cantBoleto * precioVip);
System.out.println("Total: $" + totalVip);
} else {
System.out
.println("Sin boletos Vip disponibles.");
}
} else {
System.out
.println("Eligió un tipo de boleto no valido.");
}
System.out.println("");
break;
case 2:
System.out.println("==================================");
System.out.println(" TEATRO JAVA ");
System.out.println("==================================");
//Butacas Vip
for (int x=0; x < 2; x++) {
for (int y=0; y < 5; y++) {
if (contVip < vip){
contVip = contVip + 1;
matriz[x][y] = 'V';
}
else{
matriz[x][y] = '-';
}
}
}
//Premium
for (int x=2; x < 5; x++) {
for (int y=0; y < 5; y++) {
if (contPremium < premium){
contPremium = contPremium + 1;
matriz[x][y] = 'P';
}
else{
matriz[x][y] = '-';
}
}
}
//Butacas Standar
for (int x=5; x < matriz.length; x++) {
for (int y=0; y < 5; y++) {
if (contStandar < standar){
contStandar = contStandar + 1;
matriz[x][y] = 'S';
}
else{
matriz[x][y] = '-';
}
}
}
//Muestra de butacas de teatro.
for (int x=0; x < matriz.length; x++) {
System.out.print("|");
for (int y=0; y < matriz[x].length; y++) {
System.out.print (matriz[x][y]);
if (y!=matriz[x].length-1) System.out.print("\t");
}
System.out.println("|");
}
break;
case 3:
System.out.println("Precio Standar: $");
precioObra = miscanner.nextInt();
// Se define el precio premium
precioPremium = (precioObra * 50) / 100;
precioPremium = precioPremium + precioObra;
// Se define el precio vip
precioVip = (precioObra * 100) / 100;
precioVip = precioVip + precioObra;
System.out.println("Precio Premium (50% +): $"
+ precioPremium);
System.out
.println("Precio Vip (100% +): $" + precioVip);
System.out.println("");
break;
case 4:
System.out.println("Volver...");
System.out.println("");
break;
default:// Opcion incorrecta
System.out.println("#" + op + " Opcion invalida");
System.out.println("");
break;
}// Cierra submenu
}
break;
case 3:
System.out.println("Salio del programa...");
break;
default:
System.out.println("Opcion " + op + " Invalida...");
}
}
}
}
------------------------------------------------
import java.util.Arrays;
import java.util.Scanner;
import java.io.*;
public class Boletos {
public static void main(String[] args) {
Scanner miscanner = new Scanner(System.in);
int op = 0;
char matriz[][] = new char[8][5];
int precioObra = 0;
int precioPremium = 0;
int precioVip = 0;
int totalStandar = 0;
int totalPremium = 0;
int totalVip = 0;
int tipoBoleto = 0;
int cantBoleto = 0;
int standar = 0;
int premium = 0;
int vip = 0;
int contStandar = 0;
int contPremium = 0;
int contVip = 0;
while (op != 3) {// REPITE HASTA Q ES FALSO
// menu principal
System.out.println("****************************");
System.out.println("*BIENVENIDOS AL TEATRO JAVA*");
System.out.println("****************************");
System.out.println("");
System.out.println("1.Detalles de la obra");
System.out.println("2.Venta de entradas");
System.out.println("3.Salir");
System.out.println("");
System.out.print("Ingrese una opción: ");
System.out.println("");
op = miscanner.nextInt();
switch (op) {
case 1:
while (op != 4) {
System.out.println("");
System.out.println("DETALLES DE LA OBRA");
System.out.println("''''''''''''''''''''");
System.out.println("1. Nombre de la obra: ");
System.out.println("2. Actores principales: ");
System.out.println("3. Fecha y hora de función");
System.out.println("4. Volver atras");
op = miscanner.nextInt();
String nombreObra = "";
String actoresObra = "";
String fechaObra = "";
switch (op) {// OPCION 1
case 1:
System.out.println("Nombre de la obra: ");
nombreObra = miscanner.next();
System.out.println("");
break;
case 2:
System.out.println("Actores principales: ");
actoresObra = miscanner.next();
System.out.println("");
break;
case 3:
System.out.println("Fecha y hora del show: ");
fechaObra = miscanner.next();
System.out.println("");
break;
case 4:
System.out.println("Volver... ");
System.out.println("");
break;
default:
System.out.println("");
System.out.println("#" + op + " Opcion invalida");
System.out.println("");
break;
}
}
break;
case 2:
while (op != 4) {
System.out.println("");
System.out.println("VENTA DE ENTRADAS");
System.out.println("'''''''''''''''''");
System.out.println("1. Venta de boletos: ");
System.out.println("2. Disponibilidad de butacas: ");
System.out.println("3. Listado de precio de boletos ");
System.out.println("4. Volver atras");
op = miscanner.nextInt();
switch (op) {
// abre Sub menú dentro de opción #1 del menu Principal
case 1:
System.out
.println("¿Qué tipo de boleto desea adquirir?");
System.out.println(" 1. Standar: ");
System.out.println(" 2. Premium: ");
System.out.println(" 3. Vip: ");
tipoBoleto = miscanner.nextInt();
if (tipoBoleto == 1) {
if (standar < 15) {
System.out
.println("¿Qué cantidad de boletos Standar? ");
System.out.println("Quedan disponibles: "
+ (15 - standar));
cantBoleto = miscanner.nextInt();
standar = standar + cantBoleto;
totalStandar = (cantBoleto * precioObra);
System.out.println("Total: $" + totalStandar);
} else {
System.out
.println("Sin boletos Standar disponibles.");
}
} else if (tipoBoleto == 2) {
if (premium < 15) {
System.out
.println("¿Qué cantidad de boletos Premium? ");
System.out.println("Quedan disponibles: "
+ (15 - premium));
cantBoleto = miscanner.nextInt();
premium = premium + cantBoleto;
totalPremium = (cantBoleto * precioPremium);
System.out.println("Total: $" + totalPremium);
} else {
System.out
.println("Sin boletos Premium disponibles.");
}
} else if (tipoBoleto == 3) {
if (vip < 10) {
System.out
.println("¿Qué cantidad de boletos Vip? ");
System.out.println("Quedan disponibles: "
+ (10 - vip));
cantBoleto = miscanner.nextInt();
vip = vip + cantBoleto;
totalVip = (cantBoleto * precioVip);
System.out.println("Total: $" + totalVip);
} else {
System.out
.println("Sin boletos Vip disponibles.");
}
} else {
System.out
.println("Eligió un tipo de boleto no valido.");
}
System.out.println("");
break;
case 2:
System.out.println("==================================");
System.out.println(" TEATRO JAVA ");
System.out.println("==================================");
//Butacas Vip
for (int x=0; x < 2; x++) {
for (int y=0; y < 5; y++) {
if (contVip < vip){
contVip = contVip + 1;
matriz[x][y] = 'V';
}
else{
matriz[x][y] = '-';
}
}
}
//Premium
for (int x=2; x < 5; x++) {
for (int y=0; y < 5; y++) {
if (contPremium < premium){
contPremium = contPremium + 1;
matriz[x][y] = 'P';
}
else{
matriz[x][y] = '-';
}
}
}
//Butacas Standar
for (int x=5; x < matriz.length; x++) {
for (int y=0; y < 5; y++) {
if (contStandar < standar){
contStandar = contStandar + 1;
matriz[x][y] = 'S';
}
else{
matriz[x][y] = '-';
}
}
}
//Muestra de butacas de teatro.
for (int x=0; x < matriz.length; x++) {
System.out.print("|");
for (int y=0; y < matriz[x].length; y++) {
System.out.print (matriz[x][y]);
if (y!=matriz[x].length-1) System.out.print("\t");
}
System.out.println("|");
}
break;
case 3:
System.out.println("Precio Standar: $");
precioObra = miscanner.nextInt();
// Se define el precio premium
precioPremium = (precioObra * 50) / 100;
precioPremium = precioPremium + precioObra;
// Se define el precio vip
precioVip = (precioObra * 100) / 100;
precioVip = precioVip + precioObra;
System.out.println("Precio Premium (50% +): $"
+ precioPremium);
System.out
.println("Precio Vip (100% +): $" + precioVip);
System.out.println("");
break;
case 4:
System.out.println("Volver...");
System.out.println("");
break;
default:// Opcion incorrecta
System.out.println("#" + op + " Opcion invalida");
System.out.println("");
break;
}// Cierra submenu
}
break;
case 3:
System.out.println("Salio del programa...");
break;
default:
System.out.println("Opcion " + op + " Invalida...");
}
}
}
}
Valora esta pregunta


0