• 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

Monthly calendar. Help with simplification

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all. The code below builds monthly calendar. It was my homeclass and it works fine. But it looks pretty long and complicated. Can it be simplified? How?
Thank you

 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could use the standard date/time library https://docs.oracle.com/javase/tutorial/datetime/
 
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. You have got only 1 method in your class, and that method is named "main" which suppose to start your program only.
And it should look similar to:
2. Check if leap year suppose to become a method named isLeapYear() and return "true" if it is, and "false" if it is not.
3. Define month suppose to be a separate method also, which a singular task to define which month it is. Could be named for ex. "defineMonthName()"
4. Define the day of the month should be method also, and take a month name as a parameter.

And likely more methods. So, after you get methods created, your program could be similar to:
After all this, you might find that you can simplify some parts. If you write program by placing all code in one method, it is very difficult to improve something without breaking down something.
Also, it is very difficult to follow your program flow. For the simple programs one class maybe is enough, but one method is not enough in pretty much all cases. Unless it is a "Hello, World" program.
 
Tony Fisher
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you good sir.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic