Jurado001

TP4ej3_Principal

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