Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class G5E8Ticket {
- private double importe;
- private boolean abierto;
- private boolean descuentoPosible;
- private int cantidadProductos;
- /* post: el Ticket se inicializa con importe 0. */
- public G5E8Ticket(){
- importe = 0.0;
- abierto = true;
- descuentoPosible = true;
- cantidadProductos = 0;
- }
- /* pre: cantidad y precio son mayores a cero. El ticket está abierto.
- * post: suma al Ticket un item a partir de la cantidad de productos y su precio unitario. */
- public void agregarItem(int cantidad, double precioUnitario){
- if (abierto && cantidad>0 && precioUnitario>0){
- importe = importe + (cantidad*precioUnitario);
- cantidadProductos = cantidadProductos + cantidad;
- }
- }
- /* pre : el Ticket está abierto y no se ha aplicado un descuento previamente.
- * post: aplica un descuento sobre el total del importe. */
- public void aplicarDescuento(double porcentaje){
- if (abierto && descuentoPosible){
- importe = importe - ((importe * porcentaje) / 100);
- descuentoPosible= false;
- }
- }
- /* post: devuelve el importe acumulado hasta el momento sin cerrar el Ticket. */
- public double calcularSubtotal(){
- return (importe);
- }
- /* post: cierra el Ticket y devuelve el importe total. */
- public double calcularTotal(){
- abierto = false;
- return (importe);
- }
- /* post: devuelve la cantidad total de productos. */
- public int contarProductos(){
- return (cantidadProductos);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement