Exercice3: Ecrivez un programme Geometrie qui permet à l'utilisateur d'entrer les coordonnées (x, y) des sommets d'un triangle. Le programme affiche ensuite le périmètre du triangle ainsi qu'un message indiquant s'il s'agit d'un triangle isocèle. Votre programme doit être orienté objet.
/**
*
*/
package tp2;
/**
* @author pirate
*
*/
public class Point {
float x;
float y;
public Point(float x, float y) {
super();
this.x = x;
this.y = y;
}
public float getX() {
return x;
}
public void setX(float x) {
this.x = x;
}
public float getY() {
return y;
}
public void setY(float y) {
this.y = y;
}
public Point() {
this.x=0;
this.y=0;
}
public double distance(Point point1,Point point2){
double n=Math.sqrt(Math.pow(Math.abs(point1.x-point2.x),2)+Math.pow(Math.abs(point1.y-point2.y),2));
return n;
}
}
*
*/
package tp2;
/**
* @author pirate
*
*/
public class Point {
float x;
float y;
public Point(float x, float y) {
super();
this.x = x;
this.y = y;
}
public float getX() {
return x;
}
public void setX(float x) {
this.x = x;
}
public float getY() {
return y;
}
public void setY(float y) {
this.y = y;
}
public Point() {
this.x=0;
this.y=0;
}
public double distance(Point point1,Point point2){
double n=Math.sqrt(Math.pow(Math.abs(point1.x-point2.x),2)+Math.pow(Math.abs(point1.y-point2.y),2));
return n;
}
}
package tp2;
import java.util.Scanner;
import tp2.Point;
public class triangle {
Point p1,p2,p3;
public Point getP1() {
return p1;
}
public void setP1(Point p1) {
this.p1 = p1;
}
public Point getP2() {
return p2;
}
public void setP2(Point p2) {
this.p2 = p2;
}
public Point getP3() {
return p3;
}
public void setP3(Point p3) {
this.p3 = p3;
}
public triangle(Point p1, Point p2, Point p3) {
super();
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
}
public triangle() {
}
public double distance(Point point1,Point point2){
double n=Math.sqrt(Math.pow((point1.x-point2.x),2)+Math.pow((point1.y-point2.y),2));
return n;
}
public boolean isIsocele(){
System.out.println(distance(this.p1,this.p2)+"+"+distance(this.p1,this.p3));
return distance(this.p1,this.p2)==distance(this.p1,this.p3) | distance(this.p1,this.p2)==distance(this.p2,this.p3);
}
public static void main(String[] args){
Scanner sc =new Scanner(System.in);
Point point1=new Point(0,0);
Point point2=new Point(2,4);
Point point3=new Point(0,0);
triangle tr=new triangle(point1,point2,point3);
System.out.println(tr.isIsocele());
}
}
Commentaires
Enregistrer un commentaire