Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Calculation Application
#1
I have studied 4 lectures upto now and then tried to write some sort of GUI based calculation only for +,-,x and / .. code of the file is below. It is working pretty well. but i intend to know if the method could be made more simple.. Help and suggestions are welcomed.. waiting for response. ******** import javax.swing.*; public class Testing3 { public static void main (String[] args) { for (int i=0; i<5; i++) { String value1 = JOptionPane.showInputDialog("Please Enter the First Number: "); int val1 = Integer.parseInt(value1); String option = JOptionPane.showInputDialog("Enter + , - , x , / "); String opt = "0"; if (option.equals("+")) {opt="1";} else if (option.equals("-")) {opt="2";} else if (option.equals("x")) {opt="3";} else if (option.equals("*")) {opt="3";} else if (option.equals("/")) {opt="4";} int operation = Integer.parseInt(opt); String value2 = JOptionPane.showInputDialog("Please Enter the Second Number: "); int val2 = Integer.parseInt(value2); switch(operation) { case 1: int Result = val1 + val2; JOptionPane.showMessageDialog(null, "Your sum is = "+Result); break; case 2: int Result1 = val1 - val2; JOptionPane.showMessageDialog(null, "Your Result is = "+Result1); break; case 3: int Result2 = val1 * val2; JOptionPane.showMessageDialog(null, "Your Prodcut is = "+Result2); break; case 4: int Result3 = val1 / val2; JOptionPane.showMessageDialog(null, "Your Result is = "+Result3); break; default: JOptionPane.showMessageDialog(null, "Wrong Choice"); } String choice = JOptionPane.showInputDialog("To continue calculation enter y or exit"); if (choice.equals("y")){i = 0;} else i = 5; } System.exit(0); } } *********
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error in Java Programming language: x64.exe not a valid Win32 application Xpert 0 1,674 06-24-2011, 07:52 AM
Last Post: Xpert
  Error inJava has discovered application components that could indicate a security con Xpert 0 1,123 06-24-2011, 07:43 AM
Last Post: Xpert
  How to start JavaDb(Derby) server from Java application 2011 Vuhelper 0 2,685 06-04-2011, 10:38 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)