• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to make a class that creates a timeseries array and returns the entire array  RSS feed

 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I want the calling class to be able to iterate the timeSeries array,
I dont want to return specific elements

got the following error


F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\TimeSeries.java:26: error: '.class' expected
        return timeSeries[];
1 error


 
Pete Letkeman
Ranch Foreman
Posts: 914
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven, try changing line 25 from

to

and line 20 from

to

To see what happens.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But there is already a member called 'timeSeries' of type LocalDate[]. The current code, even with Pete's improvement, is very confusing.

In your constructor, simply initialize this member with:

You can then make the method 'getTimeSeries()' have a return type of void, if you drop the line

(and dropping the return statement of course).

By the way, why not make 'timesSeriesDateStart' a parameter of the constructor as well?
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried
Piet's suggestions but got this error

F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\TimeSeries.java:23: error: '(' expected
public void LocalDate getTimeSeries(){
1 error
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\nbproject\build-impl.xml:930: 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)




 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Steven,

yes, getting all those details right can take some time.

A method has only one return type, that can be void or some class. So this is wrong:

since you are now specifying both 'void' and 'LocalDate' as return types. Remove the 'LocalDate':

Then, as the last statement in your constructor, add:

(a better name might be: fillTimeSeries, and you should make this method private instead of public)

Well, see if you can get the code up and running!
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Piet
Thanks for help.
Well I got my TimeSeries class to have no errors.
I am having trouble figuring out how to access the time series in my class that consumes the TimerSeries

error
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:67: error: array required, but TimeSeries found
                boolean isbefore = employees.getEmployee(j).getDateStart().isBefore( timeSeries[t]);
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:68: error: array required, but TimeSeries found
                boolean isafter= employees.getEmployee(j).getDateEnd().isAfter( timeSeries[t]);
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:70: error: array required, but TimeSeries found
                boolean isequalStart= employees.getEmployee(j).getDateStart().isEqual( timeSeries[t]);
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:73: error: array required, but TimeSeries found
                boolean isequalEnd= employees.getEmployee(j).getDateEnd().isEqual( timeSeries[t]);
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:101: error: cannot find symbol
        for ( int t1=0; t1 < timeSeries.length; t1++ ) {
  symbol:   variable length
  location: variable timeSeries of type TimeSeries
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:108: error: array required, but TimeSeries found
                    String textOut= timeSeries[t1]   + "," +  totalHeadCount+ "," + totalSalary + ",";
6 errors
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\nbproject\build-impl.xml:930: 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)





 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your Employees class looking like these days?
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's employees class
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You declare timeSeries to be of type TimeSeries but you use it like an array.
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what your point is. I want to access the individual elements.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute's point is that you're applying the [] operator to an instance of type TimeSeries. The [] operator can only be applied to arrays, which the variable timeSeries is not.
If you want to get individual dates from your TimeSeries instance, you have to expose them with a method:
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I was trying to do was to return the entire TimeSeries as an object. And then iterate  through it in the calling class OnPlanUserModule.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding a getLocalDate() method to the TimeSeries class:

Now you can use it to get a specific LocalDate based on an index:
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Steven,

well I see that a lot has been thrown at you! So here comes the next portion  

Seeing what you intend to do with a TimeSeries instance, it might be time to consider how we can get the month indices in a more efficient way. Here is my thought. Global Health Warning: what follows may be a bit complex. If so, then forget it for now: we will come back to it later.

1) suppose that the class TimeSeries has a method that, when called with a starting date and an end date, gives us a list of the indices of all the months in the timeSeries instance that are completely inside the two parameters startdat and enddate. So that would mean something like:

2) we may assume that the starting date of any employee is on the first of a month, and an eventual enddate also on the first of the month. Otherwise, since parts of a month do not count as a working month, we can make a method that forces these dates to start on the first of the month.

3) The LocalDates in the LocalDate-array are also as per the first of a month. Now, since LocalDate implements Comparable<LocalDate>, we can use a binarysearch to find the index of the startdate and the enddate in our array.

4) the months worked are the months from the index of startdate up to the index of the enddate. We can make a List of these integers, and return them.

5) of course, the startdate or the enddate may not be present in the LocalDate-array, so we need to take that into account.

6) the instance that invokes, for every employee, this method, makes a big List of all the months in the returned Lists. Then it is a simple task to make a frequencytable of all the months received.

7) this sounds maybe a bit complicated, but with Java 8 it is just a few simple lines of code. But that will be for later.

8) Can you implement a method, that makes the startdate and enddate be on the first of the month?

9) By looking at the API of Arrays, method
     (click here for the api)

can you find the index of the LocalDate 'startdate' in the LocalDate-array?

10) can you implement this new method in the TimeSeries class?

Well, as said, this may sound (and probably it is) complicated, so don't worry if it is not clear. If so, we will come back to this later.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!