Java - Programa en Java. Ayuda, por favor

 
Vista:

Programa en Java. Ayuda, por favor

Publicado por Lana (1 intervención) el 31/01/2022 14:45:57
Desarrollar un programa que permita capturar 5 productos cualquiera con su precio unitario y luego imprima la lista de estos en una tabla (o con estructura de tabla) con el precio total neto incluyendo el impuesto ITBMS 7%. Utilice el formato siguiente:

Lista de productos Precio
Producto a precio
Producto b precio
Producto c precio
Producto d precio
Producto e precio
---------------------------------------
Total : Precio Neto + ITBMS (7%)

Para el formateo del texto recuerda utilizar \t (tabulación)
Problema 2:
1. Se necesita un programa que permita obtener la cantidad de billetes en denominación de 20, 10 y 5 de una cantidad dada por el usuario, debe verificarse que la cantidad sea un múltiplo de 5 y posteriormente indicar la cantidad de billetes a entregar según la denominación. Utilizar la solicitud por medio de JOptionPane.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Billy Joel
Val: 2.665
Oro
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Programa en Java. Ayuda, por favor

Publicado por Billy Joel (876 intervenciones) el 18/02/2022 23:15:04
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
50
51
52
53
54
55
56
57
58
59
60
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;
 
public class TablaProducto {
 
    String nombre;
    private Double precio;
 
    public TablaProducto(String nombre, Double precio) {
        this.nombre = nombre;
        this.precio = precio;
    }
 
    @Override
    public String toString() {
        return "Producto\t" + nombre + "\t" + getPrecio();
    }
 
    /**
     * @return the precio
     */
    public Double getPrecio() {
        return precio;
    }
 
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int CANTIDAD_PRODUCTOS = 5;
        TablaProducto[] tabla = new TablaProducto[CANTIDAD_PRODUCTOS];
        Double total = 0.00;
        for (int i = 0; i < CANTIDAD_PRODUCTOS; i++) {
            System.out.print("Producto #" + (i + 1) + ": Introduzca el nombre: ");
            String nombre = br.readLine();
            System.out.print("Producto #" + (i + 1) + ": Introduzca el precio: ");
            Double precio = Double.parseDouble(br.readLine());
            tabla[i] = new TablaProducto(nombre, round2Decimals(precio));
            total += round2Decimals(precio);
        }
 
        System.out.println();
        for (TablaProducto p : tabla) {
            System.out.println(p);
        }
        System.out.println("---------------------------------------"
                + "\nTotal: " + round2Decimals(total * 1.07));
    }
 
    /**
     * Redondea una variable Double a 2 decimales
     *
     * @param val
     * @return
     */
    public static Double round2Decimals(Double val) {
        return new BigDecimal(val.toString()).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar