Advertisement
Jurado001

TP4ej2_Principal

Oct 12th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Principal {
  4.  
  5.     public static void main(String[] args) {
  6.         int opc = 0;
  7.         List<Product>Lista = new List<Product>();
  8.         Scanner S = new Scanner(System.in);
  9.        
  10.         do {
  11.             Menu();
  12.             opc = S.nextInt();
  13.             System.out.println();
  14.             switch (opc) {
  15.                 case 1:
  16.                     CrearAgregarALista(Lista);
  17.                     break;
  18.                 case 2:
  19.                     RemoverDeLista(Lista);
  20.                     break;
  21.                 case 3:
  22.                     Mostrar(Lista);
  23.                     break;
  24.                 default:
  25.                     System.out.println("Opcion no valida...");
  26.                 }
  27.         }while(opc != 4);
  28.        
  29.     }
  30.    
  31.     public static void Menu() {
  32.         System.out.println("\n********* MENU *********");
  33.         System.out.println("1) Crear Objetos y agregarlos a la lista \n2) Remover o retirar Objetos \n3) Mostrar Lista \n4) Salir");
  34.         System.out.print("\nOpcion: ");
  35.     }
  36.  
  37.     public static void CrearAgregarALista(List<Product> Lista){
  38.         Scanner in = new Scanner(System.in);
  39.         int opc,Codigo,dia,mes,año;
  40.         String Descripcion;
  41.         float PrecioVenta;
  42.         char resp;
  43.         do {
  44.             Codigo = 0; dia = 0; mes = 0; año = 0; PrecioVenta = 0;
  45.             while(Codigo == 0) {
  46.                 System.out.print("Codigo del producto: ");
  47.                 Codigo = in.nextInt();
  48.                 if(Codigo == 0)
  49.                     System.out.println("El codigo no puede ser 0...");
  50.             }
  51.             in.nextLine();
  52.             System.out.print("Descripcion: ");
  53.             Descripcion = in.nextLine();
  54.             System.out.println("Fecha de expiracion: ");
  55.             while(dia == 0) {
  56.                 System.out.print("Dia: ");
  57.                 dia = in.nextInt();
  58.                 if(dia<=0 || dia>30) {
  59.                     dia=0;
  60.                     System.out.println("Dia no valido, ingrese un numero entre 0 y 30...");
  61.                 }
  62.             }
  63.             while(mes == 0) {
  64.                 System.out.print("Mes: ");
  65.                 mes = in.nextInt();
  66.                 if(mes<=0 || mes>12) {
  67.                     mes=0;
  68.                     System.out.println("Mes no valido, ingrese un numero entre 1 y 12...");
  69.                 }
  70.             }
  71.             while(año == 0) {
  72.                 System.out.print("Año: ");
  73.                 año = in.nextInt();
  74.                 if(año<1950) {
  75.                     año=0;
  76.                     System.out.println("Año fuera de rango, ingrese un año superior a 1950...");
  77.                 }
  78.             }
  79.             while(PrecioVenta == 0) {
  80.                 System.out.print("Precio de venta del producto ($): ");
  81.                 PrecioVenta = in.nextFloat();
  82.                 if(PrecioVenta<=0) {
  83.                     System.out.println("Precio de venta no valido...");
  84.                 }
  85.             }
  86.             Product Producto = new Product(Codigo,Descripcion,dia,mes,año,PrecioVenta);
  87.             do {
  88.                 System.out.println("\n1) Agregar al Pricipio de la lista \n2) Agregar al Final de la lista");
  89.                 System.out.print("Opcion: ");
  90.                 opc = in.nextInt();
  91.                 switch (opc) {
  92.                 case 1:
  93.                     Lista.AddToHead(Producto);
  94.                     break;
  95.                 case 2:
  96.                     Lista.AddToTail(Producto);
  97.                     break;
  98.                 default:
  99.                     System.out.println("Opcion no valida..."); 
  100.                 }
  101.             }while(opc != 1 && opc !=2);
  102.            
  103.             System.out.print("\n¿Crear otro Objeto y agregarlo? s/n : ");
  104.             resp = in.next().charAt(0);
  105.         }while(resp == 's' || resp == 'S');
  106.     }
  107.  
  108.     public static void RemoverDeLista(List<Product> Lista) {
  109.         Scanner in = new Scanner(System.in);
  110.         char resp;
  111.         int opc;
  112.         do {
  113.             do {
  114.                 System.out.println("1) Remover del principio \n2) Remover del final");
  115.                 System.out.print("Opcion: ");
  116.                 opc = in.nextInt();
  117.                 if(opc == 1 || opc == 2)
  118.                     System.out.println("\nProducto Removido...");
  119.                 switch (opc) {
  120.                 case 1:
  121.                     System.out.println(Lista.RemoveFromHead());
  122.                     break;
  123.                 case 2:
  124.                     System.out.println(Lista.RemoveFromTail());
  125.                     break;
  126.                 default:
  127.                     System.out.println("Opcion no valida..."); 
  128.                 }
  129.             }while(opc != 1 && opc !=2);
  130.            
  131.             System.out.print("¿Remover otro objeto? s/n : ");
  132.             resp = in.next().charAt(0);
  133.         }while(resp == 's' || resp =='S');
  134.     }
  135.    
  136.     public static void Mostrar(List<Product>Lista) {
  137.         if(Lista.getCount()==0) {
  138.             System.out.println("LA LISTA ESTÁ VACIA...");
  139.         }
  140.         else {
  141.             System.out.println("LISTA...");
  142.             Lista.Mostrar();
  143.         }
  144.     }
  145.    
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement