triangle class
807600Sep 30 2007 — edited Sep 30 2007I am new to java and relatively new to programming so please bare with me.
I have to create a class with three instance variables for the sides of a triangle, a constructor method for assigning the values to the sides of the triangle. I have to use an instance method to determine the type of triangle created. My problam lies in the triangle class itself, not the test class. I don't know how to declare the class variable. I have to test this triangle class with a main method that prompts the user to enter three values and based on those values I want it to tell the user if the trianlge is "scalene", "isocelese" or "equalateral". Below is what I have:
public class triangle
{
//instance variables
int side1;
int side2;
int side3;
//class variable
static string triangletype;
//****************************************************************************
//this method expects three arguments and sets those values to the instance
//variables in that order
public void set_values(int a, int b, int c)
{
side1 = a;
side2 = b;
side3 = c;
}
//***************************************************************************
//Method to printout the values of the instnace variables
public void get_values()
{
System.out.println();
System.out.println("Side 1 is: " + side1);
System.out.println("Side 2 is: " + side2);
System.out.println("Side 3 is: " + side3);
}
//user defined constructor method that takes three arguments that set those values to the instance variable in the cooresponding order.
triangle(int x, int y, int z)
{
side1 = x;
side2 = y;
side3 = z;
}
//returns the type of triangle (instances of the triangle class) created
public static char get_triangletype()
{
return triangletype;
}
}