MOISES_QUISPE_ROJAS

Estructura Datos 2021 - TP03 Helper

Oct 6th, 2021 (edited)
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.12 KB | None | 0 0
  1. /* Estructura de Datos - Facultad de Ingenieria - Universidad Nacional de Jujuy
  2.  *
  3.  * @Autor: Equipo 4.1
  4.  */
  5. /*      @integrantes:                  |    @Carrera:             |   @LU:
  6.                                        |                          |
  7.   Flores ,Cesar Ismael                 | Lic. en Sistemas         | 1782
  8.   Llampa, Ariel Angel Gabriel          | Ing. Informatica         | 8445
  9.   Machaca, Rodrigo Agustin             | Ing. Informatica         | 8512
  10.   Perez, Emanuel Ismael                | Ing. Informatica         | 8393
  11.   Quispe Rojas, Moises Esteban Nicolas | Ing. Informatica         | 7286
  12.  
  13.     Clase Helper
  14.  
  15. */
  16. package Queue;
  17.  
  18. import Stack.*;
  19. import Array.*;
  20. import java.text.ParseException;
  21. import java.text.SimpleDateFormat;
  22. import java.util.Date;
  23. import java.util.Random;
  24. import java.util.Scanner;
  25.  
  26. public class Helper {
  27.     private static Scanner input = new Scanner(System.in);
  28.     public static Random random=new Random();
  29.    
  30.      public static float getFloat(){
  31.         float numberfloat = 0;
  32.         boolean band = true;
  33.         do {
  34.             try {
  35.                 numberfloat = Float.parseFloat(input.nextLine());
  36.                 band = false;
  37.             } catch (NumberFormatException e) {
  38.                 System.out.println("Error...debe ingresar un numero");
  39.                 System.out.print("Ingrese nuevamente: ");
  40.             }
  41.         } while (band);
  42.         return numberfloat;
  43.     }
  44.    
  45.     public static String getString(){
  46.         String string;
  47.         do {
  48.             string = input.nextLine();
  49.             if (string.isBlank()) {
  50.                 System.out.println("Debe ingresar una cadena de texto");
  51.                 System.out.print("Ingrese nuevamente: ");
  52.             }
  53.         } while (string.isBlank());
  54.         return string;
  55.     }
  56.      
  57.     public static void showArray(Object array[]) {
  58.         for(int i=0;i<array.length;i++){
  59.             System.out.println("v[" + i + "]: " + array[i]);
  60.         }
  61.     }
  62.      
  63.     public static float getFloatPositive(){
  64.         float numberfloat = 0;
  65.         boolean band = true;
  66.         do {
  67.             try {
  68.                 numberfloat = Float.parseFloat(input.nextLine());
  69.                 if(numberfloat<=0){
  70.                     System.out.println("Debe ingresar un numero positivo");
  71.                     System.out.print("Intentelo de nuevo: ");
  72.                 }else{
  73.                     band = false;
  74.                 }
  75.             } catch (NumberFormatException e) {
  76.                 System.out.println("Error...debe ingresar un numero");
  77.                 System.out.print("Ingrese nuevamente: ");
  78.             }
  79.         } while (band);
  80.         return numberfloat;
  81.     }
  82.  
  83.     public static Date getDate(){
  84.         SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
  85.         boolean band = true;
  86.         Date testDate = null;
  87.         do{                    
  88.             String fecha = input.nextLine();  
  89.             try{
  90.                testDate = sdf.parse(fecha);
  91.                 band = false;
  92.             } catch (ParseException e){
  93.             System.out.print("Error... ");  
  94.                 System.out.print("Intentelo nuevamente:");
  95.             }
  96.         }while(band);
  97.         return testDate;
  98.     }
  99.    
  100.     public static int getIntegerPositive(){
  101.         int numberint = 0;
  102.         boolean band=true;
  103.         do{
  104.             try{
  105.                 numberint=Integer.parseInt(input.nextLine());
  106.                 if (numberint<=0){
  107.                     System.out.println("Debe ingresar un numero positivo");
  108.                     System.out.print("Intentelo de nuevo: ");
  109.                 }else{
  110.                     band=false;
  111.                 }
  112.             }catch(Exception e){
  113.                 System.out.println("Error...");
  114.                 System.out.print("Intentelo de nuevo: ");
  115.             }
  116.         }while(band);
  117.         return numberint;
  118.     }
  119.    
  120.     public static int getInteger(){
  121.         int numberint = 0;
  122.         boolean band=true;
  123.         do{
  124.             try{
  125.                 numberint=Integer.parseInt(input.nextLine());
  126.                 band=false;
  127.             }catch(Exception e){
  128.                 System.out.println("Error...");
  129.                 System.out.print("Intentelo de nuevo: ");
  130.             }
  131.         }while(band);
  132.         return numberint;
  133.     }
  134.    
  135.     public static char getChar(){
  136.         String character;
  137.         char singleCharacter;
  138.         boolean band;
  139.         do {
  140.             character = input.nextLine();
  141.             if(character.isBlank()){
  142.                 System.out.println("No ha ingresado un valor");
  143.                 System.out.print("Ingrese nuevamente: ");
  144.                 band = true;
  145.             }else{
  146.                 if(character.length()>1){
  147.                     System.out.println("Ingreso invalido");
  148.                     System.out.print("Ingrese nuevamente: ");
  149.                     band=true;
  150.                 }else{
  151.                  band = false;  
  152.                 }
  153.             }
  154.         } while (band!=false);
  155.         singleCharacter = character.charAt(0);
  156.         return singleCharacter;
  157.     }
  158.    
  159. }
Add Comment
Please, Sign In to add comment