Question about discounts in java

0

I have the following statement:

  

Design and implement the following    program: - Decide (use constants):

     

● What is the minimum value to qualify for the discount? ● How much   will discount what is the maximum possible value ● - Ask for the price   initial, in euros - Read it - Checking is not negative: ● If   true, see if the price entered is greater than or equal to the minimum value   to opt for the discount - In this case, calculate the discount -   Check if the discount exceeds the maximum allowable ● If true,   the discount is reduced to the maximum allowable - Apply the discount   about the initial price - Show the final price If the price was   negative, display an error message.

I've done this, but it does not work for me

package practicas;

import java.util.Scanner;

public class Practica5 {//las constantes siempre se introducen antes del main

private static final double VALOR_MINIMO = 20;

private static final double DESCUENTO = 0.5;

private static final double VALOR_MAXIMO = 40;

public static void main(String[] args) {

    int numero;
    double precio;
    Scanner teclado = new Scanner(System.in);


    System.out.println("¿cual es el precio inicial? \n");
    precio = teclado.nextDouble();

    if (precio < 0) {
        System.out.println("El número es incorrecto");

    } else if (precio >= VALOR_MINIMO) {

        double cantidadADescontar = precio * DESCUENTO;

        if (cantidadADescontar > VALOR_MAXIMO) {
            cantidadADescontar= VALOR_MAXIMO;
        }   

        precio = precio - cantidadADescontar;
        System.out.println("El precio es" + precio);

    }

}
}
    
asked by marxal 28.09.2017 в 09:49
source

0 answers