Brandon Hunter Brandon Hunter - 1 year ago 114
Java Question

Calendar (GregorianCalendar) .complete() method not visible?

So I read through a few different threads but none of them seem to directly address how I fix my issue. I'm trying to create a Calendar (Gregorian) and then use the .complete() method so that in my classes using this (Paycheck) class I can find relative dates and create new Calendar(s) from those dates to determine wages payed and wages owed. However, it's telling me that .complete() .computeTime() and .computeFields() are all not visible.

From what I've read, this seems to be because they are protected methods and even though I import the java.util for them, I can't access them because that class is not in my package. How do I get this so that I can call the .complete() method?

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Paycheck {
protected double grossAmount;
protected Calendar paymentDate;
protected Calendar payPeriodStart;

public Paycheck(double grossAmount, int iYear, int iMonth, int iDay, int sYear, int sMonth, int sDay) {
this.grossAmount = grossAmount;

TimeZone tz1 = TimeZone.getTimeZone("America/Chicago");
this.paymentDate = new GregorianCalendar(iYear, iMonth, iDay);
this.paymentDate.complete(); //says "method not visible"

this.payPeriodStart = new GregorianCalendar(sYear, sMonth, sDay);


I appreciate any help! Sorry if I'm an idiot, I'm a newer Java user.

Answer Source

In a comment you wrote:

I don't care about the actual time, I just want it to give me the date so I can determine the dayofweek (important based on various state laws).

That is very easy to do, and don't need any call to internal methods.

Calendar cal = new GregorianCalendar(2016, Calendar.SEPTEMBER, 22);
System.out.println("Day of week (1=Sun, ..., 7=Sat): " + cal.get(Calendar.DAY_OF_WEEK));


Day of week (1=Sun, ..., 7=Sat): 5

Output is 5 because today is Thu 9/22/2016, and that's the date that was given.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download