Advertisement
Guest User

Tienda.java

a guest
Oct 22nd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1. package tienda;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Tienda {
  6.  
  7.     static Storage storage;
  8.     static Scanner entry = new Scanner(System.in);
  9.     static float total = 0;
  10.     static short selected = 0;
  11.     static short exit = 8;
  12.     public static void main(String[] args) {
  13.         storage = new Storage();
  14.         addItems("Leche", 0.8f, 3);
  15.         addItems("Jamón", 8f, 1);
  16.         addItems("Magdalenas", 2.3f, 5);
  17.         addItems("Huevos", 1.4f, 1);
  18.        
  19.         askItems();
  20.         end();
  21.     }
  22.    
  23.     private static void askItems() {
  24.         do { // Salir si se selecciona el producto 9
  25.             mostrarProductos();
  26.  
  27.             print("Elige un producto (9 para salir): ");
  28.             selected = (short) (entry.nextInt() - 1);
  29.  
  30.             if (selected == exit) continue; // Salir si se selecciona el producto 9
  31.            
  32.             if (storage.items.get(selected).GetStock() > 0) {
  33.                 println("Vendido.");
  34.                 total = (float) (total + storage.items.get(selected).price);
  35.                 storage.items.get(selected).sell();
  36.             } else {
  37.                 println("Producto agotado");
  38.                 storage.items.remove(selected);
  39.             }
  40.         } while (selected != exit);
  41.     }
  42.    
  43.     private static void end() {
  44.         println("Total a pagar: " + total);
  45.         println("Gracias por su visita");
  46.     }
  47.     /**
  48.      *
  49.      */
  50.     private static void mostrarProductos() {
  51.         println("LISTA DE PRODUCTOS");
  52.         int i = 1;
  53.         for (Items producto : storage.items) {
  54.             println(i +  ". " + producto.name + " " + producto.price + "€ Quedan : " + storage.items.get(i - 1).GetStock());
  55.             i++;
  56.         }        
  57.     }
  58.    
  59.     private static void println(String text){
  60.         System.out.println(text);
  61.     }
  62.    
  63.     private static void print(String text){
  64.         System.out.print(text);
  65.     }
  66.    
  67.     private static void addItems(String name, float price, int stock){
  68.         storage.items.add(new Items (name, price, stock));
  69.     }    
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement