Code:
import java.io.*;
import java.util.*;
public class triangletest
{
public static void main(String args[])
{
triangle theTriangle = new triangle();
theTriangle.setBase(4);
theTriangle.setHeight(2);
theTriangle.calculateArea();
theTriangle.printArea();
theTriangle.calculatePerimeter();
theTriangle.printPerimeter();
}
}
Code:
import java.io.*;
import java.util.*;
public class triangle
{
private double area;
private double base;
private double height;
private double perimeter;
public static void printInstructions()
{
System.out.println();
}
public void setBase(double theBase)
{
base = theBase;
}
public void setHeight(double theHeight)
{
height = theHeight;
}
public void calculateArea()
{
area = base *height * .5;
}
public void printArea()
{
System.out.println("The area is: " + area);
}
public void calculatePerimeter()
{
perimeter = height * 3;
}
public void printPerimeter()
{
System.out.println("The perimeter is: " + perimeter);
}
}
As you can see there are two different programs. One called triangletest and one called triangle. In triangletest notice how I hardcoded what the dimensions of the triangle were. Instead of that, and likely using the "Scanner" command, ask for and accept user input to use in my CalculatePerimeter/Area of my second code, triangle.
Guys know anything about this?


