From: Doni Pracner Date: Wed, 29 Apr 2015 11:17:19 +0000 (+0200) Subject: Primeri koriscenja PolinomL klase X-Git-Url: https://svarog.pmf.uns.ac.rs/gitweb/?a=commitdiff_plain;h=d94134725646fe79c448cf84f95f7ac661056d7b;p=spa1-materijali.git Primeri koriscenja PolinomL klase --- 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(); + + } + +}