Jump to content
Sign in to follow this  
Psywar

Java Program: I cannot figure out what is wrong (Fixed)

Recommended Posts

Hey ya'll!

 

I am working on my final programming project and I am stuck. My code runs with no errors, but my output is wrong.

When you look at the code you are going to wonder why I am not using a calendar function that is built in and the answer is I am not allowed to.

 

When you run my code you get 3 options.

Option 1 allows you to choose a day of the week.

It will tell you the next day, the previous day, and then it will ask you to input how many days in advance you want it to be. 

If I recall right on option 1 when you enter in the advance days it never returns the correct day. 

 

Option 2 is my testing option. It has a static day set (Sunday).

Here is the output:

Capture.JPG

 

As you can see from the photo adding 9 days, previous day, and add 3 days is totally wrong. EDIT: I actually just realized I uploaded the wrong screen capture. This photo is right.

 

I was hoping someone could help me out with this as I have been racking my head on it for the last couple days.

 

I have uploaded my code to Google Docs here: https://docs.google.com/document/d/1DRPgN0cK16P-dNpFTzFM074zweX4LN00z5iI8THxe8Y/edit?usp=sharing

 

Thanks for any help!

Share this post


Link to post
Share on other sites

So at first glance it looks like you're overwriting the variable holding the initial day. I haven't looked at the code at all though, but the increments and decrements all appear correct based on the previous answer.

Share this post


Link to post
Share on other sites

Hrmm.. that is an interesting thought.. 

I looked through the code and if I am, I cannot figure out where. 

I dunno.. I made another version of this program and it works, but it does not have the menu this one has and it also does not have a way to test the code like this version has.

However it does work correctly and it sounds like my teacher does not care if it has a testing feature or not so I might just turn that one in.

Share this post


Link to post
Share on other sites

Fixed the issue:

 

Line 94 I added the code:

theDay.setDay(theDay.getNextDay());
theDay.setDay(theDay.addDays(days));
 
fixed the issue right up.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...