Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package domein;
- public class Driehoek
- {
- private int a, b, c;
- // setters
- private void setA(int a)
- {
- /*
- if(a > 0)
- this.a = a;
- else
- this.a = 1;
- */
- this.a = (a > 0?a:1);
- }
- private void setB(int b)
- {
- this.b = (b > 0?b:1);
- }
- private void setC(int c)
- {
- this.c = (c > 0?c:1);
- }
- // constructor
- public Driehoek(int a, int b, int c)
- {
- this.setA(a);
- this.setB(b);
- this.setC(c);
- }
- // getters
- public int getA()
- {
- return this.a;
- }
- public int getB()
- {
- return this.b;
- }
- public int getC()
- {
- return this.c;
- }
- // andere methoden
- public boolean isRechthoekigeDriehoek()
- {
- if(a*a == b*b + c*c || b*b == a*a + c*c || c*c == a*a + b*b)
- return true;
- else
- return false;
- }
- }
- ----------
- package ui;
- import java.util.Scanner;
- import domein.Driehoek;
- public class DriehoekApplicatie
- {
- public static void main(String[] args)
- {
- int a, b, c, teller = 1;
- Scanner input = new Scanner(System.in);
- while(teller <= 3)
- {
- System.out.printf("Driehoek %d:%n", teller);
- System.out.print("Geef een geheel getal verschillend van 0 voor de eerste zijde: ");
- a = input.nextInt();
- System.out.print("Geef een geheel getal verschillend van 0 voor de tweede zijde: ");
- b = input.nextInt();
- System.out.print("Geef een geheel getal verschillend van 0 voor de derde zijde: ");
- c = input.nextInt();
- Driehoek dr = new Driehoek(a, b, c);
- boolean isRecht = dr.isRechthoekigeDriehoek();
- System.out.printf("De driehoek met de zijden %d, %d en %d is %s rechthoekige driehoek.%n%n", dr.getA(), dr.getB(), dr.getC(), (isRecht?"een":"geen"));
- teller++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement