• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Problem with printing variables

 
Ranch Hand
Posts: 42
Netbeans IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Lines 102 to 124 is my inputSystemTask() method. It asks users to input a month, day, hour, minute, and a message. It then passes each variable to another class, UserInput(), to check for correct input.
Lines 94 to 100 is my toString() method that prints a message using the month, day, hour, minute, and message variables.
On lines 128 to 130 of my main method I am attempting to print the new user input variables using my toString() method. It will print my default values for my variables, but not my new user input variables.
Where am I going wrong?
Thank you.

 
Sheriff
Posts: 28382
99
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
As far as I can see: your method where input takes place doesn't actually assign any values to month, day, and so on. It passes those things into your mysterious UserInput class, for why I don't know. Maybe those assignment statements are the wrong way around?
 
Paul Clapham
Sheriff
Posts: 28382
99
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
By the way, having those class-level variables (month, day, etc) be static is going to cause you problems. Shouldn't each SystemTask object have its own version of those things?
 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are adding value in UserInput class methods but not system task class and you are class toString() method of system task class.
 
Scott M Summers
Ranch Hand
Posts: 42
Netbeans IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, I am sending values to my UserInput class, to check if it is within the correct parameters. I'm using to set the value from the variable in UserInput to the value for my variable in SystemTask.
 
Paul Clapham
Sheriff
Posts: 28382
99
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

Scott M Summers wrote:Right, I am sending values to my UserInput class, to check if it is within the correct parameters. I'm using to set the value from the variable in UserInput to the value for my variable in SystemTask.



But you already know that the value of the month variable is correct. It's "Jan", because you already assigned that value to it in the constructor. So what's the point of sending it to the UserInput class? Shouldn't you be checking the value which the user typed in instead?

Especially since you don't seem to do anything after that, based on whether it's acceptable or not. Especially, you don't assign any new value to the month variable, and that results in the problem you already complained about.
 
Scott M Summers
Ranch Hand
Posts: 42
Netbeans IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Jan" is the default value for month.
I don't want to send my default value to my UserInput class, nor am I. I send the user input from inputSystemTask() to the UserInput class.
UserInput will check to see if the user input is within the parameters and returns a variable. I need the returned variable from UserInput to be assigned as my new month, new day, new hour, and new message. This way I can print the new variables that the user input using my toString() method.

Code for UserInput:

 
Paul Clapham
Sheriff
Posts: 28382
99
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

Scott M Summers wrote:"Jan" is the default value for month.
I don't want to send my default value to my UserInput class, nor am I.



On the contrary, that's exactly what this line of code does:



It assigns the value of variable "month", which until you change it (which you never do) contains the default value of "Jan", to something inside the UserInput class.

I need the returned variable from UserInput to be assigned as my new month, new day, new hour, and new message.



Well then, why don't you do that? You need to assign something from the UserInput class to the "month" variable, and you don't have any code which does it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic