Guest User

Untitled

a guest
Jun 17th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. public class Kreis {
  2.  
  3. // diese Eigenschaften hat der Kreis
  4. double x, y;
  5. double radius;
  6.  
  7. Kreis(double x, double y, double radius) {
  8.  
  9. this.x = x;
  10. this.y = y;
  11. this.radius = radius;
  12.  
  13. }
  14.  
  15. Kreis() {
  16.  
  17. }
  18.  
  19. public boolean equals(Object other) {
  20.  
  21. // wenn das selbe Objekt uebergeben wird ist jedenfalls true zurueckzugeben, falls das uebergebene Objekt nicht mal ein Kreis ist dann sicher false.
  22. if(other == this) {
  23. return true;
  24. }
  25. if(!(other instanceof Kreis)) {
  26. return false;
  27. }
  28.  
  29. // wir casten mal das uebergebene Objekt auf einen Kreis.
  30. Kreis kother = (Kreis) other;
  31. // und geben dann den logischen wert von folgenden Vergleich zurueck, der ist nur dann true wenn alles ( x,y,radius) gleich ist)
  32. return this.x == kother.x && this.y == kother.y && this.radius == kother.radius;
  33.  
  34. }
  35.  
  36.  
  37. double addieren(double... zahlen) {
  38. double summand = 0.0;
  39. int i = 0;
  40. while (i < zahlen.length) {
  41. summand += zahlen[i]; // ist das gleiche wie: summand = summand +
  42. // zahlen[i]
  43. i++;
  44. }
  45.  
  46. return summand;
  47.  
  48. }
  49.  
  50. double umfang(double radius) {
  51.  
  52. double umfang = 2 * Math.PI * radius;
  53. return umfang;
  54. }
  55.  
  56. double flaecheninhalt(double radius) {
  57.  
  58. double flaecheninhalt = Math.PI * radius * radius;
  59. return flaecheninhalt;
  60. }
  61.  
  62. double getRadius () {
  63. return radius;
  64. }
  65.  
  66. public static void main(String[] args) {
  67.  
  68. Kreis k1 = new Kreis(0.0, 0.0, 5.0);
  69. Kreis k2 = new Kreis(0.0, 0.0, 5.0);
  70. Kreis k3 = new Kreis(0.0, 1.0, 4.0);
  71.  
  72. if ( k1.equals(k2) ){
  73. System.out.println("Juhu wir sind gleich");
  74. }
  75.  
  76. else {
  77. System.out.println("Oje ungleich");
  78. }
  79.  
  80.  
  81. if ( k1.equals(k3) ){
  82. System.out.println("Juhu wir sind gleich");
  83. }
  84.  
  85. else {
  86. System.out.println("Oje ungleich");
  87. }
  88.  
  89. }
  90.  
  91. }
Add Comment
Please, Sign In to add comment