This week's book giveaways are in the Angular and TypeScript and Web Services forums.
We're giving away four copies each of Programming with Types and The Design of Web APIs and have the authors on-line!
See this thread and this one for details.
Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Not getting the most desired behavior

 
Ranch Hand
Posts: 58
1
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So my problem is: An office submits schedules for interviewing candidates the following week. If submission is done on week 3 of the year, the submission must be for week 4 and only week 4. There can be no Mondays, nor weekend schedules submitted. I created scheduler app and then a ValidDate class to validate the submitted schedules. The code, while probably not as correct as it should be, works as a solution. The only issue is that I cannot get the submission cutoff to execute first before it checks all of the schedules for validity. It will validate all of the submissions, ask for corrections and then, when all are correct, it then initiates the cutoff and closes the app. I've tried puttng the before the but then it just skips it and no longer functions.

I am still learning core Java and playing with this side project is really helping me learn.

Any help is much appreciated,

Ray

Here is the scheduler and the validate class for it:



 
Marshal
Posts: 66975
255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you appear to have non‑private fieldss? See your very first code block, for example.
Afraid I don't think people will go through 400 lines of code to find the problem. Please start by writing a much smaller class (an SSCCE ←link) and isolate the problem. That might enable you to see the problem yourself, otherwise it will make it easier for us to help you.
 
Ray Gilbert
Ranch Hand
Posts: 58
1
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So in the Secheduler I have:



And in the ValidDate I have:



Whether or not is true, it still goes through all of the validations. I would prefere that if is true, that it then displays the message dialog and disposes and skips the validation process.
 
Sheriff
Posts: 14614
243
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The validDate() method is supposed to return a boolean, I'm guessing to indicate whether the date is valid or not. Why does it have code in it that uses a JOptionPane to display a message? This a very poor design. Imagine the equals() method of any object displaying something instead of just returning a boolean indicating if the current object is equal to another. Methods like this should do one thing and one thing only. If it's evaluating something, then that's all it should do. Displaying the result of that evaluation should be done somewhere else.
 
Ray Gilbert
Ranch Hand
Posts: 58
1
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:The validDate() method is supposed to return a boolean, I'm guessing to indicate whether the date is valid or not. Why does it have code in it that uses a JOptionPane to display a message? This a very poor design. Imagine the equals() method of any object displaying something instead of just returning a boolean indicating if the current object is equal to another. Methods like this should do one thing and one thing only. If it's evaluating something, then that's all it should do. Displaying the result of that evaluation should be done somewhere else.



Thank you Junilu, I always value your input. It makes sense that the ValidDate() method should do one thing but I am struggling with how not to again create repetitive code. When I first started, I had all the code in one class. The validate process was repeated with every date object created. From the perspective of scalability, this would be unworkable with a client that was allowed to submit up to 10 schedule dates. From what I have learned so far, I knew that was not a good design. I knew I needed to create a seperate class to validate the submissions. I wrote the ValidDate class that seemed to accomplish that. I also needed feedback to the user, to indicate what was wrong with a particular submission. I commented out the JOptionPane code and as one would expect, when a submission is incorrect, the application just sets there. I could create another method such as getErrorMsg() I guess but then I would have to repeat all of the same lines of code that are in the ValidDate() method. I sure that the fact that I am still early stages of learning basic core Java is not ideal but playing with this code and getting it to do what it does so far with my limited knowledge has been rewarding and encouraging.
 
Sheriff
Posts: 6551
176
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Whether or not

is true, it still goes through all of the validations. I would prefere that if

is true, that it then displays the message dialog and disposes and skips the validation process.



Why not this?:

 
Ray Gilbert
Ranch Hand
Posts: 58
1
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ray Gilbert wrote:

Junilu Lacar wrote:The validDate()  Methods like this should do one thing and one thing only. If it's evaluating something, then that's all it should do. Displaying the result of that evaluation should be done somewhere else.



I went back and worked the method and I broke a lot of things, got frustrated, left it, read more in my book, came back, broke more stuff, and then  I made it better:

I created a getErrorMsg() method and the validation behavior is exactly like I wanted. I repeated the same if statements in it as the ValidDate() method. I don't yet know a better way, yet. I know my coding is still brutally dirty but I am learning. This is how I changed the OmniTrackScheduler part of the code:


Thank you Junilu.

 
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!