This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with printing variables  RSS feed

 
Scott M Summers
Ranch Hand
Posts: 42
Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • 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.

 
Paul Clapham
Sheriff
Posts: 22480
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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: 22480
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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?
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • 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
Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • 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: 22480
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • 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: 22480
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!