-
Lenguaje
Java usando Scanner
-
Descripción
Un restaurante vende dos tipos de comidas, servidas a 4.50 y para llevar a 6.00. Realice un algoritmo que teniendo como datos por cada cliente su nombre, tipo de comida y cantidad a comprar, calcule y de cómo salida el nombre y el neto a pagar por cada cliente, tomando en cuenta que el restaurante da una rebaja del 15% por cada compra que exceda de los 4 comidas.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.Scanner;
public class ComidasServidasYParaLlevar {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int tipo_de_comida;
double cantidad_a_comprar, neto_a_pagar, rebaja, subtotal;
String nombre;
String tecla_repetir;
do {
System.out.print("Ingresa el nombre: ");
nombre = in.nextLine();
System.out.print("Ingresa el valor de cantidad a comprar: ");
cantidad_a_comprar = in.nextDouble();
in.nextLine();
in.nextLine();
System.out.println("Selecciona el valor de tipo de comida.");
System.out.println("\t1.- servidas");
System.out.println("\t2.- para llevar");
System.out.print("\t: ");
do {
tipo_de_comida = in.nextInt();
in.nextLine();
if (tipo_de_comida<1||tipo_de_comida>2)
System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
} while (tipo_de_comida<1||tipo_de_comida>2);
if(tipo_de_comida==1)
subtotal=4.5*cantidad_a_comprar;
else
subtotal=6.0*cantidad_a_comprar;
if(cantidad_a_comprar>4)
rebaja=subtotal*0.15;
else
rebaja=0;
neto_a_pagar=subtotal-rebaja;
System.out.println("Nombre: " + nombre);
System.out.println("Valor de neto a pagar: " + neto_a_pagar);
System.out.println("Valor de rebaja: " + rebaja);
System.out.println("Valor de subtotal: " + subtotal);
System.out.println();
do {
System.out.print("\u00BFDeseas repetir el proceso? (S/N): ");
tecla_repetir = in.nextLine();
} while (!tecla_repetir.equalsIgnoreCase("s") && !tecla_repetir.equalsIgnoreCase("n"));
} while (tecla_repetir.equalsIgnoreCase("s"));
}
}
public class ComidasServidasYParaLlevar {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int tipo_de_comida;
double cantidad_a_comprar, neto_a_pagar, rebaja, subtotal;
String nombre;
String tecla_repetir;
do {
System.out.print("Ingresa el nombre: ");
nombre = in.nextLine();
System.out.print("Ingresa el valor de cantidad a comprar: ");
cantidad_a_comprar = in.nextDouble();
in.nextLine();
in.nextLine();
System.out.println("Selecciona el valor de tipo de comida.");
System.out.println("\t1.- servidas");
System.out.println("\t2.- para llevar");
System.out.print("\t: ");
do {
tipo_de_comida = in.nextInt();
in.nextLine();
if (tipo_de_comida<1||tipo_de_comida>2)
System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
} while (tipo_de_comida<1||tipo_de_comida>2);
if(tipo_de_comida==1)
subtotal=4.5*cantidad_a_comprar;
else
subtotal=6.0*cantidad_a_comprar;
if(cantidad_a_comprar>4)
rebaja=subtotal*0.15;
else
rebaja=0;
neto_a_pagar=subtotal-rebaja;
System.out.println("Nombre: " + nombre);
System.out.println("Valor de neto a pagar: " + neto_a_pagar);
System.out.println("Valor de rebaja: " + rebaja);
System.out.println("Valor de subtotal: " + subtotal);
System.out.println();
do {
System.out.print("\u00BFDeseas repetir el proceso? (S/N): ");
tecla_repetir = in.nextLine();
} while (!tecla_repetir.equalsIgnoreCase("s") && !tecla_repetir.equalsIgnoreCase("n"));
} while (tecla_repetir.equalsIgnoreCase("s"));
}
}