// Input 5 required values and then calculate and display
// the inputted values, surface area and volume of the
// triangular prism. Calculate the base, then
// calculate the rectangles, then add these two together
// to get the grand total for the surface area.
import java.awt.*;
import hsa.Console;
public class TriangularPrism
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
double height;
double length;
double sideA;
double sideC;
double base;
double base2;
double rectangles = 0;
double grandTotal = 0;
double volume = 0;
c.print ("Enter the value of the base of the triangular prism: ");
base = c.readDouble ();
base2 = base; // base2 will store the input base
c.print ("Enter the value of the length of the triangular prism: ");
length = c.readDouble ();
c.print ("Enter the value of the height of the triangular prism: ");
height = c.readDouble ();
c.print ("Enter the value of side A of the triangular prism: ");
sideA = c.readDouble ();
c.print ("Enter the value of side C of the triangular prism: ");
sideC = c.readDouble ();
// display the inputted values
c.println ("You just inputted a base of " + base2
+ " a length of " + length + " a height of ");
c.println (height + " side A which is " + sideA
+ " and side C which is " + sideC + " (all in mm)");
// first, calculate the surface area of the triangular prism
// using 3 formulas: base = (base * length) / 2 (recalculated base)
// rectangles = sideA * height + base * height + sideC * height
// grandTotal = rectangles + base
base = (base2 * length) / 2;
rectangles = sideA * height + base * height + sideC * height;
grandTotal = rectangles + (2 * base);
// final output statement # 1
c.println (); // one blank line
c.println ("The surface area of the triangular prism with a "
+ "re-calculated base of " + base);
c.println ("a length of " + length + " a height of " + height
+ " side A which is " + sideA);
c.println ("and side C which is " + sideC
+ " is about: " + Math.round (grandTotal) + " mm sqrd");
// next, calculate the volume of the triangular prism
// using the formula: volume = (base2* length * height) / 2
volume = base2 * length * height;
// final output statement # 2
c.println ();
c.println ("The volume of the triangular prism with an "
+ "input base of " + base2);
c.println ("a length of " + length + " and a height of " + height);
c.println ("is about: " + Math.round (grandTotal) + " mm cubed");
} // main method
} // TriangularPrism class