logo

import javax.swing.JOptionPane; // Dialog box methods public

   

Added on  2023-04-08

2 Pages267 Words54 Views
import javax.swing.JOptionPane; // Dialog box methods
public class rectangle {
public static void main(String[] args)
{
double shape = InputDouble("Area of \n 1. Triangle \n 2.
Retangle"); /* User choice for shape*/
double width = InputDouble("Enter Width"); /* user value for
width */
double height = InputDouble("Enter Height"); /* user value for
height */
double shapearea = calculatearea(width, height, shape); /*
variable to store the value of the calculated area */
if (shapearea == 0) /* value returned if width/height was entered
as 0 or triangle/rectangle was not selected 8 */
{
JOptionPane.showMessageDialog(null, "The value entered was
incorrect \n Please re assess the entered criteria"); /* Display warning
message */
}
else if (shapearea < 0) /* value is a negative number was entered
for dimension */
{
JOptionPane.showMessageDialog(null, "A negative value has
been entered. An area can never be negative. Please try again"); /* Display
warning message */
}
else {JOptionPane.showMessageDialog(null, "The area is"
+ shapearea);} /* Return the area of the shape*/
System.exit(0); // Terminate program
}
public static double InputDouble(String prompt)
{
/* Get data in string form: convert to double */
String s = JOptionPane.showInputDialog(prompt);
return Double.parseDouble(s);
}
public static double calculatearea(double Basewidth, double tall,
double Typeshape )
{
/* Calculates the area */
double test;
import javax.swing.JOptionPane; // Dialog box methods public_1

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
import java.util.Scanner; public class rectangle { private
|2
|241
|184

Java Code import java.util.Scanner; /** * * File name
|2
|257
|314

Workshop 2 CT619
|11
|1306
|421

Assignment on Python Programming
|9
|1384
|74

Rectangle Class in Java
|7
|1167
|75

Rectangle Class Code
|12
|1173
|295