/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javaapplication1; import java.util.List; import java.util.Scanner; /** * * @author pw.d.9 */ public class JavaApplication1 { /** * @param args the command line arguments */ public static void main(String[] args) { System.out.println("hello world"); double a,b,c; Scanner sc = new Scanner(System.in); RównanieKwadratowe rk;// = new RównanieKwadratowe(2, 2, -12); // double d = rk.obliczDelte(); // double[] zerowe = rk.mscZerowe(d); // System.out.println(zerowe[0]); // System.out.println(zerowe[1]); // System.out.print("Podaj a: "); a= 5;//sc.nextDouble(); //System.out.print("Podaj b: "); b= 4;//sc.nextDouble(); //System.out.print("Podaj c: "); c= -12;//sc.nextDouble(); rk = new RównanieKwadratowe(a, b, c); double d = rk.obliczDelte(); double[] zerowe = rk.mscZerowe(d); System.out.println(zerowe[0]); System.out.println(zerowe[1]); System.out.print("Podaj x0: "); double x0 = sc.nextDouble(); System.out.print("Podaj x1: "); double x1 = sc.nextDouble(); System.out.print("Podaj skok: "); double skok = sc.nextDouble(); List rs = rk.obliczWPrzedziale(x0, x1, skok); System.out.println("X Y"); for(double y : rs){ // System.out.println(x0 + " " + y); System.out.println(String.format("%1$-2.3f %2$2.3f", x0, y)); x0+=skok; } } } //RównanieKwadratowe.java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javaapplication1; import java.util.ArrayList; import java.util.List; /** * * @author pw.d.9 */ class RównanieKwadratowe { private double _a, _b, _c; public RównanieKwadratowe(double a, double b, double c) { _a = a; _b = b; _c = c; } public double obliczDelte(){ return _b*_b - 4*_a*_c; } public double[] mscZerowe(double delta) { double[] msc_zerowe = {0,0}; if(delta > 0){ msc_zerowe[0] = (-_b - Math.sqrt(delta))/2*_a; msc_zerowe[1] = (-_b + Math.sqrt(delta))/2*_a; return msc_zerowe; } if(delta == 0){ msc_zerowe[0] = -_b/2*_a; msc_zerowe[1] = -_b/2*_a; return msc_zerowe; } return msc_zerowe; } public double function(double x){ return _a*x*x+_b*x+_c; } public List obliczWPrzedziale(double x0, double x1, double skok){ List results = new ArrayList<>(); for(double x = x0; x