[Bluej-discuss] bluej-discuss Digest, Vol 45, Issue 1

Bruce Quig bquig at deakin.edu.au
Wed Mar 7 02:13:37 GMT 2007


Parminder,

On 21/11 we announced that we were going to add another list 
specifically designed for questions about the Objects First book. We 
have also advised you personally (22/11 & 14/12) that bluej-discuss is 
not the appropriate place for continuing to ask questions relating to 
the Objects First book, particularly support/help/guidance related 
questions. As suggested last time, the appropriate list for you to join 
and post to is objects-first-discussion at bluej.org . 
<mailto:objects-first-discussion at bluej.org> If you have any problems 
trying to register for the new list contact us at bluej-support at bluej.org

Continued attempts to post these questions to bluej-discuss will result 
in us having to consider removing you from this list.


regards,

Bruce

Parminder Hundal wrote:

> Can someone help me with the Chapter 6 exercise.
>
>  
>
> Thanks
>
>     ------------------------------------------------------------------------
>     From:  /Stephen Bloch <sbloch at adelphi.edu>/
>     Reply-To:  /General discussion for users of BlueJ
>     <bluej-discuss at bluej.org>/
>     To:  /bluej-discuss at bluej.org/
>     Subject:  /Re: [Bluej-discuss] bluej-discuss Digest, Vol 45, Issue 1/
>     Date:  /Thu, 1 Mar 2007 17:35:13 -0500/
>     >Jason writes:
>     > >Okay, my programme that calculates pi based on a number of terms
>     > >entered is nearly finished but all the reading and everything I've
>     > >done is not helping me to understand how to make variables cross
>     > >between classes.
>     > >
>     > >Wallis's infinite product series ; pi = 2 x 2/1 x 2/3 x 4/3 x 4/5 x
>     > >6/5 x 6/7...... etc.
>     > >
>     > >Confirms to the following class diagram
>     > >
>     > >Picalculator
>     > >_________________
>     > >pi:double=0.0
>     > >_________________
>     > >+main(args:String[]
>     > >+getTerms():int
>     > >+calculatePi( terms:int):double
>     > >+displayPi(terms:int):void
>     > >_________________
>     > >
>     > >
>     > >'Method main() should call the other 3 methods in turn. All the
>     > >methods are static. Note what parameters are passed and
>     returned, if
>     > >any. .... (stuff to do with how to programme the bit that
>     calculates
>     > >pi that I've already done)....
>     > >A static attribute pi is present to hold the value of pi; this can
>     > >be assigned either once at the end of the kmethod call/
>     calculation,
>     > >or repeatedly updated on each pass through the loop; note that the
>     > >attribute has class scope and therefore visible throughout the
>     > >class. Method displayPi() should simply use the value stored in the
>     > >attribute pi and display it to screen, along with the number of
>     > >terms used to arrive at this approximation and an appropriate
>     > >message.'
>     >
>     >I agree with Andrea that this is a lousy example of object-oriented
>     >programming; if this is an assignment given by your instructor, your
>     >instructor is teaching 1960's-vintage procedural programming in a
>     >modern, object-oriented language.  Your instructor, alas, would be
>     >far from alone in this... :-(
>     >
>     >The idea that the three non-"main" methods have to be called in a
>     >particular order particularly bothers me.  (displayPi won't produce a
>     >correct answer unless calculatePi has already been called, and
>     >calculatePi won't produce a correct answer unless getTerms has
>     >already been called.  Yecch!)
>     >When you make a method public, you are allowing anybody in the world
>     >to call it whenever they choose; if it doesn't work correctly unless
>     >a particular other method has been called first, that's YOUR fault,
>     >not the fault  of the people who called it.  Public methods should be
>     >callable in any order, without affecting their correctness.
>     >
>     >Andrea suggests an alternative view of the problem:
>     > >Suppose you want to: create a PiCalculator, set the precision
>     once and call
>     > >the display() method.
>     > >The first time you call display, the computation is carried out
>     and you see
>     > >the result, from
>     > >the second time, you get the answer from the stored value PI in
>     your object.
>     > >If you set another precision (number of terms), the computation
>     should be
>     > >carried out again, next time you call the display().
>     > >
>     > >Suggestions:
>     > >Avoid passing the precision to all methods: use a local variable.
>     > >And make only the main to be static.
>     > >
>     > >In this way you could have 2 or 3 PiCalculators, set to different
>     > >precisions, in your application, and display them repeatedly.
>     >
>     >I like that approach.  I might go a step farther and get rid of the
>     >"display" method entirely.  If you're using BlueJ, you really don't
>     >need I/O until several months into a first programming course,
>     >because BlueJ allows you to call methods directly on specified
>     >parameters, and see the return values directly.
>     >
>     >But what about "user-friendliness"?  Well, that depends on what
>     >"user" means.  The vast majority of methods in the world are not used
>     >by humans, but rather by other methods; the most "user-friendly" way
>     >to interact with such a "user" is NOT to take in input from the
>     >keyboard and print it to System.out, but rather to take in parameters
>     >and return values, as your "calculatePi" method does.
>     >
>     >--
>     > Stephen Bloch
>     > sbloch at adelphi.edu
>     >_______________________________________________
>     >mailing list bluej-discuss at bluej.org
>     >To unsubscribe or change your preferences, go to
>     >http://lists.bluej.org/mailman/listinfo/bluej-discuss
>
>
> ------------------------------------------------------------------------
> Windows Live Spaces: Share your your latest news with your friends 
> now! <http://g.msn.com/8HMAENCA/2731??PS=47575>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>mailing list bluej-discuss at bluej.org
>To unsubscribe or change your preferences, go to
>http://lists.bluej.org/mailman/listinfo/bluej-discuss
>  
>


-- 
Bruce Quig
Research Programmer/Analyst
BlueJ Project
School of Engineering & Information Technology
Deakin University

Ph: +61 3 92446239

bquig at deakin.edu.au



More information about the bluej-discuss mailing list