Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class Delta {
- double a, b, c;
- public Delta(double a, double b, double c) {
- this.a = a;
- this.b = b;
- this.c = c;
- System.out.println("\nA = " + a + "\nB = " + b + "\nC = " + c);
- }
- public double obliczY(double x) {
- System.out.println("\nJestem funkcją obliczY");
- double wartoscDlaY;
- wartoscDlaY = (a * (x * x)) + (b * x) + c;
- System.out.println("Wartość y wynosi: " + wartoscDlaY);
- return wartoscDlaY;
- }
- public double obliczPierwiastki() {
- System.out.println("\nJestem funkcją obliczPierwiastek");
- double delta, pierwiastekZDelty, liczbaPierwiastkow, x1, x2, x0;
- delta = (b * b) - 4 * a * c;
- System.out.println("Delta = " + delta);
- if (delta > 0) {
- pierwiastekZDelty = Math.sqrt(delta);
- System.out.println("Pierwiastek z delty = " + pierwiastekZDelty);
- liczbaPierwiastkow = 2;
- x1 = (-b - pierwiastekZDelty) / (2 * a);
- x2 = (-b + pierwiastekZDelty) / (2 * a);
- System.out.println("x1 = " + x1 + "\nx2 = " + x2);
- } else if (delta == 0) {
- liczbaPierwiastkow = 1;
- x0 = -b / (2 * a);
- System.out.println("x0 = " + x0);
- } else {
- liczbaPierwiastkow = 0;
- System.out.println("Delta mniejsza od zera, brak miejsc zerowych");
- }
- return liczbaPierwiastkow;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement