Advertisement
Guest User

driehoek koekoek

a guest
Oct 17th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. package domein;
  2.  
  3. public class Driehoek
  4. {
  5. private int a, b, c;
  6.  
  7. // setters
  8. private void setA(int a)
  9. {
  10. /*
  11. if(a > 0)
  12. this.a = a;
  13. else
  14. this.a = 1;
  15. */
  16.  
  17. this.a = (a > 0?a:1);
  18. }
  19.  
  20. private void setB(int b)
  21. {
  22. this.b = (b > 0?b:1);
  23. }
  24.  
  25. private void setC(int c)
  26. {
  27. this.c = (c > 0?c:1);
  28. }
  29.  
  30. // constructor
  31. public Driehoek(int a, int b, int c)
  32. {
  33. this.setA(a);
  34. this.setB(b);
  35. this.setC(c);
  36. }
  37.  
  38. // getters
  39. public int getA()
  40. {
  41. return this.a;
  42. }
  43.  
  44. public int getB()
  45. {
  46. return this.b;
  47. }
  48.  
  49. public int getC()
  50. {
  51. return this.c;
  52. }
  53.  
  54. // andere methoden
  55. public boolean isRechthoekigeDriehoek()
  56. {
  57. if(a*a == b*b + c*c || b*b == a*a + c*c || c*c == a*a + b*b)
  58. return true;
  59. else
  60. return false;
  61. }
  62.  
  63. }
  64.  
  65. ----------
  66.  
  67. package ui;
  68.  
  69. import java.util.Scanner;
  70.  
  71. import domein.Driehoek;
  72.  
  73. public class DriehoekApplicatie
  74. {
  75.  
  76. public static void main(String[] args)
  77. {
  78. int a, b, c, teller = 1;
  79. Scanner input = new Scanner(System.in);
  80.  
  81. while(teller <= 3)
  82. {
  83. System.out.printf("Driehoek %d:%n", teller);
  84. System.out.print("Geef een geheel getal verschillend van 0 voor de eerste zijde: ");
  85. a = input.nextInt();
  86. System.out.print("Geef een geheel getal verschillend van 0 voor de tweede zijde: ");
  87. b = input.nextInt();
  88. System.out.print("Geef een geheel getal verschillend van 0 voor de derde zijde: ");
  89. c = input.nextInt();
  90.  
  91. Driehoek dr = new Driehoek(a, b, c);
  92. boolean isRecht = dr.isRechthoekigeDriehoek();
  93.  
  94. 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"));
  95.  
  96. teller++;
  97. }
  98.  
  99. }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement