Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. package PackDados;
  2. import java.util.Scanner;
  3. class Dados{
  4. public static void main (String[] args) {
  5.     pedirOpcion();
  6.     interactuarConUsuario();
  7. }
  8.    
  9.     static void pedirOpcion() {
  10.         System.out.println("Buenos días, escoge un dado: \n 1)1d4 , 2)1d6, 3) 1d8, \n 4)1d10, 5)1d12, 6)1d20 \n 7)2d10, 8)salir ");}
  11.    
  12.     static void interactuarConUsuario() {
  13.         Scanner scan = new Scanner(System.in);
  14.         int opcion = scan.nextInt();
  15.     int numero = 0;
  16.     int numAux;
  17.             switch(opcion) {
  18.                 case 1:
  19.           numero = (int) (Math.random()*4+1);
  20.           break;
  21.                 case 2:
  22.           numero = (int) (Math.random()*6+1);
  23.           break;
  24.                 case 3:
  25.           numero = (int) (Math.random()*8+1);
  26.           break;
  27.                 case 4:
  28.           numero = (int) (Math.random()*10+1);
  29.           break;
  30.                 case 5:
  31.           numero = (int) (Math.random()*12+1);
  32.           break;
  33.                 case 6:
  34.           numero = (int) (Math.random()*20+1);
  35.           break;
  36.                 case 7:
  37.           numero = (int) (Math.random()*10+1); numAux = (int) (Math.random()*10+1);
  38.                     System.out.println(numero+" "+numAux);
  39.           break;
  40.                 case 8:
  41.           System.out.println("ha sido un placer, adios");
  42.           return; //Sale del programa si es la opción de salir
  43.                 default:
  44.           System.out.println("Opción incorrecta, recuerda: ");
  45.           pedirOpcion();
  46.           interactuarConUsuario();
  47.           break;
  48.       }
  49.  
  50.       if (opcion < 8) {
  51.         interactuarConUsuario();
  52.         System.out.println(numero);
  53.       }
  54.            
  55.         }          
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement