Simple Calculation Application
Virtual Position Forum :: Members Lounge :: Sciences & Knowledge :: Programing and Design :: Java Forum
Page 1 of 1 • Share
Simple Calculation Application
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); } } *********
Diya- Monstars
-
Posts : 364
Join date : 2011-02-08
Age : 33
Character sheet
Experience:
(10/500)
Similar topics
» Speed Mathematics ? Secret Skills for Quick Calculation
» Advice on getting a simple haircut
» RSS (Really Simple Syndication or Rich Site Summary)
» IT430 - Cryptography :VB6 APPLICATION:
» Application for Issuance of Certificate
» Advice on getting a simple haircut
» RSS (Really Simple Syndication or Rich Site Summary)
» IT430 - Cryptography :VB6 APPLICATION:
» Application for Issuance of Certificate
Virtual Position Forum :: Members Lounge :: Sciences & Knowledge :: Programing and Design :: Java Forum
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Yesterday at 12:21 pm by ali001
» Hemangiom'App
Tue Nov 05, 2024 11:25 am by ali001
» MindfulMe - Mental Health App
Mon Nov 04, 2024 10:50 am by ali001
» Learn Candlestick Patterns
Tue Oct 15, 2024 5:51 am by ali001
» Woh Pagal Si Episode 52 to 62 - Top Pakistani Drama
Sat Sep 21, 2024 6:26 pm by Mir Emmad Ali Khan Domki
» Nearu - share your socials
Sat Sep 21, 2024 1:12 pm by ali001
» Nightclub Tycoon: Idle Empire
Thu Sep 19, 2024 9:16 pm by ali001
» Carnivore - Meat Diet Recipes
Wed Sep 18, 2024 2:37 pm by ali001
» Eid Milad un Nabi Mubarak 2024 (Rabiʻ I 14, 1446 AH)
Tue Sep 17, 2024 3:44 pm by Mir Emmad Ali Khan Domki