Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help with Java homework

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with Java homework

    I am completely lost with this assignment. Can someone help me with it? Here are our instructions:

    This assignment will use the following description to implement a Dialog class for the Leap Year Problem. You need to decompose this problem into 2 classes:


    1.The Date.java class. Implement a public class Date that represents a date composed of a month , day, and a year. Declare month, day, and year as integers. They are the 3 instance variables. Remember that you need to write a constructor Date and 4 methods:

    "daysIs()" which returns a day

    "monthIs()" which returns a month

    "yearIs()" which returns a year

    "isLeapYear()" is needed in the class Date. It has one parameter "year" and returns a boolean. Write the method isLeapYear() knowing that a year is defined to be a leapyear it is a multiple of 4, and if it is is a multiple of 100, it must also be a multiple of 400. isLeapYear() thus decides when a year is a leap year. (see the discussion on "Hints for Assign5" to discover specific examples of a LeapYear).

    2.The DateJDialog.java class: which implements the GUI. Please use the Dialog boxes developed in the book in chapter2 in pages 99-100 in the code-listing 2-32 (NamesDialog.java) for input and output.

    Remember that you will prompt the user to enter:

    1.a day;

    2.a month;

    3.a year

    And out of these 3 you will be able to create a Date. Then you will use the dialog box to tell the user whether the year entered was a leapyear or not a leapyear.

    The purpose of the Date.java that you will implement is to decide whether a year is a leap year. Here is a definition of when a year is considered a leap year :
    1.
    year y1 is a leap year if it is multiple of 4.

    2.
    year y1 is a leap year if it is a multiple of 100, it must be a multiple of 400.

    3.
    Otherwise y1 is not a leap year.


    Do not forget to compile the 2 java files. To verify that the DateJDialog.java works, in TextPad after you compile DateJDialog.java, Click on Tools, Click on "Run Java Application".


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help with Java homework

    Quote Originally Posted by BoDuke1835 View Post
    Can someone help me with it?
    Glad to help. What do you need help with?

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with Java homework

    Here is what I have for the leap year program. The 2nd file will be for the GUI, how do I associate the files together?

    public class LeapYear {
    public static void main(String[] args) {
    int year = Integer.parseInt(args[0]);
    boolean isLeapYear;

    // divisible by 4
    isLeapYear = (year % 4 == 0);

    // divisible by 4 and not 100
    isLeapYear = isLeapYear && (year % 100 != 0);

    // divisible by 4 and not 100 unless divisible by 400
    isLeapYear = isLeapYear || (year % 400 == 0);

    System.out.println(isLeapYear);
    }
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Help with Java homework

    how do I associate the files together?
    A method in another class can call the main() method in this class using normal static method calling syntax:
    Classname.methodName(args to method here)

    This class needs to be on the classpath so the java program can find it.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Can you someone help me with my homework for java... Please
    By surfelijo in forum What's Wrong With My Code?
    Replies: 15
    Last Post: February 25th, 2013, 09:01 PM
  2. Replies: 8
    Last Post: February 12th, 2013, 04:45 AM
  3. New to Java. Need help with homework
    By ptison in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 26th, 2013, 04:53 PM
  4. Really new to Java, need some help with some homework
    By vanillabilla in forum Java Theory & Questions
    Replies: 1
    Last Post: November 14th, 2012, 10:01 PM
  5. Java Homework Help
    By JustDelta767 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 6th, 2012, 07:22 AM