Jump to content


Photo
- - - - -

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


  • Please log in to reply
3 replies to this topic

#1 Psywar

Psywar

    Social Engineering at its finest.

  • Moderator
  • PipPipPipPipPipPip
  • 6325 posts
  • Gender:Male
  • Location:Saint Clair, MI

Posted 30 June 2015 - 04:07 PM

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....dit?usp=sharing

 

Thanks for any help!


 sigimage.php?un=Psywar&t=12772
ASUS M5A97 R2.0 Motherboard
AMD FX 8350 (4.0GHz 16MB Cache 8-Core)
XFX R7970 Black Edition Video Card
Mushkin Enhanched 16GB RAM
PC Power and Cooling 610w PSU


#2 Waco

Waco

    Lab Rat 2

  • Members
  • PipPipPipPipPipPipPipPip
  • 16508 posts
  • Gender:Male
  • Location:Los Alamos, NM

Posted 30 June 2015 - 07:29 PM

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.

Tolerance is a sign of weakness.


#3 Psywar

Psywar

    Social Engineering at its finest.

  • Moderator
  • PipPipPipPipPipPip
  • 6325 posts
  • Gender:Male
  • Location:Saint Clair, MI

Posted 01 July 2015 - 03:18 AM

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.


 sigimage.php?un=Psywar&t=12772
ASUS M5A97 R2.0 Motherboard
AMD FX 8350 (4.0GHz 16MB Cache 8-Core)
XFX R7970 Black Edition Video Card
Mushkin Enhanched 16GB RAM
PC Power and Cooling 610w PSU


#4 Psywar

Psywar

    Social Engineering at its finest.

  • Moderator
  • PipPipPipPipPipPip
  • 6325 posts
  • Gender:Male
  • Location:Saint Clair, MI

Posted 02 July 2015 - 02:22 PM

Fixed the issue:

 

Line 94 I added the code:

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

 sigimage.php?un=Psywar&t=12772
ASUS M5A97 R2.0 Motherboard
AMD FX 8350 (4.0GHz 16MB Cache 8-Core)
XFX R7970 Black Edition Video Card
Mushkin Enhanched 16GB RAM
PC Power and Cooling 610w PSU