🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.java
Article #153785

Re: Poczatkujacy - program nie dziala tak jak powinien.

#153785
From: gorudonu
Date: Sun, 17 Mar 2013 01:51
18 lines
2303 bytes
Program sie nie zapetla. Tylko widze ze w konstruktorze klasy "liczby" (btw klasy z duzej litery) tworzysz nowy obiekt klasy "wyniki". Klasa "wyniki" posiada konstruktor, ktory wczytuje dane z klawiatury. Nastepnie w metodzie main tworzysz cztery obiekty ktore dziedzicza po klasie liczby (czyli uruchamiany jest cztery razy konstruktor "liczby"). Dlatego program pyta sie cztery razy. Cwiczenie pewnie mialo posluzyc jako nauka polimorfizmu wiec, czemu nie zrobic tak:

abstract class Liczy {

protected int a;
protected int b;

//gettery i settery


}

nastepnie w kazdej klasie w konstruktorze podawac te dwa parametry lub poprzez te propertisy. a liczby zaczytywac tylko raz w metodzie main.

innym sposobem jest zrobienie Liczby jako interface oraz dadanie metody 
public void setNumbers(int a, int b);

wtedy kazda klasa implementujace ten interface bedzie musiala tez miec defeinicje tej metody.
Technical Details
Message-ID: <c0a1796d-10c0-482e-9e8e-744345b891db@googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin2!goblin.stu.neva.ru!cyclone02.ams2.highwinds-media.com!voer-me.highwinds-media.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!t2no4070294qal.0!news-out.google.com!k8ni188qas.0!nntp.google.com!dd2no2024071qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
References: <ki2m7o$hl8$1@speranza.aioe.org>

Show Full Headers
Complete Article Headers
X-Received: by 10.224.185.79 with SMTP id cn15mr6674498qab.4.1363485061929;        Sat, 16 Mar 2013 18:51:01 -0700 (PDT)
X-Received: by 10.49.116.165 with SMTP id jx5mr917173qeb.22.1363485061890; Sat, 16 Mar 2013 18:51:01 -0700 (PDT)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin2!goblin.stu.neva.ru!cyclone02.ams2.highwinds-media.com!voer-me.highwinds-media.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!t2no4070294qal.0!news-out.google.com!k8ni188qas.0!nntp.google.com!dd2no2024071qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: pl.comp.lang.java
Date: Sat, 16 Mar 2013 18:51:01 -0700 (PDT)
In-Reply-To: <ki2m7o$hl8$1@speranza.aioe.org>
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=77.254.207.122; posting-account=HN9TswoAAAA5UOWD0lXLYbKUGwR6HMby
NNTP-Posting-Host: 77.254.207.122
References: <ki2m7o$hl8$1@speranza.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c0a1796d-10c0-482e-9e8e-744345b891db@googlegroups.com>
Subject: Re: Poczatkujacy - program nie dziala tak jak powinien.
From: gorudonu@gmail.com
Injection-Date: Sun, 17 Mar 2013 01:51:01 +0000
X-Received-Bytes: 2177
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit