Advertisement
gabuwu

TP04-EJ4- HELPER new

Nov 18th, 2021
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. package TP4;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class Helper {
  7.  
  8. Random random = new Random();
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. public boolean continuar() {
  12. boolean seguir = true;
  13.  
  14. int opc;
  15. do {
  16. opc = ingresoNum();
  17. if (opc == 1) {
  18. seguir= true;
  19. }else if(opc==2){
  20.  
  21. seguir=false;
  22. print("\n-------------------\nFin del programa...\n------------------");
  23. }else {
  24. print("Opcion invalida. Ingrese correctamente\n");
  25. }
  26. }while(opc>2 || opc <1);
  27. return seguir;
  28.  
  29. }
  30.  
  31. public int ingresoNum() {
  32. int numero=0;
  33. int cont=0;
  34.  
  35. while (cont == 0) {
  36. Scanner scanner= new Scanner(System.in);
  37. try{
  38. numero=scanner.nextInt();
  39. cont =1;
  40. }catch(Exception e) {
  41. print("No se Ingreso correctamente, por favor ingrese nuevamente...");
  42. cont =0;
  43. }
  44. }
  45. return numero;
  46. }
  47.  
  48. public int generarRand () {
  49.  
  50. int numRand =(int) (Math.random()*500+1);
  51. System.out.println("El numero aleatorio genrado es: "+numRand);
  52. return numRand;
  53.  
  54. }
  55. public void print(String texto) {
  56. System.out.println(texto);
  57. }
  58.  
  59. public String toString(int num) {
  60. return Integer.toString(num);
  61.  
  62. }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement