-4
コードの第1ブロックでは、3種類の車両を表示するメニューを作成する必要があります。その後、車のリストを表示して1つを選択してから、いくつかの質問を記入する別のメニューにリダイレクトする必要があります。それはスペイン語で私は知っている、ごめんなさい; __;スイッチメニューでは、ケースを選択できないため、表示することができません
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例1を選択したときも、私はそれを表示し、質問に答えることができるように得ることができない、第三のケースを選択することはできませんし、理由を知らない
各ケース内にbreak after文を追加します。switch(variable){case 0:ブレーク;ケース1:あなたの声明。ブレーク; – HaroldSer
すべてのケースで未到達コードがあります: – Zhenam