Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Talar;
- import static java.lang.Math.*;
- public class funkcjaKwadratowa {
- private double a;
- private double b;
- private double c;
- private double x1;
- private double x2;
- public funkcjaKwadratowa(double a, double b, double c){
- if(a==0) this.a = ((b+c)/2);
- else this.a = a;
- this.b = b;
- this.c = c;
- }
- public double obliczWartosc(double x){
- double y = 0;
- y = (this.a * pow(x,2)) + (this.b * x) + this.c;
- return y;
- }
- public int ilePierwiastkow(){
- int ilosc = 0;
- double delta = pow(this.b,2) - 4 * this.a * this.c;
- if(delta < 0) ilosc = 0;
- else if(delta == 0){
- ilosc = 1;
- this.x1 = (this.b/2*this.a) * -1;
- }
- else if(delta > 0){
- ilosc = 2;
- this.x1 = (((this.b*(-1))+sqrt(delta))/(2*this.a));
- this.x2 = (((this.b*(-1))-sqrt(delta))/(2*this.a));
- }
- return ilosc;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement