hi
i write code that is mesure the area of traingle
with two constructor ... with argument and default constructor
and set ,, get , high and length ,,
and tostring , equals methods
but i think is there a logical error
class file
public class Traingle {
private int length;
private int high;
public Traingle (){
length=10;
high=11;
}
public Traingle (int l,int w){
length=l;
high=w;
}
public void setLength(int l){
length=l;
}
public void setHigh(int w){
high=w;
}
public int getLength()
{
return length;
}
public int getHigh()
{
return high;
}
public boolean equals(Traingle obj){
return((length==obj.length)&&(high==obj.high));
}
public String toString(){
return "("+length+","+high+")";
}
public int areaTringle( ){
int area=0;
area=(high*length)/2;
return area;
}
}
main
public class Test{
public static void main(String [] args){
Traingle o=new Traingle ();
System.out.print(o);
System.out.println();
System.out.print("area is "+o.areaTringle());
Traingle pos =new Traingle ();
if(o.equals(pos))
System.out.println("\n are equals");
else
System.out.println("not equals");
}
}
and what os the copy constructor ,how i can writed ,
and if you can explain equals method how its work ..