Created
May 15, 2013 13:59
-
-
Save gmfc/5584199 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import javax.swing.*; | |
| public class calculadora { | |
| static double x,y,resultado; | |
| static int opcao; | |
| public static void soma(){ | |
| resultado = x+y; | |
| } | |
| public static void subtracao(){ | |
| resultado = x-y; | |
| } | |
| public static void divisao(){ | |
| if(y == 0){ | |
| saida("Erro! Y não pode ser zero!"); | |
| }else{ | |
| resultado = x/y; | |
| } | |
| } | |
| public static void multiplicacao(){ | |
| resultado = x*y; | |
| } | |
| public static void saida(String saida){ | |
| JOptionPane.showMessageDialog(null,saida); | |
| } | |
| public static void main(String[] args) { | |
| saida("Calculadora! Algo bem simples..."); | |
| do{ | |
| saida("Nova conta!"); | |
| x = Double.parseDouble(JOptionPane.showInputDialog("Entre com o valor de X")); | |
| y = Double.parseDouble(JOptionPane.showInputDialog("Entre com o valor de Y")); | |
| opcao = Integer.parseInt(JOptionPane.showInputDialog("Escolha uma opção: \n\nAdição ---------- 1\nSubtração ------- 2\nDivisão --------- 3\nMultiplicação --- 4\n\nFechar ---------- 6\n")); | |
| do{ | |
| switch(opcao){ | |
| case 1: soma(); | |
| break; | |
| case 2: subtracao(); | |
| break; | |
| case 3: divisao(); | |
| break; | |
| case 4: multiplicacao(); | |
| default: | |
| } | |
| JOptionPane.showMessageDialog(null, resultado); | |
| opcao = 6; | |
| }while(opcao !=6); | |
| }while(opcao !=6); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment