[Bluej-discuss] Ex 9.7

Colleen Penrowley cpen at telus.net
Sun Nov 12 19:22:52 GMT 2006


John,

Try:
System.out.print(" CD:  "  + artist) ;

Colleen


At 11:55 AM 11/12/2006 -0500, John Simonds wrote:
>  Thank you for your prompt reply.  My question was a bit more specific 
> than that.  I unsderstand that when printing from CD, for instance that 
> the print method will execute CD's print method and wherever 
> super.print();  is placed, Items print method's will execute in the order 
> they are placed.  My question is that in the book, question 9.7 wants you 
> to print
>
>
>CD:  Frank  Sinatra:  A Swingin'  Affair  *
>
>64 minutes
>
>my favorite Sinatra album
>
>tracks: 16
>
>Now, the code I have in Item, looks like this:
>
>public void print( )
>{
>     System.out.print(title + " ( " + playingTime + minutes)");
>     if (got It)   {
>       System.out.println(" * ");
>       }  else {
>             System.out.println( ) ;
>      }
>      System.out.println("  "  + comment);
>
>   }
>
>}
>
>The CD class has this print method:
>
>public void print( )
>{
>     System.out.println(" CD:  "  + artist) ;
>     super.print( ) ;
>     System.out.println("   tracks:  + numberOfTracks);
>
>}
>
>What I get looks like this:
>
>CD : Frank Sinatra
>A Swingin' Affair (64 minutes)*
>great album
>tracks 16
>
>
>I can't seem to get CD: Frank Sinatra A Swingin' Affair (64 minutes)*  all 
>on the same line, which is what the exercise calls for.
>
>
>John Simonds
>Systems Technologist
>simonj2 at sage.edu
>(518)244-3111
>(518)292-1734
>
>
>
>
>---------------------------------------
>Original E-mail
>From: Davin McCall
>Sent: 11/12/2006 02:19 AM
>To: John Simonds , General discussion for users of BlueJ
>Subject: Re: [Bluej-discuss] Ex 9.7
>
>Hi John,
>
>I don't happen to have a copy of the book handy at the moment, but:
>
>What determines "what prints where" is simply a matter of the order in 
>which things print - and that is the same order as the relevant print 
>statements in your code are executed. This order is of course determined 
>solely by the structure of your program. Understanding how the structure 
>and the execution order are related is critical to understanding how to 
>program.
>
>I suggest you need to look at your program and - in your head - follow the 
>execution path to see when each statement will be executed. Then you 
>should be able to see why some things are printed before others, and 
>hopefully also where you need to put your own print statements to get the 
>desired behaviour.
>
>If this is too difficult (the execution path may be very complex) you can 
>use the debugger to step through your program's execution line by line. 
>You just need to set a breakpoint at the beginning of the method you are 
>going to call interactively, then call the method. Use the "Step" or "Step 
>into" buttons in the debugger window to see how your program runs ("Step" 
>will step over method calls, so I recommend using "Step into" unless the 
>call is trivial and you already understand what it does).
>
>There should be more information on how to use the debugger in the 
>tutorial, or at least in the reference manual, which you can download from 
>the web site.
>
>I hope this is helpful & I apologise if I have oversimplified due to 
>misunderstanding your question,
>
>Davin
>
>
>
>On Sat, 11 Nov 2006 20:04:19 -0500 (EST)
>John Simonds wrote:
>
> > I am having a problem with Ex 9.7 and the problem is, I don't know how 
> to get it to print in a specific order.
> > I did the super.print(); method.  I discovered that, depending on where 
> that is placed in one of the other classes, things print out differently, 
> put I don't know how to get contol over what prints where.
> >
> >
> > John Simonds
> > Systems Technologist
> > simonj2 at sage.edu
> > (518)244-3111
> > (518)292-1734
> >
> >
> >
> >
> >
> >
>
>
>
>
>_______________________________________________
>mailing list bluej-discuss at bluej.org
>To unsubscribe or change your preferences, go to
>http://lists.bluej.org/mailman/listinfo/bluej-discuss




More information about the bluej-discuss mailing list