Alexis-Coria

Untitled

Aug 28th, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class Resolucion {
  5.  
  6. public static void main(String[] args) {
  7. int opc = 0,a , b , result , sumtotal=0, i=0 ,prodtotal=0;
  8. while (opc != 4) {
  9. opc=menus();
  10. switch (opc)
  11. {
  12. case 1:
  13. System.out.println("Ingrese valor de a.");
  14. a=entradas();
  15. System.out.println("Ingrese valor de b.");
  16. b=entradas();
  17. result=opdatos(a,b);
  18. if (result == a+b)
  19. { sumtotal = sumtotal + result;
  20. }
  21. if (result == a*b)
  22. { prodtotal = prodtotal + result;
  23. i=i+1;
  24. }
  25. System.out.println("El resultado es: "+ result);
  26. break;
  27. case 2:
  28. System.out.println("Generando valores random para a y b.");
  29. Random ar= new Random();
  30. int ar1 = ar.nextInt();
  31. Random br = new Random();
  32. int br1 = br.nextInt();
  33. result= opdatos(ar1,br1);
  34. System.out.println("El resultado es: "+ result);
  35. if (result == ar1+br1)
  36. { sumtotal = sumtotal + result;
  37. }
  38. if (result == ar1*br1)
  39. { prodtotal = prodtotal + result;
  40. i=i+1;
  41. }
  42. break;
  43. case 3:
  44. System.out.println("El total de sumas acumuladas es: "+ sumtotal);
  45. System.out.println("El promedio de productos es: "+ prodtotal/i);
  46. break;
  47. default:
  48. System.out.println("Seleccione una opcion valida.");
  49. }
  50.  
  51. }
  52.  
  53. }
  54. public static int entradas() {
  55. Scanner sn = new Scanner(System.in);
  56. int teclado = sn.nextInt();
  57. return teclado;
  58. }
  59.  
  60. public static String entradalog() {
  61. Scanner sn = new Scanner(System.in);
  62. String teclado = sn.next();
  63. return teclado;
  64. }
  65.  
  66. public static int menus() {
  67. int sel;
  68. System.out.println("Calculadora");
  69. System.out.println("Seleccione una opcion.");
  70. System.out.println("1 - Ingreso de datos.");
  71. System.out.println("2 - Numeros al azar.");
  72. System.out.println("3 - Total de procedimientos.");
  73. System.out.println("4 - Finalizar");
  74. sel = entradas();
  75. return sel;
  76.  
  77. }
  78.  
  79.  
  80. public static int opdatos(int x , int y){
  81. String s;
  82. int op = 0;
  83. System.out.println("Ingrese operador logico.");
  84. s=entradalog();
  85. switch (s)
  86. {
  87. case "+":
  88. op = x+y;
  89. break;
  90. case "-":
  91. op = x-y;
  92. break;
  93. case "*":
  94. op = x*y;
  95. break;
  96. case "/":
  97. if (y!=0)
  98. { op = x/y;
  99. }
  100. System.out.println("Error: Division por 0.");
  101. break;
  102. default:
  103. System.out.println("Ingrese un operador logico valido ( + , - , * , / ).");
  104. }
  105.  
  106. return op;
  107. }
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment