Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PackDados;
- import java.util.Scanner;
- class Dados{
- public static void main (String[] args) {
- pedirOpcion();
- interactuarConUsuario();
- }
- static void pedirOpcion() {
- 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 ");}
- static void interactuarConUsuario() {
- Scanner scan = new Scanner(System.in);
- int opcion = scan.nextInt();
- int numero = 0;
- int numAux;
- switch(opcion) {
- case 1:
- numero = (int) (Math.random()*4+1);
- break;
- case 2:
- numero = (int) (Math.random()*6+1);
- break;
- case 3:
- numero = (int) (Math.random()*8+1);
- break;
- case 4:
- numero = (int) (Math.random()*10+1);
- break;
- case 5:
- numero = (int) (Math.random()*12+1);
- break;
- case 6:
- numero = (int) (Math.random()*20+1);
- break;
- case 7:
- numero = (int) (Math.random()*10+1); numAux = (int) (Math.random()*10+1);
- System.out.println(numero+" "+numAux);
- break;
- case 8:
- System.out.println("ha sido un placer, adios");
- return; //Sale del programa si es la opción de salir
- default:
- System.out.println("Opción incorrecta, recuerda: ");
- pedirOpcion();
- interactuarConUsuario();
- break;
- }
- if (opcion < 8) {
- interactuarConUsuario();
- System.out.println(numero);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement