From cb88f040cd3c9594bdc7cead653eebe54b14bd9c Mon Sep 17 00:00:00 2001 From: Doni Pracner Date: Wed, 6 May 2015 02:09:37 +0200 Subject: [PATCH] PolinomL, doterivanja primera --- kodovi/polinomi/PolSuma.java | 49 +++++++++++++++++--------------- kodovi/polinomi/PolinomDemo.java | 45 +++++++++++++++-------------- 2 files changed, 50 insertions(+), 44 deletions(-) diff --git a/kodovi/polinomi/PolSuma.java b/kodovi/polinomi/PolSuma.java index 021ec13..1794c4e 100644 --- a/kodovi/polinomi/PolSuma.java +++ b/kodovi/polinomi/PolSuma.java @@ -8,34 +8,37 @@ public class PolSuma { int k; - do { - System.out.print("Unesite broj k ( >0 ) "); - k = Svetovid.in.readInt(); - } while (1 > k); + System.out.print("Unesite broj k ( >0 ) "); + k = Svetovid.in.readInt(); - PolinomL[] p = new PolinomL[k]; + if (k > 0) { - 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(); - } + PolinomL[] p = new PolinomL[k]; - for (int i = 1; i <= k; i++) { - System.out.println((i + 1) + ". polinom: "+p[i]); - } + for (int i = 0; i < k; i++) { + System.out.println(); + System.out.print("Unos polinoma broj "); + System.out.print(i + 1); + System.out.println(); + p[i] = new PolinomL(); + p[i].unos(); + } - PolinomL suma = new PolinomL(); - for (int i = 1; i <= k; i++) { - suma.saberiNa(p[i]); - } + for (int i = 0; i < k; i++) { + System.out.println("polinom broj " + (i + 1) + ": " + p[i]); + } - System.out.println(); - System.out.println("Njihova suma je: " + suma); + PolinomL suma = new PolinomL(); + for (int i = 0; i < k; i++) { + suma.saberiNa(p[i]); + } + + System.out.println(); + System.out.println("Njihova suma je: " + suma); + + } else { //k <= 0 + System.out.println("Pogresna vrednost za k, nije moguce nastaviti"); + } } } diff --git a/kodovi/polinomi/PolinomDemo.java b/kodovi/polinomi/PolinomDemo.java index d4c7fee..cc158f1 100644 --- a/kodovi/polinomi/PolinomDemo.java +++ b/kodovi/polinomi/PolinomDemo.java @@ -1,37 +1,40 @@ - +/** + * Zadatak: formirati polinom 'p' od korisničkog unosa. Formirati polinom 'q' + * tako da bude jednak sa x^5 - 3x^4 + 4.5x + 7. Izračunati zbir ova dva + * polinoma. + * + */ public class PolinomDemo { - - public static void main(String[] args){ - - PolinomL p, q, rez; - - /*Korisnik unosi prvi polinom*/ - p = new PolinomL(); + + public static void main(String[] args) { + + /* Korisnik unosi prvi polinom */ + PolinomL p = new PolinomL(); System.out.println("Unestite polinom: "); p.unos(); - - /*Drugi polinom kreiramo mi, monom po monom*/ - q = new PolinomL(); - /*Postavimo clan x^5*/ + + /* Drugi polinom kreiramo mi, monom po monom */ + PolinomL 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*/ + /* 4 x */ + q.postaviClan(4.5, 1); + /* 7 x^0 */ q.postaviClan(7.0, 0); - - /*Sabiramo polinome*/ - rez = p.saberi(q); - - /*Odstampamo rezultat i polinome*/ + + /* Sabiramo polinome */ + PolinomL 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