Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Delta {
  4.  
  5. double a, b, c;
  6.  
  7.  
  8. public Delta(double a, double b, double c) {
  9. this.a = a;
  10. this.b = b;
  11. this.c = c;
  12. System.out.println("\nA = " + a + "\nB = " + b + "\nC = " + c);
  13. }
  14.  
  15.  
  16. public double obliczY(double x) {
  17. System.out.println("\nJestem funkcją obliczY");
  18. double wartoscDlaY;
  19. wartoscDlaY = (a * (x * x)) + (b * x) + c;
  20. System.out.println("Wartość y wynosi: " + wartoscDlaY);
  21. return wartoscDlaY;
  22. }
  23.  
  24.  
  25. public double obliczPierwiastki() {
  26. System.out.println("\nJestem funkcją obliczPierwiastek");
  27. double delta, pierwiastekZDelty, liczbaPierwiastkow, x1, x2, x0;
  28. delta = (b * b) - 4 * a * c;
  29. System.out.println("Delta = " + delta);
  30.  
  31.  
  32. if (delta > 0) {
  33. pierwiastekZDelty = Math.sqrt(delta);
  34. System.out.println("Pierwiastek z delty = " + pierwiastekZDelty);
  35. liczbaPierwiastkow = 2;
  36. x1 = (-b - pierwiastekZDelty) / (2 * a);
  37. x2 = (-b + pierwiastekZDelty) / (2 * a);
  38. System.out.println("x1 = " + x1 + "\nx2 = " + x2);
  39. } else if (delta == 0) {
  40. liczbaPierwiastkow = 1;
  41. x0 = -b / (2 * a);
  42. System.out.println("x0 = " + x0);
  43. } else {
  44. liczbaPierwiastkow = 0;
  45. System.out.println("Delta mniejsza od zera, brak miejsc zerowych");
  46. }
  47. return liczbaPierwiastkow;
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement