Jump to content

Help with Java homework?

super_teabag

So, I'm doing this homework about creating classes, and my own methods, and I can't figure out how to do this one portion of the instructions which says.

 

Create a method called public void nextDay( )–

 

advance the date one day. This may also require advances to the month and/or the year. (15pts)

 

Note: Invoke the isLeapYear method, described below,to figure out if the year is a leap year. If it is a leap year, change the number of days for February from 28 to 29 in the String where you stored the number of days for each month. Instead of using literal numbers in your if statements to compare the number of days, use the substring method to retrieve the number of days for each month from the String that contains the days for each month, the Integer.parseInt method, and invoke the isLeapYear method when needed.

 

I don't understand how to invoke one of my methods in an if statement.

 

Examples:

4/10/2014 will

advance to 4/11/2014

12/31/2014 will advance to 1/1/2015.

2/28/2013 will advance to 3/1/2013

2/28/2004 will advance to 2/29/2004

 

note that 2004 is a leap year

 

Nextday.txt

 

Link to comment
Share on other sites

Link to post
Share on other sites

Does this help? Found in google with solutions looks to be similar task (pages 9 and 17): http://courses.cs.washington.edu/courses/cse142/14su/exams/final/final_sample_7.pdf

 

Also... i don't know java lol

Core i7 4820K  |  NH-D14 | Rampage IV Extreme | Asus R9 280X DC2T | 8GB G.Skill TridentX | 120GB Samsung 840 | NZXT H440  |  Be quiet! Dark Power Pro 10 650W

Link to comment
Share on other sites

Link to post
Share on other sites

Have you learned about getter/setter methods? You should have a getter/setter for the variables you created.

 

Maybe call the setter method you have and call it inside the nextday method. Call the getter and use that to increment the day variable with the setter. (Obviously check if it's a leap year, and also check if it's the last day of the month, in which I assume you increment to the following month and the first day of that month).

 

Hopefully this helps?

Link to comment
Share on other sites

Link to post
Share on other sites

 

You'll want something like this but you'll need to alter it a little to match your requirements. Then you'll call it in main using nextDay("4/10/2014"); which will return "4/11/2014".

-snip-

 

This is exactly what should be done if OP is a beginning programmer.

I might be wrong.

Link to comment
Share on other sites

Link to post
Share on other sites

The point of the homework is not to learn how to import, it's to learn how Java methods work.

Then learning the Java API would satisfy that requirement wouldn't it. Unless specifically told not to use then using built in Java classes is the way to go.

Link to comment
Share on other sites

Link to post
Share on other sites

Thanks everyone for helping out, I'm so confused on the rest of my assignment though... it's due tuesday I'm at my whits end and can't figure out how to come up with several more methods that I need to.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×