Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to turn off debug statements in multiple classes ?

 
Anu pearson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code structure in which two classes are defined along with the main() method.
The class "Month" is instantiated in a class called "Tax_calc". Tax_calc is itself instantiated inside "main()".
Both the Tax_calc and Month classes have debugging messages turned on by default.
I am unable to figure out to turn off the debugging messages in BOTH classes - Tax_calc and also Income.
Would greatly appreaciate pointers on how to do this...
TIA
Anu
----------- Code structure --------------
public static void main(String[] args)
{
Tax_calc yr_2004;
yr_2004 = new Tax_calc;
}
public class Tax_calc
{
private boolean debug_flag;
//constructor
public Tax_calc
{
debug_flag = true;
show_values();
}
// instantiate the "Month class"
Month may2004;
may2004 = new Month;
//show_values method
public void show_values
{
debug("show calculated values");
}
// debug message method
public void debug(boolean on)
{
if(debug_flag)
{
System.out.println("Tax_Calc:" + message);
}
}
}
public class Income
{
private boolean debug_flag;

System.out.println("This is just a test\n");

public void toggleDebugMode(boolean on)
{
debug_flag = on;
}
public void debug( String message);
{
if(debug_flag)
{
System.out.println(message);
}
}
}
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Anu!
I'm not certain about what you're specifically looking for help on. Your question doesn't indicate that you've compilation problems that you can't figure out, but your posted example code obviously doesn't compile.
So, are you experiencing errors when compiling that you can't figure out? If so, what are the error messages?
If your question isn't to do with compilation, then perhaps you could post code that actually compiles.
When posting code, please be sure to surround the code with the [code] and [/code] UBB Tags. This will help to preserve the formatting of the code, thus making it easier to read and understand.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think what's going on is that he's got two separate boolean flags controlling debug prints in two separate classes, and somehow wants to turn them both on and off together. The answer is to make them just one fla: create a separate Debug class, and move your flag and debug() method into that class. Make it a static method. Then use that method from the other two classes, instead of duplicating the debug code.
 
Anu pearson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest and Dirk,
Thanks for your replies...
SOrry if the quality of the posting wasnt upto the mark ...I am still learning the ropes and promise to do better.
Here are additional specific details regarding the sample program that I stuff I am trying to do
The code has three parts to it...
A) The "driver" program if you will :
This simply instantiates the Tax_calc class :


B) The second part is a predefine class of methods called "Month":
[code]public class Tax_calc
{
private boolean debug_flag;
//constructor
public Tax_calc
{
debug_flag = true;
show_values();
}
// instantiate the "Month class"
Month may2004;
may2004 = new Month;
//show_values method
public void show_values
{
debug("show calculated values");
}
// debug message method
public void debug(boolean on)
{
if(debug_flag)
{
System.out.println("Tax_Calc:" + message);
}
}
}
 
Anu pearson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest and Dirk,
Thanks for your replies...
SOrry if the quality of the posting wasnt upto the mark ...and I apologize for the incomplete follow-up that I just inadverently posted....I am still learning the ropes and promise to do better.
Here are additional specific details regarding the sample program that I stuff I am trying to do
The code has three parts to it.
A) the main() method
B) the Income_calc method
C) the Month method
Of these, I only have edit priveledges to the Income_calc method.
I can get the code to compile...however, the problem that I am facing is with respect to turning on/turning off the Debug messages.
There are two distinct things that I am grappling with:
i) Trying to toggle the debug messages from the Income_calc method.
ii) Trying to toggle the debug messages from the Month method.

A) The "main()" method :
This simply instantiates the Tax_calc class :


B) The second part is a predefine class of methods called "Month". This class contains a method called debug and its constructor turns on debug_flag.

c) The third part is the class called Income. This class also contains a method

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic