【发布时间】:2016-10-28 05:02:39
【问题描述】:
在第一个代码块中,我需要制作一个显示 3 种车辆类型的菜单,然后用户输入他将选择的车辆的数量,之后他需要被重定向到另一个显示列表的菜单车辆并选择一个,然后填写几个问题。我知道是西班牙语,对不起;__;
import java.util.Scanner;
public class Vehic {
public static void main(String[] args) {
int vehic;int comp;
Scanner sc=new Scanner(System.in);
System.out.println("¡Hola!,\nEscriba el numero de la clase de "
+ "vehiculo que desea comprar:\n1.Autos \n2.Camionetas "
+ "\n3.Motocicletas");
vehic=sc.nextInt();
switch(vehic) {
case 1:System.out.println("-AUTOMOVILES-\nEscriba el numero de "
+ "un automovil para añadirlo al carrito1. 542315 Tesla "
+ "X 2017 4500km \n2. 892567Honda Civic 2015 4200km "
+ "\n3. 634563 Tesla Z 2016 5600km \n4. 787256 Nissan "
+ "Sentra 1000km \n5. 646464 Tesla Y 2300km \n6. 359812 "
+ "BMW Hunter 7800km \n7. 159327 Mini Cooper 4500km \n8."
+ " 496251 Jeep 6000km");
comp=sc.nextInt();
while(comp<8){
switch(comp){
case 1:
String nom;
String ap;
int id;
String model;
System.out.println("Gracias por su compra!, "
+ "ingrese su nombre:");
nom=sc.next();
System.out.println("Ahora, ingrese su apellido");
ap=sc.next();
System.out.println("Por ultimo, ingrese su ID de "
+ "comprador:");
id=sc.nextInt();
System.out.println("Ingrese el modelo que adquirio");
model=sc.next();
System.out.println("-RECIBO- \nModelo adquirido:"
+ "542315 Tesla X 2017 4500km"+model
+" \n Almacenamos esta informacion de usted,"
+ " \nNombre:"+nom+"\nApellido:"+ap+"ID:"+id);
break;
case 2:
System.out.println("-CAMIONETAS-\nEscriba el numero "
+ "de la camioneta para añadirla al carrito1. "
+ "263785 Tesla X 2017VAN 4500km \n2. 892567"
+ "Honda Civic 2015VAN 4200km \n3. 634563 "
+ "Tesla Z 2016VAN 5600km \n4. 787256 "
+ "Nissan Sentra VAN1000km \n5. 646464 "
+ "Tesla YVAN 2300km \n6. 359812 BMW "
+ "HunterVAN 7800km \n7. 159327 Mini "
+ "CooperVAN 4500km \n8. 496251 JeepVAN "
+ "6000km");
comp=sc.nextInt();
while(comp<8) {
switch(comp){
case 1:
String Nom;
String Ap;
int Id;
System.out.println("Gracias por su "
+ "compra!, ingrese su nombre:");
Nom=sc.next();
System.out.println("Ahora, ingrese su apellido");
Ap=sc.next();
System.out.println("Por ultimo, ingrese su ID de comprador:");
Id=sc.nextInt();
System.out.println("Ingrese el modelo que adquirio");
model=sc.next();
System.out.println("-RECIBO- \nModelo adquirido:"
+model+"\n Almacenamos esta "
+ "informacion de usted, \nNombre:"
+Nom+"\nApellido:"+Ap+"ID:"+Id);
break;
case 3:
System.out.println("-MOTOCICLETAS-\n"
+ "Escriba el numero de la "
+ "camioneta para añadirla al "
+ "carrito1. 378265 Harley "
+ "Davidson 1995 4500km \n2. 736259"
+ "Instict 2006 4200km \n3. 264254 "
+ "Harley Davidson 2016 5600km \n4. "
+ "265731 Italika 3014 1000km \n5. "
+ "852645 JetX 2300km \n6. "
+ "356425Instict Hunter 7800km "
+ "\n7. 3592145 Italika 2006 4500km "
+ "\n8.234781 Harley Davidson 2008 6000km");
comp=sc.nextInt();
while(comp<8) {
switch(comp){
case 1:
String NOm;
String AP;
int ID;
System.out.println("Gracias "
+ "por su compra!, ingrese su nombre:");
NOm=sc.next();
System.out.println("Ahora, ingrese su apellido");
AP=sc.next();
System.out.println("Por ultimo, ingrese su ID de comprador:");
ID=sc.nextInt();
System.out.println("Ingrese el modelo que adquirio");
model=sc.next();
System.out.println("-RECIBO- \nModelo adquirido:"
+model+"\n Almacenamos esta informacion de usted, \nNombre: "
+NOm+"\nApellido:"+AP+"ID:"+ID);
break;
}
}
}
}
}
}
}
}
}
首先,我无法选择第 3 个案例,不知道为什么,当我选择 3 个案例中的 1 个时,我无法显示并能够回答问题
【问题讨论】:
-
在每个案例中的语句后添加中断:switch(variable){ case 0: your statement;休息;案例一:你的陈述;休息;等等。
-
如果我这样做的话,在每种情况下都有一段未到达的代码:/
标签: java menu switch-statement