Products
Study Documents
AI Grader
AI Answer
AI Code Checker
Plagiarism Checker
AI Paraphraser
AI Quiz
AI Detector
Pricing
Blog
About Us
Get 7 Days Free Trial
Login
import javax.swing.JOptionPane; // Dialog box methods public
Verified
Added on  2023/04/08
|
2
|
267
|
54
AI Summary
Contribute Materials
Your contribution can guide someone’s learning journey. Share your documents today.
Contribute Now
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
;
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
💎 Get Pro
if
(
Typeshape
== 1.0)
{
test
= ((
Basewidth
* .5)
*
tall
);
/* Calculate
the
area if
the
object
is a
triangle*/
}
else
if
(
Typeshape
== 2.0)
{
test
= (
Basewidth
*
tall
);
/* Calculate
the
area if
the
object
is
a rectangle*/
}
else
{
test
= 0;
/*error
handling
*/
}
return
test
;
}
}
1 out of 2
Download
Related Documents
import java.util.Scanner; public class rectangle { private
|
2
|
241
|
184
View Document
Java Code import java.util.Scanner; /** * * File name
|
2
|
257
|
314
View Document
Workshop 2 CT619
|
11
|
1306
|
421
View Document
Shape Area Calculation System
|
9
|
1384
|
74
View Document
Rectangle Class in Java
|
7
|
1167
|
75
View Document
Rectangle Class Code
|
12
|
1173
|
295
View Document