From d94134725646fe79c448cf84f95f7ac661056d7b Mon Sep 17 00:00:00 2001 From: Doni Pracner Date: Wed, 29 Apr 2015 13:17:19 +0200 Subject: [PATCH] Primeri koriscenja PolinomL klase --- kodovi/polinomi/PolSuma.java | 41 ++++++++++++++++++++++++++++++++ kodovi/polinomi/PolinomDemo.java | 37 ++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 kodovi/polinomi/PolSuma.java create mode 100644 kodovi/polinomi/PolinomDemo.java diff --git a/kodovi/polinomi/PolSuma.java b/kodovi/polinomi/PolSuma.java new file mode 100644 index 0000000..021ec13 --- /dev/null +++ b/kodovi/polinomi/PolSuma.java @@ -0,0 +1,41 @@ +/** + * Program koji ucitava broj `k`, a potom i niz od `k` polinoma i nakon toga + * izracunava njihovu sumu. + */ +public class PolSuma { + + public static void main(String[] args) { + + int k; + + do { + System.out.print("Unesite broj k ( >0 ) "); + k = Svetovid.in.readInt(); + } while (1 > k); + + PolinomL[] p = new PolinomL[k]; + + for (int i = 0; i < k; i++) { + System.out.println(); + System.out.print("Unos "); + System.out.print(i + 1); + System.out.print(". polinoma."); + System.out.println(); + p[i] = new PolinomL(); + p[i].unos(); + } + + for (int i = 1; i <= k; i++) { + System.out.println((i + 1) + ". polinom: "+p[i]); + } + + PolinomL suma = new PolinomL(); + for (int i = 1; i <= k; i++) { + suma.saberiNa(p[i]); + } + + System.out.println(); + System.out.println("Njihova suma je: " + suma); + } + +} diff --git a/kodovi/polinomi/PolinomDemo.java b/kodovi/polinomi/PolinomDemo.java new file mode 100644 index 0000000..d4c7fee --- /dev/null +++ b/kodovi/polinomi/PolinomDemo.java @@ -0,0 +1,37 @@ + +public class PolinomDemo { + + public static void main(String[] args){ + + PolinomL p, q, rez; + + /*Korisnik unosi prvi polinom*/ + p = new PolinomL(); + System.out.println("Unestite polinom: "); + p.unos(); + + /*Drugi polinom kreiramo mi, monom po monom*/ + q = new PolinomL(); + /*Postavimo clan x^5*/ + q.postaviClan(1.0, 5); + /*-3 x^4*/ + q.postaviClan(-3.0, 4); + /*4 x*/ + q.postaviClan(4.0, 1); + /*7 x^0*/ + q.postaviClan(7.0, 0); + + /*Sabiramo polinome*/ + rez = p.saberi(q); + + /*Odstampamo rezultat i polinome*/ + System.out.println("p: " + p); + System.out.println(); + System.out.println("q: " + q); + System.out.println(); + System.out.println("rez: " + rez); + System.out.println(); + + } + +} -- 2.25.1