Results 1 to 9 of 9
  1. #1
    Jsin is offline Member
    Join Date
    Nov 2011
    Location
    Texas
    Posts
    7
    Rep Power
    0

    Default Teaching myself Java.

    Hello guys,

    I'm teaching myself Java and I am at the end of chapter 3 in Introduction to Java Programming. 8th ed. by Y. Daniel Liang. I am working on one of the programming exercises and I am having an issue with this.

    dayOfWeek = [day + [26*(month + 1)/10] + year + [year/4] + [century/4] + 5*century] * .07;

    I don't think my use of parentheses and square brackets are correct, but I have played around with for a while and still don't know where my errors are.

    Thanks for the help.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Teaching myself Java.

    It all should be parenthesis and there should be no square brackets unless you're somehow dealing with arrays but not showing us (which I doubt). If the book is showing square brackets, consider getting another book.

  3. #3
    Jsin is offline Member
    Join Date
    Nov 2011
    Location
    Texas
    Posts
    7
    Rep Power
    0

    Default Re: Teaching myself Java.

    The book did show brackets but it was the actual formula and not code. I did try using all parenthesis but I wasn't getting the answer I needed. Maybe my problem is else where then. Thanks for the help.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Teaching myself Java.

    Quote Originally Posted by Jsin View Post
    The book did show brackets but it was the actual formula and not code. I did try using all parenthesis but I wasn't getting the answer I needed. Maybe my problem is else where then. Thanks for the help.
    Show us your best attempt at a code solution, your expected output and your observed output.

  5. #5
    Jsin is offline Member
    Join Date
    Nov 2011
    Location
    Texas
    Posts
    7
    Rep Power
    0

    Default Re: Teaching myself Java.

    Ok here is my best attempt at the code.

    dayOfWeek = (day + (26*(month + 1)/10) + year + (year/4) + (century/4) + 5*century) * .07;

    The answer I get is 185.01000000000002
    If I do it by hand I get 150.04

    day:26
    month:3
    year:2002
    Last edited by Jsin; 11-26-2011 at 12:34 AM.

  6. #6
    Jsin is offline Member
    Join Date
    Nov 2011
    Location
    Texas
    Posts
    7
    Rep Power
    0

    Default Re: Teaching myself Java.

    Ok, I may have read the pseudocode wrong after doing a little more reading I think this might be the right code...

    dayOfWeek = (day + (26*(month + 1)/10) + year + (year/4) + (century/4) + 5*century) %7;

    Notice the end I think the code is asking for a remainder not a percentage, but my answer is still not right. Now what I am getting is a 4 when I should be getting a 3. Can anybody tell me if I am getting closer to this?

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Teaching myself Java.

    You'll have to let us know what numbers you use and what are the rules and restrictions here.

  8. #8
    Jsin is offline Member
    Join Date
    Nov 2011
    Location
    Texas
    Posts
    7
    Rep Power
    0

    Default Re: Teaching myself Java.

    What I am trying to do is use the Zeller's congruence to determine the day of the week. After doing some more research I think the formula in my book might be wrong. The numbers I am using are

    day:26
    month:3
    year:2002

    and I am trying to come up with Tuesday as the answer. My main question is if I was using the parentheses and square brackets correctly.

  9. #9
    Jsin is offline Member
    Join Date
    Nov 2011
    Location
    Texas
    Posts
    7
    Rep Power
    0

    Default Re: Teaching myself Java.

    This is the working code.

    dayOfWeek = (day + (13*(month + 1)/5) + (year%100) + ((year%100)/4) + (century/4) + 5*century) %7;

    Thanks guys for the help.

Similar Threads

  1. Servlets class not teaching servlets
    By tsky in forum Java Servlet
    Replies: 5
    Last Post: 04-26-2011, 11:47 PM
  2. Tool for teaching Java
    By finsalscollons in forum New To Java
    Replies: 4
    Last Post: 03-17-2010, 04:24 AM
  3. The master list of self teaching java
    By fresh83 in forum New To Java
    Replies: 2
    Last Post: 12-27-2009, 01:09 AM
  4. Help with Teaching software
    By Doctor Cactus in forum New To Java
    Replies: 3
    Last Post: 11-03-2008, 07:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •