// Input 3 required values and then calculate the perimeter and area
// and output the inputted and calculated values.
import java.awt.*;
import hsa.Console;
public class Parallelogram
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
int base;
int height;
int side;
int perimeter = 0;
int area = 0;
// prompt for and input the values required to calculate
// both the perimeter and area of a parallelogram
c.print ("Enter the value of the base of the parallelogram (in cm): ");
base = c.readInt ();
c.print ("Enter the value of the height of the parallelogram (in cm): ");
height = c.readInt ();
c.print ("Enter the value of one side of the parallelogram (in cm): ");
side = c.readInt ();
c.println (); // one blank line
c.println ("The 3 required values you've inputted are: ");
c.println ("base: " + base + " height: " + height + " and "
+ "side: " + side);
// first, calculate the perimeter of the parallelogram
// according to the formula: perimeter = 2 (base + side)
perimeter = 2 * (base + side);
// final output statement # 1
c.println ();
c.println ("The perimeter of the parallelogram is: " + perimeter + " cm");
// next, calculate the area of the parallelogram
// acocrding to the formula: area = base * height
area = base * height;
// final output statement # 2
c.println ();
c.println ("The area of the parallelogram is: " + area + " cm");
} // main method
} // Parallelogram class
No comments:
Post a Comment