Advertisement
gastaojunior

Exemplo modularização

Oct 9th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1.  
  2. import javax.swing.JOptionPane;
  3.  
  4. /*
  5.  * To change this template, choose Tools | Templates
  6.  * and open the template in the editor.
  7.  */
  8. /**
  9.  *
  10.  * @author gastao
  11.  */
  12. public class modularizacao1 {
  13.  
  14.     public static void main(String args[]) {
  15.         Integer res = Integer.parseInt(
  16.                 JOptionPane.showInputDialog("Escolha: \n 1.Somar \n 2.Subtrair \n 3.Multiplicar \n 4.Dividir"));
  17.  
  18.         Double v1 = pegarValor("Digite o primeiro valor");
  19.         Double v2 = pegarValor("Digite o segundo valor");
  20.  
  21.         switch (res) {
  22.             case 1:
  23.                 mostrarMsg(somar(v1, v2));
  24.                 break;
  25.             case 2:
  26.                 mostrarMsg(subtrair(v1, v2));
  27.                 break;
  28.             case 3:
  29.                 mostrarMsg(multiplicar(v1, v2));
  30.                 break;
  31.             case 4:
  32.                 mostrarMsg(dividir(v1, v2));
  33.                 break;
  34.         }
  35.        
  36.        
  37.     }
  38.  
  39.     static double pegarValor(String sMsg) {
  40.         return Double.parseDouble(JOptionPane.showInputDialog(sMsg));
  41.     }
  42.  
  43.     static void mostrarMsg(Double aValor) {
  44.         JOptionPane.showMessageDialog(null, "O valor é: " + aValor);
  45.     }
  46.  
  47.     static double somar(Double dV1, Double dV2) {
  48.         return (dV1 + dV2);
  49.     }
  50.  
  51.     static double subtrair(Double dV1, Double dV2) {
  52.         return (dV1 - dV2);
  53.     }
  54.  
  55.     static double multiplicar(Double dV1, Double dV2) {
  56.         return (dV1 * dV2);
  57.     }
  58.  
  59.     static double dividir(Double dV1, Double dV2) {
  60.         return (dV1 / dV2);
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement