Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tienda;
- import java.util.Scanner;
- public class Tienda {
- static Storage storage;
- static Scanner entry = new Scanner(System.in);
- static float total = 0;
- static short selected = 0;
- static short exit = 8;
- public static void main(String[] args) {
- storage = new Storage();
- addItems("Leche", 0.8f, 3);
- addItems("Jamón", 8f, 1);
- addItems("Magdalenas", 2.3f, 5);
- addItems("Huevos", 1.4f, 1);
- askItems();
- end();
- }
- private static void askItems() {
- do { // Salir si se selecciona el producto 9
- mostrarProductos();
- print("Elige un producto (9 para salir): ");
- selected = (short) (entry.nextInt() - 1);
- if (selected == exit) continue; // Salir si se selecciona el producto 9
- if (storage.items.get(selected).GetStock() > 0) {
- println("Vendido.");
- total = (float) (total + storage.items.get(selected).price);
- storage.items.get(selected).sell();
- } else {
- println("Producto agotado");
- storage.items.remove(selected);
- }
- } while (selected != exit);
- }
- private static void end() {
- println("Total a pagar: " + total);
- println("Gracias por su visita");
- }
- /**
- *
- */
- private static void mostrarProductos() {
- println("LISTA DE PRODUCTOS");
- int i = 1;
- for (Items producto : storage.items) {
- println(i + ". " + producto.name + " " + producto.price + "€ Quedan : " + storage.items.get(i - 1).GetStock());
- i++;
- }
- }
- private static void println(String text){
- System.out.println(text);
- }
- private static void print(String text){
- System.out.print(text);
- }
- private static void addItems(String name, float price, int stock){
- storage.items.add(new Items (name, price, stock));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement