• Post Reply Bookmark Topic Watch Topic
  • New Topic

While, For, & Do Loop Help.  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I've been doing some coding and I'm 75% done with my Program. I just need to finish this last method in my class and I'll be set my only issue is that I having trouble starting it.

This is the code



I've done the rest of the coding within the program fine while some help however this one has got me stomp.

I was think of creating a Date Object within and try to use a For or While loop to execute the Input (1/1/1990) -> Output (#1).

If you want me to post the rest of my Class or Tester please let me know.

 
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the requirements?
What have you tried?
What is "Excel Date"?
What converting Date to int has to do with "While, For, & Do Loop"??
NotACodeMill <- click this
StopCoding <- and this

Offtop
AAAAAAAAAAAAAAAAAA!!! Hungarian notation!!! NOOOOOOOOOOOOOO!!!
End of offtop

And welcome to the Ranch.
 
Jean Pe
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote:What are the requirements?
What have you tried?
What is "Excel Date"?
What converting Date to int has to do with "While, For, & Do Loop"??
NotACodeMill <- click this
StopCoding <- and this

Offtop
AAAAAAAAAAAAAAAAAA!!! Hungarian notation!!! NOOOOOOOOOOOOOO!!!
End of offtop

And welcome to the Ranch.


Sorry,

Here is a copy of the class.


Microsoft Excel® numbers dates as 1, 2, 3, etc, beginning with January 1st, 1900. E.g., February 6th, 1900 is Excel Date 37. Have the user enter a date (month, day, and year) and call the iExcel method to get the Excel Date for the input date. Print it in your main method, not in iExcel.



The goal is to have the User input a date in the format of mm/dd/yyyy and for the Class to output a number between 1 and Infinity that represents the date in excel.

Not sure if that made it more confusing :x

EDIT:I am not looking for the answer to my code obviously I will not learn anything that way. I'm trying to get a push in the right direction for this one. The past methods were challenging for me but after hours of slamming my head into my keyboard I was able to create and finish the methods. However this one seems a little odd compared to the other ones.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
 
Jean Pe
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


It's not so much calculating the dates in-between other dates.

Let me see if i can give an example.

lets say I have a list in Excel and my #1 is the date 1/1/1990

and lets say the list will continue for infinity.
i.e

#2 1/2/1990
#3 1/3/1990
#4 1/3/1990
.....
#31 1/31/1990
#32 2/1/1990
.....

etc.

So what I am trying to do is make the user input a date (mm/dd/yyyy) in which the method will receive this date and spit out a number where the date belongs in this list of Excel dates. The list has been predefine already starting from date 01/01/1990 as #1 in the list.

so If i give the date 05/09/2039 it will give me the number #3245972 (this is just an example this is not the actual number).

EDIT: Forgot to add that the method says it Requires a Loop of some sort, For, While, or Do. Im in the processes of figuring out which one would be best so far I'm thinking a while loop could work for this method.
 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jean Pe wrote:It's not so much calculating the dates in-between other dates.
...
lets say I have a list in Excel and my #1 is the date 1/1/1990

...
#2 1/2/1990
#3 1/3/1990
#4 1/3/1990
.....
#31 1/31/1990
#32 2/1/1990
.....


Given that 1/1/1990 is #1, why is 1/2/1990 #2? Why is 1/3/1990 #3? If someone gave you 1/12/1990 then what would you give them as a result? How did you come by that result? Do you see why Pawel gave the suggested topic he did and how it applies to your post?

and lets say the list will continue for infinity.

Then int is not the data type you need to use, since int will not take you to infinity (it will take you a long way, though).
 
Jean Pe
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:
Jean Pe wrote:It's not so much calculating the dates in-between other dates.
...
lets say I have a list in Excel and my #1 is the date 1/1/1990

...
#2 1/2/1990
#3 1/3/1990
#4 1/3/1990
.....
#31 1/31/1990
#32 2/1/1990
.....


Given that 1/1/1990 is #1, why is 1/2/1990 #2? Why is 1/3/1990 #3? If someone gave you 1/12/1990 then what would you give them as a result? How did you come by that result? Do you see why Pawel gave the suggested topic he did and how it applies to your post?

and lets say the list will continue for infinity.

Then int is not the data type you need to use, since int will not take you to infinity (it will take you a long way, though).


I see what you mean. I excel counts Days in a month within a year. I understand now what Pawel meant. between 01/01/1990 and 01/04/1990 are 4 days hence #4 in the excel list. And I didnt mean infinity sorry I meant the int limit : 32,767 Sorry for that.

But yeah I'm starting to understand it now a little more.

If you give me the date 01/12/1990, then that should be #12 within the excel list.

Thanks! im slowly but surely getting it.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jean Pe wrote:And I didnt mean infinity sorry I meant the int limit : 32,767 Sorry for that.

Actually, the int limit is 2,147,483,647.
The value 32,767 is the short limit.

A big offtop:
I don't get this notation: 1/31/1990
Like month/day/year.
Is it american one?
It is (sorry for that) really stupid :P.
Like if I was giving you the time and told you
hours, then seconds, then minutes.
Or a latitude like: 23° 21″ 26′ N
I just don't get it. Sorry
End of big offtop
 
Jean Pe
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote:
Jean Pe wrote:And I didnt mean infinity sorry I meant the int limit : 32,767 Sorry for that.

Actually, the int limit is 2,147,483,647.
The value 32,767 is the short limit.

A big offtop:
I don't get this notation: 1/31/1990
Like month/day/year.
Is it american one?
It is (sorry for that) really stupid :P.
Like if I was giving you the time and told you
hours, then seconds, then minutes.
Or a latitude like: 23° 21″ 26′ N
I just don't get it. Sorry
End of big offtop


Yeah it's the American date format which is month/day/year

1/31/1990 -> January 31st, 1990.
 
Ranch Hand
Posts: 147
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote:
I don't get this notation: 1/31/1990
Like month/day/year.
Is it american one?


One can get used to it. I did (I'm german, we use day/month/year, or year-month-day), but it still confuses me when I'm not certain which notation is used in a given example. I'm still hoping for widespread usage of dates conforming to ISO 8601 in a few years.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jan Hoppmann wrote:we use day/month/year, or year-month-day

Yeah, because this is logical. Units in order biggest to lowest or lowest to biggest.
I always have a problem when facing a date like 11/12/2013. Is it 11th day of December? 12th day of November? Who knows...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not seeing a solution using a loop. set the starting date. set the parameter date. take the difference in days. return number of days as an int. What did i miss?

Ok right after i posted this i see how you can do it. Keep a counter and loop adding a day to the starting date, until you get to the parameter date. return the counter. There ya go.
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
stan johnson wrote:I'm not seeing a solution using a loop. set the starting date. set the parameter date. take the difference in days. return number of days as an int. What did i miss?

Ok right after i posted this i see how you can do it. Keep a counter and loop adding a day to the starting date, until you get to the parameter date. return the counter. There ya go.



I am not seeing the need for the loop either. Yes, you can increment and count -- but why? Why iterate, when you can just calculate the result directly?

Henry
 
Master Rancher
Posts: 2046
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it's not that clear.

Today it is November, 8. Suppose someone asks you how many days are there between today and December, 4.
I bet you do something like this:

November has 30 days, so that's 22 days left. Then I add 4 days, o yes, it's 26 days.

So, as everything in real life, a bit of a while loop and a bit of calculating.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!