Hey everyone. I am supposed to create a program that finds the area of a triangle...this i can do fine. My only problem is i was told that i need to use a get and set method to calculate the area. I dont exactly know how to use a get and set method with an object...would anybody show me how to do this or set me in the right direction? here is what i have, which works:
Main class:
public class TriMain {
public static void main(String[] args) {
TriObj myTriObj = new TriObj();
myTriObj.runIt();
}
}
Object:
import java.util.Scanner;
public class TriObj {
public void runIt()
{
Scanner input = new Scanner (System.in);
int base;
int height;
int area;
System.out.println("Enter base of triange: ");
base=input.nextInt();
System.out.println("Enter height of triange: ");
height=input.nextInt();
area=(base*height/2);
System.out.println("The area of the triangle is: "+ area);
}
}