• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Hi. My first question.

 
Greenhorn
Posts: 22
Chrome Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I would have registered earlier, but everytime I have seen a google search result that inlcuded this site, the questions were all 3, 4 or 5 years old, so I thought this site was dead... sorry!

Anyway, I do have a problem that two other forums have not been able to help me with.

Starting from lines 79-95 lies my problem. While there is no error in the code, and the && operator works perfectly, I do not want the message "tomorrow" to appear if a user enters a future day a week or more later. I will include two outputs at the bottom.
Thanks.







\Here is my problem



The whole purpose of the tomorrow code was to output tomorrow is Tuesday, instead of "Today is Monday and the future day is Tuesday."
 
Marshal
Posts: 80133
418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Why are you using % 6 when there are 7 days in the week?
 
Stephen Carter
Greenhorn
Posts: 22
Chrome Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

Why are you using % 6 when there are 7 days in the week?



Because 0 = Sunday and so on.


I am at


That's as far as I have gotten.

using blocks to label blocks of code?
block1 : {
code
/code
}

if (future + today >= 6)
break block1;
 
Campbell Ritchie
Marshal
Posts: 80133
418
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use % 6 you will never get a result above 5.
 
Campbell Ritchie
Marshal
Posts: 80133
418
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephen Carter wrote: . . .

using blocks to label blocks of code?
block1 : {
code
/code
}
. . .

Don't like break, labelled break even less. Others might disagree with me.
 
Stephen Carter
Greenhorn
Posts: 22
Chrome Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:If you use % 6 you will never get a result above 5.


I put it at 7. I am still learning. I am taking a College Java course.
I hope to take the Introduction to Android programming this summer.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To answer your original question you need to keep a record of the actual number entered for the future date and only print the 'tomorrow' bit if the number entered is less than 7.

BTW instead of the block of if statements to print the day of the week you could have an array with the names of days of the week and then you would just need to use the 'today' and/or 'future' variables as an index into the array to get the appropriate day text.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephen Carter wrote:I put it at 7. I am still learning. I am taking a College Java course.


Have you covered arrays yet? Because, if so, you could put your 'days of the week' (the names) in a string array (String[]); and since Java indexes are 0-based, it will work nicely with your '%' operator.

Another thing: think about writing a few methods to help you out; right now all your logic is crammed into main(), which isn't generally a good way to work.

Third: You are using switch statements in some places and 'if' stacks (which should probably be (if...else if...) in others. The first (lines 20-33) could certainly be changed to use a switch statement, which might be clearer - but the main point is: be consistent.

Fourth: Please DontWriteLongLines; it makes your post very difficult to read. I've broken them up (which unfortunately invalidates your line numbers; the new range is 82-102).

Winston
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic