Advertisement
KaiserRego

G5E8Ticket

Sep 24th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. public class G5E8Ticket {
  2.    
  3.     private double importe;
  4.     private boolean abierto;
  5.     private boolean descuentoPosible;
  6.     private int cantidadProductos;
  7.    
  8.     /* post: el Ticket se inicializa con importe 0. */
  9.     public G5E8Ticket(){
  10.        
  11.         importe = 0.0;
  12.         abierto = true;
  13.         descuentoPosible = true;
  14.         cantidadProductos = 0;
  15.     }
  16.    
  17.     /* pre: cantidad y precio son mayores a cero. El ticket está abierto.
  18.      * post: suma al Ticket un item a partir de la cantidad de productos y su precio unitario. */
  19.     public void agregarItem(int cantidad, double precioUnitario){
  20.        
  21.         if (abierto && cantidad>0 && precioUnitario>0){
  22.             importe = importe + (cantidad*precioUnitario);
  23.             cantidadProductos = cantidadProductos + cantidad;
  24.         }
  25.     }
  26.    
  27.     /* pre : el Ticket está abierto y no se ha aplicado un descuento previamente.
  28.      * post: aplica un descuento sobre el total del importe. */
  29.     public void aplicarDescuento(double porcentaje){
  30.        
  31.         if (abierto && descuentoPosible){
  32.             importe = importe - ((importe * porcentaje) / 100);
  33.             descuentoPosible= false;
  34.         }
  35.     }
  36.  
  37.     /* post: devuelve el importe acumulado hasta el momento sin cerrar el Ticket. */
  38.     public double calcularSubtotal(){
  39.        
  40.         return (importe);
  41.     }
  42.    
  43.     /* post: cierra el Ticket y devuelve el importe total. */
  44.     public double calcularTotal(){
  45.        
  46.         abierto = false;
  47.         return (importe);
  48.     }
  49.    
  50.     /* post: devuelve la cantidad total de productos. */
  51.     public int contarProductos(){
  52.        
  53.         return (cantidadProductos);
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement