Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Principal {
- public static void main(String[] args) {
- int opc = 0;
- List<Product>Lista = new List<Product>();
- Scanner S = new Scanner(System.in);
- do {
- Menu();
- opc = S.nextInt();
- System.out.println();
- switch (opc) {
- case 1:
- CrearAgregarALista(Lista);
- break;
- case 2:
- RemoverDeLista(Lista);
- break;
- case 3:
- Mostrar(Lista);
- break;
- case 4:
- System.out.println("Programa Finalizado...");
- break;
- default:
- System.out.println("Opcion no valida...");
- }
- }while(opc != 4);
- }
- public static void Menu() {
- System.out.println("\n********* MENU *********");
- System.out.println("1) Crear Objetos y agregarlos a la lista \n2) Remover o retirar Objetos \n3) Mostrar Lista \n4) Salir");
- System.out.print("\nOpcion: ");
- }
- public static void CrearAgregarALista(List<Product> Lista){
- Scanner in = new Scanner(System.in);
- int opc,Codigo,dia,mes,año;
- String Descripcion;
- float PrecioVenta;
- char resp;
- do {
- Codigo = 0; dia = 0; mes = 0; año = 0; PrecioVenta = 0;
- while(Codigo == 0) {
- System.out.print("Codigo del producto: ");
- Codigo = in.nextInt();
- if(Codigo == 0)
- System.out.println("El codigo no puede ser 0...");
- }
- if(!Lista.Contains(Codigo)) {
- in.nextLine();
- System.out.print("Descripcion: ");
- Descripcion = in.nextLine();
- System.out.println("Fecha de expiracion: ");
- while(dia == 0) {
- System.out.print("Dia: ");
- dia = in.nextInt();
- if(dia<=0 || dia>30) {
- dia=0;
- System.out.println("Dia no valido, ingrese un numero entre 0 y 30...");
- }
- }
- while(mes == 0) {
- System.out.print("Mes: ");
- mes = in.nextInt();
- if(mes<=0 || mes>12) {
- mes=0;
- System.out.println("Mes no valido, ingrese un numero entre 1 y 12...");
- }
- }
- while(año == 0) {
- System.out.print("Año: ");
- año = in.nextInt();
- if(año<1950) {
- año=0;
- System.out.println("Año fuera de rango, ingrese un año superior a 1950...");
- }
- }
- while(PrecioVenta == 0) {
- System.out.print("Precio de venta del producto ($): ");
- PrecioVenta = in.nextFloat();
- if(PrecioVenta<=0) {
- System.out.println("Precio de venta no valido...");
- }
- }
- Product Producto = new Product(Codigo,Descripcion,dia,mes,año,PrecioVenta);
- do {
- System.out.println("\n1) Agregar al Pricipio de la lista \n2) Agregar al Final de la lista");
- System.out.print("Opcion: ");
- opc = in.nextInt();
- switch (opc) {
- case 1:
- Lista.AddToHead(Producto);
- break;
- case 2:
- Lista.AddToTail(Producto);
- break;
- default:
- System.out.println("Opcion no valida...");
- }
- }while(opc != 1 && opc !=2);
- }
- else {
- System.out.println("Ya existe un Producto con el codigo ingresado...");
- }
- System.out.print("\n¿Crear otro Objeto y agregarlo? s/n : ");
- resp = in.next().charAt(0);
- }while(resp == 's' || resp == 'S');
- }
- public static void RemoverDeLista(List<Product> Lista) {
- Scanner in = new Scanner(System.in);
- char resp;
- int opc;
- do {
- do {
- System.out.println("1) Remover del principio \n2) Remover del final");
- System.out.print("Opcion: ");
- opc = in.nextInt();
- if(opc == 1 || opc == 2)
- System.out.println("\nProducto Removido...");
- switch (opc) {
- case 1:
- System.out.println(Lista.RemoveFromHead());
- break;
- case 2:
- System.out.println(Lista.RemoveFromTail());
- break;
- default:
- System.out.println("Opcion no valida...");
- }
- }while(opc != 1 && opc !=2);
- System.out.print("¿Remover otro objeto? s/n : ");
- resp = in.next().charAt(0);
- }while(resp == 's' || resp =='S');
- }
- public static void Mostrar(List<Product>Lista) {
- if(Lista.getCount()==0) {
- System.out.println("LA LISTA ESTÁ VACIA...");
- }
- else {
- System.out.println("LISTA...");
- Lista.Mostrar();
- }
- }
- }
Add Comment
Please, Sign In to add comment