• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem trying to create a series of dates separated by 1 month using LocalDate

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create an array with a series of dates separated by 1 month. There are 60 months.
0th element should be 2017-06-01
1st element  2017-07-01
etc

getting 2 errors
empty statement after for
; expected

I have imported java.time.LocalDate;


 
Master Rancher
Posts: 3922
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

getting 2 errors
empty statement after for
; expected  


Please copy full text of the compiler's error message and paste it here.
The message should show the source with a ^ under the location of the error.
Here is a sample from the javac compiler:
 
Master Rancher
Posts: 4669
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Check your brackets.

That sort of error is almost always because you've mucked up the brackets, and occasionally because you did actually forget a ';'.
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note:
What i posted was a code excerpt so line numbers differ from following.

I am using Netbeans. Not sure how to view compiler error output


ant -f F:\\Users\\User\\Documents\\NetBeansProjects\\OnPlanUserModule -Djavac.includes=onplanusermodule/OnPlanUserModule.java -Dnb.internal.action.name=compile.single compile-single
init:
Deleting: F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\build\built-jar.properties
deps-jar:
Updating property file: F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\build\built-jar.properties
Compiling 1 source file to F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\build\classes
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:53: error: ';' expected
       for ( int j=0; j < timeSeries.length); j++ ) {
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:53: error: ';' expected
       for ( int j=0; j < timeSeries.length); j++ ) {
2 errors
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\nbproject\build-impl.xml:953: The following error occurred while executing this line:
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\nbproject\build-impl.xml:270: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)
 
Marshal
Posts: 70338
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you copied that code correctly? I can see other potential compiler errors.
How many times will that loop run if you ever get it to start, and when will the last date in the series be?
Why are you creating two new local date objects in the loop? You only need to create one.
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This compiles with no errors

want loop to iterate 60 times

 
Dave Tolls
Master Rancher
Posts: 4669
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not just parse the string once outside the loop, and use the same resulting LocalDate object each time around the loop to do the calculation on?
 
Campbell Ritchie
Marshal
Posts: 70338
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Steven Greenbaum wrote:This compiles with no errors

That is only the first stage in getting correct code.

. . . want loop to iterate 60 times . . .

Yes, it is iterating 60×. But do you want the final date to be 2022-06-01?
 
Campbell Ritchie
Marshal
Posts: 70338
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Why not just parse the string once outside the loop, and use the same resulting LocalDate object each time around the loop to do the calculation on?

That is one way to create only one new object per loop; I can think of another way. I also think my idea which I haven't told you and Dave's can easily finish up on 2022-06-01.
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so that would be something like:

 
Campbell Ritchie
Marshal
Posts: 70338
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In which case please predict the date of the last element in that array.
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:In which case please predict the date of the last element in that array.



Thanks for your input.

I think last date would be 2022-05-01

As to your other comments:
I have changed the set/get names in my Employee class per your recommendation.

As to using constructors I may try that but dont think necessary in my application. I expect a validated input for a number of employees.

As to not caring about employees after they become non-employees:

I am trying to get headcount vs time for a company.

For each person/employee a 1 will be entering a 1 into a headcount array for that employee if they were employed in the associated time slot, else a 0. When
this is done for all people /employees, The total company headcount can be computed as a function of time.  So from this point of view, we are interested in them before they become employees as well.
Also, since part of the time series will be in the future, some of these people are hypothetical.




 
Bartender
Posts: 2233
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven, assume your start date is 2016-12-30.

Which series do you want to get?

2016-12-30, 2017-01-30, 2017-02-28, 2017-03-28, 2017-04-28, 2017-05-28...
or
2016-12-30, 2017-01-30, 2017-02-28, 2017-03-30, 2017-04-30, 2017-05-30...

This has to be specified to solve your problem correctly.
 
Campbell Ritchie
Marshal
Posts: 70338
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had suggested a possible solution to Paweł who pointed out a possible error in my suggestion; it will show no error if you start from 2017-06-01.

Another thing: if you do start from 1st June (=2017-06-01), what do you think the first date of your sixty will be and what the last date will be.
 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic