I am writing a java program where that calculates the area and perimeter for a rectangle, square, circle and triangle. The user enters the length and width for the rectangle, the sides for the square, radius for the circle, base and height for the triangle, and it will output 4 windows displaying the area and perimeter for each shape
I have got it working for the area and perimeter of a rectangle, but I cant get it to work for the others since for the square it gives the same value I enter in, any help would be appreciated
/**
* @(#)RectangleArea.java
*
*
* @author
* @version 1.00 2011/1/28
*/
import javax.swing.JOptionPane;
public class RectangleArea {
static String a,b,c,d;
static int length;
static int width;
static int area;
static int SquareSide;
static int SquareArea;
static int RectPerim;
static int CirlceArea;
static int Radius;
public static int calculation() {
area = length *width;
RectPerim = length + length +width +width;
SquareArea= SquareSide * SquareSide;
CirlceArea = Radius * Radius * 3.14;
return area; return CirlceArea ;
}
public static int SquareCalculation(){
SquareArea= SquareSide * SquareSide;
return SquareArea;
}
public static void main(String args[]) {
calculation();
a= JOptionPane.showInputDialog ("Enter Width");
b= JOptionPane.showInputDialog( "Enter length");
d= JOptionPane.showInputDialog( "Enter SquareSide");
c= JOptionPane.showInputDialog( "Enter Radius");
calculation();
length = Integer.parseInt( a );
width = Integer.parseInt( b );
SquareArea = Integer.parseInt( c );
Radius = Integer.parseInt( d );
calculation();
JOptionPane.showMessageDialog(null,"Area of rectangle is "+ area);
JOptionPane.showMessageDialog(null,"Perimeter of rectangle is "+ RectPerim);
JOptionPane.showMessageDialog(null,"Area of circle is "+ CirlceArea);
JOptionPane.showMessageDialog(null,"Area of Square is "+ SquareArea);
}
}