• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MyPrint()

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I downloaded a Basic Calculator program from Planet Source Code called BasicCalc_III. I wrote it out again in Eclipse to try and understand every aspect of it. The program itself is too large to put here so I am putting some of the code I am having difficulty with up here. Hope someone can help me understand the MyPrint() part of this.

public void actionPerformed( ActionEvent e ) {

tempNum = "" + answer ;

if ( e.getSource() == bPlus || e.getSource() == bSub ||
e.getSource() == bMult || e.getSource() == bDiv ) {
tempNum = "" + answer ;

MyPrint( "actionPerformed() 1a: The value of result is " + result +
" The value of tempNum is " + enterBox.getText() +
" The value of opCode is " + opCode ) ;
}
This is the actionPerformed method but I don't understand what MyPrint does. The MyPrint method is shown below:


/** *******************************************************
* MyPrint() - toggles debug aid on or off
* ******************************************************/
public void MyPrint( String str ) {
if ( myDiag )
System.out.println( str );

}
/** ********** End of MyPrint() *****************************/

Hope this makes sense
.
Regards,
Gus
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a hint: The comment at the top of the method is completely incorrect. So go past that and look at the actual code. It isn't that complicated... so what do you think it does?
 
Ranch Hand
Posts: 117
Mac Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It prints the String passed to it if myDiag is set to true.

 
Gus Hayes
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys for the prompt replies.
This MyPrint appears in lots of the classes in this program. Where does it print to. Is it like System.out.println(). I am a newbie and this is confusing me. Below is another example of it from the same program:

/** ***********************************************************
* MyATan() - computes the arc tangent of the entered number.
* The logic is:
* 1- If there is a pending operation, proces it.
* 2- Take the squareroot of the value in the enter box field.
* 3- Store the anser into firstNum and dNum1
* 4- Set the secondNum to null
* 5- Enter firstNum/answer into the enter box field
* 6- Set dNum2 to 0.0
* 7- Indicate that there are no pending oprations.
* **************************************************************/
public void MyATan() {
MyPrint( "MyATan() 1: opCode is " + opCode + " firstNum is " + firstNum +
"pendingOpCode =s " + pendingOpCode +
" pendingOp =s " + pendingOp ) ;
if ( pendingOpCode >= 0 ) {
MyPrint( "MyATan() 2: pendingOpCode =s " + pendingOpCode ) ;
pendingOp = true ;
opCodeMethod() ;
}

Where does MyPrint actually send the information to?
Thanks and regards,
Gus
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the operational line of that code (there are only two lines):



But it seems you already know what this code does. Am I missing something in your question?
 
Gus Hayes
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
Thanks for the reply but what does this code do. Am I right in saying the MyPrint() method is called and it prints what is inside the brackets or sends what is inside the brackets to the MyPrint() method. As I am a newbie it is confusing me.


MyPrint( "MyATan() 1: opCode is " + opCode + " firstNum is " + firstNum +
"pendingOpCode =s " + pendingOpCode +
" pendingOp =s " + pendingOp ) ;
if ( pendingOpCode >= 0 ) {
MyPrint( "MyATan() 2: pendingOpCode =s " + pendingOpCode ) ;
pendingOp = true ;
opCodeMethod() ;
}


Thanks,
Gus
 
Paul Mrozik
Ranch Hand
Posts: 117
Mac Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Am I right in saying the MyPrint() method is called and it prints what is inside the brackets or sends what is inside the brackets to the MyPrint() method. As I am a newbie it is confusing me.



Yes, you are right, but do notice that there's a conditional statement in the MyPrint() method. If you want to see what it does, find the myDiag field declaration and set it to true. Then compile/run the program and keep your eyes on the console while performing different calculations.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic