Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9006249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:21:37+00:00 2026-06-16T01:21:37+00:00

I have an assignment for my classes: The class should have a methods of

  • 0

I have an assignment for my classes:

The class should have a methods of calculating the number of days between two dates, returns the day of the week and giving the sign of the zodiac for a given date.

And here is the code I’ve written:

import java.util.GregorianCalendar;

public class Data {
    private GregorianCalendar date;

    public Data(int year, int month, int day) {
        date = new GregorianCalendar(year, month + 1, day);
    }

    public int differenceInDaysFrom(int year, int month, int day) {
        GregorianCalendar tempDate = new GregorianCalendar(year, month, day);
        int daysBetween = (int)(tempDate.getTimeInMillis()-date.getTimeInMillis())/(1000 * 60 * 60 * 24);
        return Math.abs(daysBetween);
    }

    public String dayOfTheWeek() {
        String[] stringDays = new String[]{ "Monday",
                                            "Tuesday",
                                            "Wednesday",
                                            "Thursday",
                                            "Friday",
                                            "Saturday",
                                            "Sunday" };
        return stringDays[date.get(GregorianCalendar.DAY_OF_WEEK) - 1];
    }

    public void zodiacSign() {
        int day = date.get(GregorianCalendar.DATE);
        int month = date.get(GregorianCalendar.MONTH);

        System.out.println(day + " " + month);
    }
}
  1. When I initialize date with YYY\MM\DD everything works perfect when checking dayOfTheWeek for the near-future dates but when I put my birth date (1991\11\14) it returns Wednesday but I was born on Thursday.

  2. When I’m trying to get day and mont for checking the zodiac sign it totally freak out and returns 0 when I enter 11 (for month, days works good).

  3. What is more… When I started wangling with +1 to month even differenceInDaysFrom stopped working properly

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:21:38+00:00Added an answer on June 16, 2026 at 1:21 am

    for the problem of your birthday (wed or Thursday):

    first you have to pass month 10 as Nov. since 0=January. this has been spotted out by other answers.

    then you need to declare your String array as:

        new String[] { "Sunday", "Monday", "Tuesday", 
    "Wednesday", "Thursday", "Friday", "Saturday" };
    

    because, DAY_OF_WEEK, 1=Sunday, 2=MONDAY, check javaDoc of Calendar class. Then you should get “Thursday”

    for the zodiac method. you entered 11, so your date object received month parameter is 11+1=12. 12 is not valid month (0-11 are valid, as mentioned above, Jan=0) Therefore you got freak out. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a homework assignment where I have a base class Package, and two
I am working on an assignment and have to create two classes, one represents
If I have two classes A and B and I do A=B which assignment
I have an assignment to create a secure communication between 2 people with a
I have two classes, A and B. B knows about A, and A doesn't
take two following classes: class Test1{ public: Test1()=default; Test1(char in1,char in2):char1(in1),char2(in2){} char char1; char
I have an abstract immutable base class that defines enforces child classes to be
I have a rather unique class that allows its child classes to declare virtual
I have a Assignment question about Java Generics. The given class is Product.java. It
I have an assignment and we have a couple of classes given, one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.