Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author gastao
- */
- public class modularizacao1 {
- public static void main(String args[]) {
- Integer res = Integer.parseInt(
- JOptionPane.showInputDialog("Escolha: \n 1.Somar \n 2.Subtrair \n 3.Multiplicar \n 4.Dividir"));
- Double v1 = pegarValor("Digite o primeiro valor");
- Double v2 = pegarValor("Digite o segundo valor");
- switch (res) {
- case 1:
- mostrarMsg(somar(v1, v2));
- break;
- case 2:
- mostrarMsg(subtrair(v1, v2));
- break;
- case 3:
- mostrarMsg(multiplicar(v1, v2));
- break;
- case 4:
- mostrarMsg(dividir(v1, v2));
- break;
- }
- }
- static double pegarValor(String sMsg) {
- return Double.parseDouble(JOptionPane.showInputDialog(sMsg));
- }
- static void mostrarMsg(Double aValor) {
- JOptionPane.showMessageDialog(null, "O valor é: " + aValor);
- }
- static double somar(Double dV1, Double dV2) {
- return (dV1 + dV2);
- }
- static double subtrair(Double dV1, Double dV2) {
- return (dV1 - dV2);
- }
- static double multiplicar(Double dV1, Double dV2) {
- return (dV1 * dV2);
- }
- static double dividir(Double dV1, Double dV2) {
- return (dV1 / dV2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement