• Post Reply Bookmark Topic Watch Topic
  • New Topic

Monthly calendar. Help with simplification  RSS feed

 
Tony Fisher
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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

 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use the standard date/time library https://docs.oracle.com/javase/tutorial/datetime/
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you good sir.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!