Вы находитесь на странице: 1из 2

package swing.

intro;
import javax.swing.JOptionPane;
public class SwingIntro {
public static void areaTriangle double base! double "eig"t# { $$%reated met"ods &or t"e area o& eac"
s"ape "ere. JOptionPane used to displa' result
double answerTri ( ).*+base+"eig"t#;
JOptionPane.s"ow,essage-ialognull! .T"e area o& t"e triangle is . / answerTri#;
0

public static void area%ircle int radius#{
double answer%ir ( ,at".PI#+double# ,at".powradius!1###;
JOptionPane.s"ow,essage-ialognull! .T"e area o& t"e circle is . / answer%ir#;
0

public static void area2ectangle int lengt"! int widt"#{
double answer2ec ( double#lengt"+widt"##;
JOptionPane.s"ow,essage-ialognull! .T"e area o& t"e rectangle is . / answer2ec#;

0
public static void calc3rea#{
double base! "eig"t! answer! tri3rea;
int x! radius! lengt"! widt";
$$ -eclaring variables "ere. 4sing JOptionPane to prompt user &or input.


String inputs"ape ( JOptionPane.s"owInput-ialog.5ould 'ou like to &ind t"e area o& a
trianglepress 6#! circlepress 1#! rectanglepress 7# or nonepress )#.#;
x ( Integer.parseIntinputs"ape#;
i& x (( 6#{
String inputbase ( JOptionPane.s"owInput-ialog.5"at is t"e base o& t"e triangle8.#;
base ( -ouble.parse-oubleinputbase#;
String input"eig"t ( JOptionPane.s"owInput-ialog.5"at is t"e "eig"t o& t"e triangle8.#;
"eig"t ( -ouble.parse-oubleinput"eig"t#;
areaTriangle base! "eig"t#;


0
i& x (( 1#{
String inputradius ( JOptionPane.s"owInput-ialog.5"at is t"e radius o& t"e circle8.#;
radius ( Integer.parseIntinputradius#;
area%ircle radius#;
0
i& x (( 7#{
String inputlengt" ( JOptionPane.s"owInput-ialog.5"at is t"e lengt" o& t"e rectangle8.#;
lengt" ( Integer.parseIntinputlengt"#;
String inputwidt" ( JOptionPane.s"owInput-ialog.5"at is t"e widt" o& t"e rectangle8.#;
widt" ( Integer.parseIntinputwidt"#;
area2ectangle lengt"! widt"#;
0
i& x (( )#{
return;
0


0



public static void mainString9: args# {
calc3rea #;

Вам также может понравиться