Advertisement
Talar97

Zadanie z funkcją kwadratową

Mar 26th, 2018
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package com.Talar;
  2. import static java.lang.Math.*;
  3.  
  4. public class funkcjaKwadratowa {
  5.     private double a;
  6.     private double b;
  7.     private double c;
  8.     private double x1;
  9.     private double x2;
  10.  
  11.     public funkcjaKwadratowa(double a, double b, double c){
  12.         if(a==0) this.a = ((b+c)/2);
  13.         else this.a = a;
  14.         this.b = b;
  15.         this.c = c;
  16.     }
  17.  
  18.     public double obliczWartosc(double x){
  19.         double y = 0;
  20.         y = (this.a * pow(x,2)) + (this.b * x) + this.c;
  21.         return y;
  22.     }
  23.  
  24.     public int ilePierwiastkow(){
  25.         int ilosc = 0;
  26.         double delta = pow(this.b,2) - 4 * this.a * this.c;
  27.         if(delta < 0) ilosc = 0;
  28.         else if(delta == 0){
  29.             ilosc = 1;
  30.             this.x1 = (this.b/2*this.a) * -1;
  31.         }
  32.         else if(delta > 0){
  33.             ilosc = 2;
  34.             this.x1 = (((this.b*(-1))+sqrt(delta))/(2*this.a));
  35.             this.x2 = (((this.b*(-1))-sqrt(delta))/(2*this.a));
  36.         }
  37.        
  38.         return ilosc;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement