Exemplo n.º 1
0
  public static void main(String[] args) {
    double a = Double.parseDouble(JOptionPane.showInputDialog("Enter the first value: ", "0"));
    double b = Double.parseDouble(JOptionPane.showInputDialog("Enter the second value ", "0"));
    double average = (a + b) / 2;

    int rounded = (int) average; // This is casting!

    int option =
        Integer.parseInt(
            JOptionPane.showInputDialog(
                "Choose the operation \n 1 - Average \n 2 - Rounded Average"));
    if (option != 1 && option != 2) {
      JOptionPane.showMessageDialog(
          null, "Please choose 1 or 2 !", "ERROR!", JOptionPane.ERROR_MESSAGE);
      option =
          Integer.parseInt(
              JOptionPane.showInputDialog(
                  "Choose the operation \n 1 - Average \n 2 - Rounded Average"));
    }
    switch (option) {
      case 1:
        JOptionPane.showMessageDialog(null, "Average: " + average);
        break;
      case 2:
        JOptionPane.showMessageDialog(null, "Rounded Average: " + rounded);
        break;
    }
  }
Exemplo n.º 2
0
  public static void main(String[] args) throws IOException {
    String term =
        JOptionPane.showInputDialog(
            "Welcome to our knock-off search engine! \nPlease enter a term to search:");
    while (term == null || term.isEmpty()) {
      term =
          JOptionPane.showInputDialog(
              "You didn't input anything! \nPlease enter a term to search: ");
    }
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    System.out.println("Establishing connection...");

    // Get the connection.
    DB db = mongoClient.getDB("crawler");
    DBCollection table = db.getCollection("urlpages");

    System.out.println("Connected to MongoDB!");
    db.getCollection("pagerank").drop();

    Ranking ranker = new Ranking(db);
    ranker.link_analysis();
    ranker.TFIDF(term);

    run(term, db);

    JOptionPane.showMessageDialog(
        null,
        "Search is completed! \nPlease refer to 'C:\\data\\search_results.json' for the result.");
  }
 public void actionPerformed(ActionEvent event) {
   int i;
   JButton aux = (JButton) event.getSource();
   if (aux == closeCompra) {
     try {
       String[] information = {
         JOptionPane.showInputDialog(null, "nombre"),
         JOptionPane.showInputDialog(null, "numero de targeta")
       };
       ObjectOutputStream oos = new ObjectOutputStream(client.getOutputStream());
       oos.writeObject(information);
       oos.flush();
       oos.writeObject(products);
       oos.flush();
       oos.writeObject(comprados);
       oos.flush();
       cleanTable();
       comprados.clear();
     } catch (Exception e) {
       System.out.print("\nerror al cerrar la compra " + e.getMessage());
     }
     return;
   }
   for (i = 0; aux != mostrador.addCar[i]; i++) {;
   }
   if (products.get(i).getPiesas() > 0) {
     products.get(i).popParts();
     addCompra(products.get(i));
     total.setText("total: " + comprados.getLast().getTotal());
   } else {
     JOptionPane.showMessageDialog(null, "no seas menso ya no hay mas piesas! :@");
   }
 }
 public static void main(String[] args) {
   int guess = 0;
   int result;
   String msg;
   int attempts = 1;
   final int LOW = 1;
   final int HIGH = 10;
   boolean ok = false;
   result = LOW + (int) (Math.random() * HIGH);
   while (!ok) {
     try {
       guess =
           Integer.parseInt(
               JOptionPane.showInputDialog(
                   null, "Try to guess my number between " + LOW + " and " + HIGH));
       ok = true;
     } catch (NumberFormatException e) {
       JOptionPane.showMessageDialog(null, "Input must be a number");
       ok = false;
     }
   }
   while (guess != result) {
     if (guess < result) msg = "Your guess was too low";
     else msg = "Your guess was too high";
     guess = Integer.parseInt(JOptionPane.showInputDialog(null, msg + "\nGuess again"));
     ++attempts;
   }
   JOptionPane.showMessageDialog(null, "Correct! You got it in " + attempts + " attempts");
 }
Exemplo n.º 5
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // TODO code application logic here
    String input;
    input = "";
    input =
        JOptionPane.showInputDialog(
            "Enter what you want to be in the stack array!\nIt will be seperated by space\nexit will close the program");

    while (!"exit".equals(input)) {
      Stack<Integer> myStack = new Stack();
      if (input.equals("drop")) {
        myStack.pop();
      }
      String[] inputValue = input.split(" ");
      for (String string : inputValue) {
        try {
          myStack.add(Integer.parseInt(string));
        } catch (Exception e) {
          System.out.println(e.getLocalizedMessage());
        }
      }
      System.out.println(myStack);
      input = JOptionPane.showInputDialog("Enter another stack");
    }

    System.out.println("You have exited the program!");
  }
Exemplo n.º 6
0
  public void MenuValidacao() {

    while (op != 3) {
      op =
          Integer.parseInt(
              JOptionPane.showInputDialog(
                  "1 - Entre com Nro da conta \n2 - Insira a Senha\n 3 - Logar "));
      switch (op) {
        case 1:
          contnumber = Integer.parseInt(JOptionPane.showInputDialog("Digite a conta "));

          break;
        case 2:
          pass = Integer.parseInt(JOptionPane.showInputDialog("Digite a senha "));
          break;

        case 3:
          break;

        default:
          JOptionPane.showMessageDialog(null, "Opcao Invalida");
          break;
      }
    }

    if (c.ValidaConta(contnumber, pass)) {

      MenuCaixa();
    } else {
      JOptionPane.showMessageDialog(null, "Conta ou senha inexistente");
    }
  }
Exemplo n.º 7
0
  public static void main(String args[]) {
    Manager2 m1, m2;
    String fname = JOptionPane.showInputDialog("First name: ");
    String sname = JOptionPane.showInputDialog("Surname: ");
    boolean valid = false;

    while (!valid) {
      try {
        double salary =
            Double.parseDouble(JOptionPane.showInputDialog("Weekly Salary: must be at least 600"));
        m2 = new Manager2(fname, sname, salary);
        JOptionPane.showMessageDialog(
            null,
            "Manager2 created successfully:\n "
                + m2.toString()
                + " and salary is "
                + m2.earnings());
        valid = true;
      } catch (NumberFormatException e) {
        JOptionPane.showMessageDialog(null, "Salary must be a number");
      } catch (IllegalArgumentException e) {
        JOptionPane.showMessageDialog(null, e.getMessage());
        System.out.print(e.getMessage());
      }
    }
  }
Exemplo n.º 8
0
  public static void main(String[] args) {

    String rate =
        JOptionPane.showInputDialog(
            null, "Please a desired exchange rate between Dollars(US) and Euros: ");

    double userRate = Double.parseDouble(rate);

    Converter userConverter = new Converter(userRate);

    boolean completed = false;
    while (!completed) {
      String input =
          JOptionPane.showInputDialog(
              null, "Please enter the amount in US$ to be converted (Q to quit): ");

      if (input.equalsIgnoreCase("Q")) completed = true;
      else {
        double amount = Double.parseDouble(input);

        if (amount > 0) {
          double Coinexchange = userConverter.convert(amount);
          JOptionPane.showMessageDialog(
              null, "The conversion to Euro is: " + Coinexchange + " Euro");
        } else completed = true;
      }
    }
  }
Exemplo n.º 9
0
  public static void main(String[] args) {
    int n = -1;
    boolean goodInput = false; // flag variable

    // priming read
    String s = JOptionPane.showInputDialog(null, "Enter an integer larger than 0:");
    while (!goodInput) {
      if (s == null) // Test for User Pressing Cancel/Close
      goodInput = true;

      // Exception Handle: Number smaller than 0; second due to exception handle of the following S
      // overwriting cancel.
      if (n < 1 && n != -1)
        s =
            JOptionPane.showInputDialog(
                null, s + " is not Greater than 0. " + "Enter an new number:");

      // Exception Handle: Improper Input
      try {
        // attempt to convert the String to an int
        n = Integer.parseInt(s);
        // System.out.println("\nN is value: " + n);
        if (n > -1) goodInput = true; // Catch n being parsed correctly

      } catch (NumberFormatException nfe) {
        if (s != null) // If null wasn't pressed ask for correct input:
        s = JOptionPane.showInputDialog(null, " Incorrect input: " + s + " Enter an new number:");
      }
    }
    if (n < 0) { // User Canceled/Closed
      JOptionPane.showMessageDialog(null, "Thanks for using the Program!");
    } else { // Normal Close
      JOptionPane.showMessageDialog(null, "The integer is: " + n);
    }
  }
Exemplo n.º 10
0
 @Action
 public void addItem() {
   String item = JOptionPane.showInputDialog("Item : ");
   String amount = JOptionPane.showInputDialog("Amount : ");
   PrintDemon.getInstance().reciepts.add(new String[] {item, amount});
   populateTable();
 }
  public static int cadastrarProduto(Produto p[], int c) {
    int tipo;
    do {
      tipo =
          Integer.parseInt(
              JOptionPane.showInputDialog(
                  "1- para cadastrar Remedio " + "ou 2- para cadastrar produto de Higiene"));
    } while (tipo != 1 && tipo != 2);

    if (tipo == 1) {
      Remedio auxiliar = new Remedio();
      auxiliar.setCodigo(c + 1);
      auxiliar.setDescricao(JOptionPane.showInputDialog("Digite descricao do produto"));
      auxiliar.setPrecoDeCompra(
          Float.parseFloat(
              JOptionPane.showInputDialog("Digite o preco de " + "compra do produto")));
      auxiliar.definirPercentualDeLucro();
      JOptionPane.showMessageDialog(null, "Preco de Venda = " + auxiliar.gerarPrecoDeVenda());
      p[c] = auxiliar;
    } else {
      Higiene auxiliar = new Higiene();
      auxiliar.setCodigo(c + 1);
      auxiliar.setDescricao(JOptionPane.showInputDialog("Digite descricao do produto"));
      auxiliar.setPrecoDeCompra(
          Float.parseFloat(
              JOptionPane.showInputDialog("Digite o preco de " + "compra do produto")));
      auxiliar.setPercentualDeLucro(30);
      JOptionPane.showMessageDialog(null, "Preco de Venda = " + auxiliar.gerarPrecoDeVenda());
      p[c] = auxiliar;
    }
    c++;
    return c;
  }
public class RestaurantBill implements TipData {

  private double tip;

  private double billAmount =
      Double.parseDouble(JOptionPane.showInputDialog("What is the restaurant bill amount"));
  private int serviceRating =
      Integer.parseInt(
          JOptionPane.showInputDialog(
              "How was the service?\n 1 =  Excellent\n 2 = good\n 3= average \n 4 = shitty"));

  public double calculateTipOutput() {
    if (this.serviceRating == 1) {
      this.tip = (.20 * this.billAmount);
    } else if (this.serviceRating == 2) {
      this.tip = (.15 * this.billAmount);
    } else if (this.serviceRating == 3) {
      this.tip = (.07 * this.billAmount);
    } else if (this.serviceRating == 4) {
      this.tip = (.01 * this.billAmount);
    }

    return this.tip;
  }
}
Exemplo n.º 13
0
  public static void main(String[] args) {
    int in, cost, out, scost;
    String nin, soda;
    nin = JOptionPane.showInputDialog("Enter Money");
    in = Integer.parseInt(nin);
    soda = JOptionPane.showInputDialog("(1) Soda 2$, (2) Water 1$");
    scost = Integer.parseInt(soda);
    switch (scost) {
      case 1:
        cost = 2;
        break;
      case 2:
        cost = 1;
        break;
      default:
        cost = 0;
        break;
    }

    out = in - cost;
    if (out >= 0) {
      System.out.print("Change = " + out);
    } else {
      System.out.print("Error, Not enough money");
    }
    System.exit(0);
  }
Exemplo n.º 14
0
 public static void main(String[] args) {
   Boolean checktrue = true;
   int topnumber = 0;
   while (checktrue) {
     String topNumber = "";
     topNumber = JOptionPane.showInputDialog("How many customers are there?");
     topnumber = Integer.parseInt(topNumber);
     if (topnumber >= 1) checktrue = false;
     else
       JOptionPane.showMessageDialog(
           null, "You have entered an invalid number, please try again.");
   }
   Customer customerz[] = new Customer[topnumber + 1];
   int i = 1;
   while (!checktrue) {
     String State = "";
     customerz[i] = new Customer();
     customerz[i].name = JOptionPane.showInputDialog("Hello customer, what is your name?");
     State = JOptionPane.showInputDialog("Press 1 if you live in PA or 2 if you do not");
     customerz[i].state = Integer.parseInt(State);
     System.out.println(
         "Hello " + customerz[i].name + " , Welcome to Final Frontier Online Store");
     System.out.println("Please take a look at our quality goods below:");
     customerz[i].ChoiceSystem();
     if (i >= topnumber) checktrue = true;
     i++;
   }
 }
Exemplo n.º 15
0
  public void MenuCliente() {
    cli = new Cliente();
    while (op != 4) {

      op =
          Integer.parseInt(
              JOptionPane.showInputDialog("1 - CPF \n2 - Conta\n 3 - Senha \n 4 - Finalizar "));
      switch (op) {
        case 1:
          a = Double.parseDouble(JOptionPane.showInputDialog("Digite o cpf "));
          cli.setCpf(a);

          break;
        case 2:
          contnumber = Integer.parseInt(JOptionPane.showInputDialog("Digite a conta "));
          cli.setPassword(contnumber);

          break;
        case 3:
          pass = Integer.parseInt(JOptionPane.showInputDialog("Digite a senha "));
          cli.setId(pass);

          break;

        case 4:
          break;
        default:
          JOptionPane.showMessageDialog(null, "Opcao Invalida");
          break;
      }
    }

    c = new Conta(cli, 100);
  }
Exemplo n.º 16
0
  public void init() { // a grid to layout the screen nicely
    JLabel title = new JLabel("THE GAME OF NIM!");
    title.setFont(new Font("Times New Roman", Font.PLAIN, 48));
    Panel p = new Panel();
    resize(500, 100);
    // declare a new array of buttons
    a = new JButton[row];
    // initialize each of the buttons in the array
    // with an empty label
    for (int nNum = 0; nNum < row; nNum++) {
      a[nNum] = new JButton("8");
      p.add(a[nNum]);
      // each button will have an action listener
      a[nNum].addActionListener(this);
      a[nNum].setBackground(Color.yellow);
      // each button will send a message with its number
      a[nNum].setActionCommand("" + nNum);
    }

    name = JOptionPane.showInputDialog("Enter name Player 1: ");
    name2 = JOptionPane.showInputDialog("Enter name Player 2:  ");

    JButton reset = new JButton("Reset");
    reset.addActionListener(this);
    reset.setActionCommand("re");

    status = new JLabel("Welcome! The player to remove the final stones is the loser!");
    add(title);
    add(status);
    add(p);
    add(reset);
  }
Exemplo n.º 17
0
  public void MenuCaixa() {

    while (op != 4) {
      op =
          Integer.parseInt(
              JOptionPane.showInputDialog("1 - Sacar\n2 - Depositar\n3 - Saldo\n4 - Sair"));
      switch (op) {
        case 1:
          a = Double.parseDouble(JOptionPane.showInputDialog("Digite o valor " + "a ser Sacado:"));
          c.sacar(a);
          break;
        case 2:
          a =
              Double.parseDouble(
                  JOptionPane.showInputDialog("Digite o Valor a Ser " + "Depositado: "));
          c.depositar(a);
          break;
        case 3:
          JOptionPane.showMessageDialog(null, "Seu Saldo é: " + c.getSaldo());
          break;
        case 4:
          break;

        default:
          JOptionPane.showMessageDialog(null, "Opcao Invalida");
          break;
      }
    }
  }
Exemplo n.º 18
0
  // program uses JOptionPane
  public static void main(String[] args) {
    // obtain user input from JOptionPane input dialogs
    String firstNumber = JOptionPane.showInputDialog("Enter first integer");
    String secondNumber = JOptionPane.showInputDialog("Enter second integer");
    String operation = JOptionPane.showInputDialog("Enter the operation");

    // convert String inputs to int values for use in a calculation
    int number1 = Integer.parseInt(firstNumber);
    int number2 = Integer.parseInt(secondNumber);
    int result = 0;
    switch (operation) {
      case "+":
        result = number1 + number2;
        break; // add numbers
      case "*":
        result = number1 * number2;
        break;
      case "/":
        result = number1 / number2;
        break;
      case "%":
        result = number1 % number2;
        break;
      default:
        System.out.println("erro");
    }

    // display result in a JOptionPane message dialog
    JOptionPane.showMessageDialog(
        null, "The Result is " + result, "Result of Two Integers", JOptionPane.PLAIN_MESSAGE);
  } // end method main
Exemplo n.º 19
0
  public static void main(String[] args) {
    JOptionPane.showMessageDialog(
        null,
        "The object of this game is to get the number 21. Anything over 21, is a bust. Anything below is acceptable, but the goal is 21.");
    int card = new Random().nextInt(20) + 1;
    int hit = new Random().nextInt(10);
    JOptionPane.showMessageDialog(null, "YOU got " + card);
    int hat =
        JOptionPane.showConfirmDialog(null, "Do you want a HIT?", "", JOptionPane.YES_NO_OPTION);
    if (JOptionPane.YES_OPTION == hat) {
      while (JOptionPane.YES_OPTION == hat) {
        hit = new Random().nextInt(10);
        card += hit;
        JOptionPane.showMessageDialog(null, "YOU got " + card);
        JOptionPane.showConfirmDialog(
            null, "Do you want a HIT AGAIN?", "", JOptionPane.YES_NO_OPTION);
        int lat =
            JOptionPane.showConfirmDialog(
                null, "Do you want a HIT?", "", JOptionPane.YES_NO_OPTION);
        if (card > 21) {
          JOptionPane.showMessageDialog(null, "BUST!!!");
        } else if (JOptionPane.NO_OPTION == hat) {

          String stand = JOptionPane.showInputDialog(null, "In the end, YOU got " + card);
        }
      }
    } else if (card > 21) {
      JOptionPane.showMessageDialog(null, "BUST!!!");
    } else if (card <= 21) {
      String stand = JOptionPane.showInputDialog(null, "In the end, YOU got " + card);
      JOptionPane.showMessageDialog(null, "OK!!!");
    }
  }
  public static void main(String[] args) throws Excecoes {

    String strCargo = null, strNivel = null;
    double dblSalario = 0;
    int resp = 0;

    try {

      while (resp == 0) {

        strCargo = JOptionPane.showInputDialog("Digite o cargo");
        strNivel = JOptionPane.showInputDialog("Digite o nível");
        dblSalario = Double.parseDouble(JOptionPane.showInputDialog("Digite o Salário"));
        Cargo c = new Cargo(strCargo, strNivel, dblSalario);
        System.out.println(new CargoDAO().gravar(strCargo, strNivel, dblSalario));

        resp =
            JOptionPane.showConfirmDialog(
                null,
                "Continuar Cadastrando?",
                "Camadas",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE);
      }

    } catch (Exception e) {
      throw new Excecoes(e);
    }
  }
Exemplo n.º 21
0
  public static void main(String[] args) {

    int num1 = Integer.parseInt(JOptionPane.showInputDialog("Digite o primeiro numero: "));
    int num2 = Integer.parseInt(JOptionPane.showInputDialog("Digite o segundo numero:"));

    JOptionPane.showMessageDialog(null, "A soma e: " + (num1 + num2));
  }
Exemplo n.º 22
0
    public void actionPerformed(ActionEvent e) {
      if (shop != null & shop.getVideoTechnik().size() != 0) {
        try {
          if (butName.isSelected()) {
            String string = JOptionPane.showInputDialog(panel5, "Введите название");
            if (string.equals("")) {
            } else JOptionPane.showMessageDialog(panel5, shop.poisk(string, 1));
          } else if (butProizvod.isSelected()) {
            String string = JOptionPane.showInputDialog(panel5, "Введите производителя");
            if (string.equals("")) {
            } else JOptionPane.showMessageDialog(panel5, shop.poisk(string, 2));
          } else if (butPrice.isSelected()) {
            String string = JOptionPane.showInputDialog(panel5, "Введите цену");
            JOptionPane.showMessageDialog(panel5, shop.poisk(string, 3));
          } else if (butQuan.isSelected()) {
            String string = JOptionPane.showInputDialog(panel5, "Введите количество");
            JOptionPane.showMessageDialog(panel5, shop.poisk(string, 4));
          }
        } catch (NumberFormatException ee) {
        } catch (NullPointerException ex) {
        }

        butName.setSelected(false);
        butProizvod.setSelected(false);
        butPrice.setSelected(false);
        butQuan.setSelected(false);
        buttonPoisk.setEnabled(false);
      }
    }
Exemplo n.º 23
0
 public void actionPerformed(ActionEvent event) {
   if (typePanel.getSelection().equals("Confirm"))
     JOptionPane.showConfirmDialog(
         OptionDialogFrame.this,
         getMessage(),
         "Title",
         getType(optionTypePanel),
         getType(messageTypePanel));
   else if (typePanel.getSelection().equals("Input")) {
     if (inputPanel.getSelection().equals("Text field"))
       JOptionPane.showInputDialog(
           OptionDialogFrame.this, getMessage(), "Title", getType(messageTypePanel));
     else
       JOptionPane.showInputDialog(
           OptionDialogFrame.this,
           getMessage(),
           "Title",
           getType(messageTypePanel),
           null,
           new String[] {"Yellow", "Blue", "Red"},
           "Blue");
   } else if (typePanel.getSelection().equals("Message"))
     JOptionPane.showMessageDialog(
         OptionDialogFrame.this, getMessage(), "Title", getType(messageTypePanel));
   else if (typePanel.getSelection().equals("Option"))
     JOptionPane.showOptionDialog(
         OptionDialogFrame.this,
         getMessage(),
         "Title",
         getType(optionTypePanel),
         getType(messageTypePanel),
         null,
         getOptions(),
         getOptions()[0]);
 }
  public static void main(String[] args) {
    double salary; // Annual salary
    double yearsOnJob; // Years at current job
    String input; // To hold string input

    // Get the user's annual salary.
    input = JOptionPane.showInputDialog("Enter your " + "annual salary.");
    salary = Double.parseDouble(input);

    // Get the number of years at the current job.
    input = JOptionPane.showInputDialog("Enter the number of " + "years at your current job.");
    yearsOnJob = Double.parseDouble(input);

    // Determine whether the user qualifies for the loan.
    if (salary >= 30000) {
      if (yearsOnJob >= 2) {
        JOptionPane.showMessageDialog(null, "You qualify " + "for the loan.");
      } else {
        JOptionPane.showMessageDialog(
            null,
            "You must have " + "been on your current job for at least " + "two years to qualify.");
      }
    } else {
      JOptionPane.showMessageDialog(
          null, "You must earn " + "at least $30,000 per year to qualify.");
    }

    System.exit(0);
  }
Exemplo n.º 25
0
 public static void main(String[] args) {
   String input = JOptionPane.showInputDialog("Skriv inne en tekst.");
   String input2 = JOptionPane.showInputDialog("Skriv inne en tekst.");
   String utstreng = "";
   likString ls = new likString();
   boolean fortsett = (input.length() != 0 && input2.length() != 0);
   do {
     if (ls.delav(input, input2)) {
       utstreng =
           (input
               + "\n"
               + input2
               + "\n"
               + ls.delav(input, input2)
               + "\n"
               + "Streng B er en del av streng A");
     } else {
       utstreng =
           (input
               + "\n"
               + input2
               + "\n"
               + ls.delav(input, input2)
               + "\n"
               + "Streng B er IKKE en del av streng A");
     }
     JOptionPane.showMessageDialog(null, utstreng);
     input = JOptionPane.showInputDialog("Skriv inne en tekst.");
     input2 = JOptionPane.showInputDialog("Skriv inne en tekst.");
     fortsett = (input.length() != 0 && input2.length() != 0);
   } while (fortsett);
 }
Exemplo n.º 26
0
 public void actionPerformed(ActionEvent e) {
   String name = null;
   name =
       JOptionPane.showInputDialog(
           objUpdate.this,
           "Enter a name (eg. John Russell)",
           "Input Person",
           JOptionPane.QUESTION_MESSAGE);
   if (!(name == null)) {
     // prompt the user for a date
     String date = null;
     date =
         JOptionPane.showInputDialog(
             objUpdate.this,
             "Enter Date (eg. 06/17/1946)",
             "Input Person",
             JOptionPane.QUESTION_MESSAGE);
     if (!(date == null)) {
       // convert String to Date
       try {
         Date d = f.parse(date);
         p = new Person(name, d);
         persons.add(p);
         index = persons.lastIndexOf(p);
         displayRecord();
       } catch (ParseException ex) {
         JOptionPane.showMessageDialog(
             objUpdate.this, "Invalid date format!", "Input Error", JOptionPane.ERROR_MESSAGE);
       }
     }
   }
 }
Exemplo n.º 27
0
  public static void main(String[] args) {
    double n1;
    double n2;
    double n3;
    double sum;
    double average;

    String in, out;
    in = JOptionPane.showInputDialog("Enter the first number");
    n1 = Double.parseDouble(in);
    in = JOptionPane.showInputDialog("Enter the second number");
    n2 = Double.parseDouble(in);
    in = JOptionPane.showInputDialog("Enter the third number");
    n3 = Double.parseDouble(in);

    sum = n1 + n2 + n3;
    average = sum / 3;

    // Build the out String
    out = "";
    out = out + "The sum of " + n1 + "," + n2 + " and " + n3 + " is " + sum;
    out = out + "\nThe average of " + n1 + "," + n2 + " and " + n3 + " is " + average;

    JOptionPane.showMessageDialog(null, out);
    System.exit(0);
  }
Exemplo n.º 28
0
    public void actionPerformed(ActionEvent e) {
      try {
        String name = JOptionPane.showInputDialog("Enter the UserId:");
        String name1 = JOptionPane.showInputDialog("Enter the Password:"******"Enter the MobileNo:");
        // int name2=Integer.parseInt(name22);
        String name3 = JOptionPane.showInputDialog("Enter the DOB(dd/mm/yyyy):");
        DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
        Connection con =
            DriverManager.getConnection(
                "jdbc:oracle:thin:@localhost:1521:xe", "system", "9696030257");
        Statement st = con.createStatement();
        st.executeUpdate(
            "insert into database values('"
                + name
                + "','"
                + name1
                + "','"
                + name2
                + "','"
                + name3
                + "')");
        st.executeUpdate("commit");
        JOptionPane.showMessageDialog(
            null,
            "Hi !! Welcome in Our Database.Your userId is  < "
                + name
                + " > And Password is < ******* >");

      } catch (Exception ex) {
        System.out.print(ex);
        JOptionPane.showMessageDialog(null, "Please Fill All Entry OR choose another UsetId.");
      }
    }
  /** Hold a dialog with the user. */
  public void construyeDialogo() {
    String accion;

    accion =
        (String)
            JOptionPane.showInputDialog(
                null,
                "Selecciona una opción:\n",
                "Seleccion de acción",
                JOptionPane.PLAIN_MESSAGE,
                null,
                arrAcciones,
                "Propiedades");
    if (accion != null) {
      switch (accion) {
        case "Desicion":
          String nombre = JOptionPane.showInputDialog("Ingresa la desicion:");
          if (nombre != null) desicion = nombre;
          break;
        case "Propiedades":
          String mensaje = "Desicion:\n" + desicion + "\n";
          JOptionPane.showMessageDialog(null, mensaje);
          break;
      }
    }
  }
  public static void main(String args[]) {
    String rwString = JOptionPane.showInputDialog("Enter a number");
    String clString = JOptionPane.showInputDialog("Enter a number");
    int rw = Integer.parseInt(rwString);
    int cl = Integer.parseInt(clString);
    int i = 0;

    String[][] grid = new String[rw][cl];
    String[] letters =
        new String[] {
          "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
          "S", "T", "U", "V", "W", "X", "Y", "Z"
        };

    for (int row = 0; row < grid.length; row++) {
      for (int col = 0; col < grid.length; col++) {
        grid[row][col] = letters[i];
        System.out.print(grid[row][col] + "\t");
        i++;
        if (i == 26) {
          i -= 26;
        }
      }
      System.out.println("\n");
    }
  }