Created
November 27, 2017 09:02
-
-
Save kevinmungai/132906661acb64043c7dd7f34db84e2d to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package areacalculator; | |
import javax.swing.*; | |
/** | |
* | |
* @author kkmungai | |
*/ | |
public class AreaCalculator { | |
private double area; | |
/** | |
* @param args the command line arguments | |
*/ | |
public int getChoice() { | |
int choice = 0; | |
while (choice <= 0 || choice > 4) { | |
choice = Integer.parseInt(JOptionPane.showInputDialog("Enter \n1. Circle \n2. Rectangle \n3. Triangle \n4. Exit")); | |
} | |
return choice; | |
} | |
public double getInput(String neededInput) { | |
double s = Double.parseDouble(JOptionPane.showInputDialog(neededInput)); | |
return s; | |
} | |
private void displayResult(String output) { | |
JOptionPane.showMessageDialog(null ,output); | |
} | |
public static void main(String[] args) { | |
// TODO code application logic here | |
AreaCalculator myDemo = new AreaCalculator(); | |
int choice = myDemo.getChoice(); | |
if (choice == 1) { | |
double radius = myDemo.getInput("Enter the radius"); | |
myDemo.area = Math.Pi * radius * radius; | |
myDemo.displayResult("The area of the Circle is : " + myDemp.area); | |
} else if (choice == 2) { | |
double sidA = myDemo.getInput("Enter side a"); | |
double sidB = myDemo.getInput("Enter side b"); | |
dou | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment