• Lenguaje

    Java usando Scanner

  • Descripción

    Determinar el valor a pagar por hospedaje en un determinado hotel, de acuerdo a los siguientes requerimientos:
    1.- Mostrar un menú de opciones donde se muestre el tipo de habitación y su precio: (Sencilla - $25, Doble - $40, Matrimonial - $65). El usuario debe elegir un solo tipo de habitación e indicar el número de días de hospedaje.
    2.- Considerar un descuento del 8% si el número de días de hospedaje es mayor o igual a 3 y sólo para el tipo de habitación matrimonial.

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
import java.util.Scanner;

public class PagoPorHospedaje {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int tipo_de_habitacion;
        double descuento, dias_de_hospedaje, precio, subtotal, total;
        System.out.print("Ingresa el valor de dias de hospedaje: ");
        dias_de_hospedaje = in.nextDouble();
        in.nextLine();
        precio=0;
        System.out.println("Selecciona el valor de tipo de habitacion.");
        System.out.println("\t1.- Sencilla");
        System.out.println("\t2.- Doble");
        System.out.println("\t3.- Matrimonial");
        System.out.print("\t: ");
        do {
            tipo_de_habitacion = in.nextInt();
            in.nextLine();
            if (tipo_de_habitacion<1||tipo_de_habitacion>3)
                System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
        } while (tipo_de_habitacion<1||tipo_de_habitacion>3);
        if(tipo_de_habitacion==1)
            precio=25;
        if(tipo_de_habitacion==2)
            precio=40;
        if(tipo_de_habitacion==3)
            precio=65;
        subtotal=dias_de_hospedaje*precio;
        if(dias_de_hospedaje>=3&&tipo_de_habitacion==3)
            descuento=subtotal*0.08;
        else
            descuento=0;
        total=subtotal-descuento;
        System.out.println("Valor de descuento: " + descuento);
        System.out.println("Valor de precio: " + precio);
        System.out.println("Valor de subtotal: " + subtotal);
        System.out.println("Valor de total: " + total);
    }

}