Advertisement
Automake

ProgramaDeSorteioEmJava

Sep 4th, 2019
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 KB | None | 0 0
  1.     package programadesorteio;
  2.  
  3.         import javax.swing.*;
  4.  
  5.         public class Sorteio {
  6.         public static Object Sorteio;
  7.  
  8.  
  9.             private int numero;
  10.  
  11.           Sorteio() {
  12.                numero = (int) (1 + (Math.random() * 10)); //sorteia numeros entre 1 e 10
  13.            }
  14.  
  15.            public int getNumero() {
  16.                return this.numero;
  17.           }
  18.  
  19.            public void setNumero(int n) {
  20.                numero = n;
  21.           }
  22.  
  23.            public static void main(String args[]) {
  24.                Sorteio Sorteio1 = new Sorteio();
  25.                int resposta = Integer.parseInt(JOptionPane.showInputDialog("Informe o valor entre 1 e 10"));
  26.  
  27.                if (resposta == Sorteio1.getNumero()) {
  28.                    JOptionPane.showMessageDialog(null, "Você acertou o primeiro sorteio");
  29.                } else {
  30.                    JOptionPane.showMessageDialog(null, "Você errou o primeiro sorteio. \n O valor sorteado foi " + Sorteio1.getNumero());
  31.                }
  32.            
  33.                {
  34.                  Sorteio Sorteio2=new Sorteio();
  35.                    int resposta2=Integer.parseInt(JOptionPane.showInputDialog("Informe um valor entre 1 e 10"));
  36.  
  37.                    if (resposta2 ==Sorteio2.getNumero()){
  38.                        JOptionPane.showMessageDialog(null,"Você acertou o segundo sorteio");
  39.                    }else{
  40.                        JOptionPane.showMessageDialog(null,"Você errou o segundo sorteio. \n O valor sorteado foi " +Sorteio2.getNumero());
  41.  
  42.                    }
  43.                }
  44.                    {
  45.                        Sorteio Sorteio3=new Sorteio();
  46.                        int resposta3=Integer.parseInt(JOptionPane.showInputDialog("Informe um valor entre 1 e 10"));
  47.  
  48.                        if (resposta3==Sorteio3.getNumero()){
  49.                            JOptionPane.showMessageDialog(null,"Você acertou o terceiro sorteio");
  50.                        }else{
  51.                            JOptionPane.showMessageDialog(null,"Você errou o terceiro sorteio. \n O valor sorteado foi "+Sorteio3.getNumero());
  52.  
  53.                        }
  54.  
  55.                    System.exit(0);
  56.  
  57.  
  58.                    }
  59.            }
  60.         }
  61.  
  62.  
  63.     Voltar ao Topo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement