This question's due date has already passed. You may post a tutorial, but there's no guarantee that the original asker will purchase the tutorial. But other people might!

Question

$15.00 Week 3 Help

Asked by :
jarhammy
jarhammy
Rating :No Rating
Questions Asked: 10
Tutorials Posted: 0
 
 
Q:

Hello, I am currently working on an assignment that I can not completely finish, I have all but the c step. I will post the assignment then what I have, how can I :

Incrementing into the next month in a leap year, for example,
use date: 02/28/2012 

STEP 2: Date (20
points)

Create a program called Date.java to perform
error-checking on the initial values, for instance: fields month, day, and year.
Also, provide a method nextDay() to increment the day by one. The Date object
should always remain in a consistent state.

 

Write a program called DateTest.java that
prompts the user to enter the month, day, and year as numeric values. This
program then creates a Date object using the Date class you just created and
tests the nextDay() method. This can be done in a loop of 40 iterations: the
Date object calls the nextDay() method and prints the date during each iteration
of the loop. This loop is to illustrate that the nextDay() method works
correctly. Test the following cases:



  1. Incrementing into the next month, for example, use date:
    02/28/2011
  2. Incrementing into the next year, for example, use date:
    11/27/2011
  3. Incrementing into the next month in a leap year, for example,
    use date: 02/28/2012

This is what I have so far:



package datePackage;

public class Date

{

    private int year;

    private int month;

    private int day;

    // constructor

    public Date(int year, int month, int day)

    {

        this.year = year;

        this.month = month;

        this.day = day;    

        if (month < 1 || month > 12)

            throw new
IllegalArgumentException("Invalid Month");

        if (!validDay())

            throw new
IllegalArgumentException("Invalid Day");

    }

    // move to next day

    public void nextDay()

    {

        day++;

        if (!validDay())

        {

            System.out.println("Day "
+ day + " invalid. Set to day 1.");

            day = 1;

            if (++month == 13)

            {

                month = 1;

                year++;

            }

        }

    }

    // check valid

    public boolean validDay()

    {

        int[] monthDay = {31, 28, 31, 30, 31,
30, 31, 31, 30, 31, 30, 31};

        boolean leap = (year % 400 == 0) ||
(year % 4 == 0 && year % 100 != 0);

        int addDay = (month == 2 &&
leap) ? 1 : 0;

        if (month >= 1 && month
<= 12 && day > 0 && day <= monthDay[month - 1] +
addDay)

            return true;

        return false;

    }

    // accessors

    public int getYear()

    {

        return year;

    }

    public int getMonth()

    {

        return month;

    }

    public int getDay()

    {

        return day;

    }   

}

 package datePackage;

public class DateTest

{

    // the main method

    public static void main(String[] args)

    {

        System.out.println("Checking
increment");

        Date dat = new Date(2010, 11, 21);

        System.out.println("Date object
constructor for date " + dat.getMonth() + "/" +

                dat.getDay() + "/" +
dat.getYear());

        for (int i = 0; i < 100; i++)

        {

            dat.nextDay();

System.out.println("Incremented Date: " + dat.getMonth() +
"/" +

                    dat.getDay() +
"/" + dat.getYear());

        }

    }

}

 

Available Tutorials to this Question
 
$1.00
Please message for detail
  • This tutorial was purchased 1 time and rated D by students like you.
  • Posted on Mar 18, 2012 at 7:23:14PM
Posted by :
lightsource
lightsource Not confirmed
Rating (2355):A+
Questions Asked: 4
Tutorials Posted: 5433,
Earned: $110,871.17
 
A:
Preview: ... lease ...

The full tutorial is about 8 words long .
 
$10.00
iLab 3 complete - Cylinder and Date classes
  • This tutorial was purchased 1 time and rated C- by students like you.
  • Posted on Sep. 18, 2012 at 06:20:09AM
Posted by :
A:
Preview: ... tion ...

The full tutorial is about 3 words long plus attachments.

attachmentlogo

Attachments:
iLab3.zip (7K) 

 iLab3/.classpath
 iLab3/.project
 iLab3/src/Cylinder.class
 iLab3/src/Cylinder.java
 iLab3/src/CylinderTest.class
 iLab3/src/CylinderTest.java
 iLab3/src/Date.class
 iLab3/src/Date.java
 iLab3/src/DateTest.class
 iLab3/src/DateTest.java
 ]

 
$15.00
correct A++ solution !!!
  • This tutorial hasn't been purchased yet.
  • Posted on Feb. 24, 2013 at 07:45:18AM
Posted by :
soleil91
soleil91
Rating (33):A
Questions Asked: 1
Tutorials Posted: 319,
Earned: $2,669.50
 
A:
Preview: ... 100% correct ...

The full tutorial is about 11 words long plus attachments.

attachmentlogo

Attachments:
Date.zip (63K) 

 Date/Date.java
 Date/DateTest.java
 Date/Date_screenshot.jpg
 ]

 
$10.00
Two java programs - Date.java and DateTest.java - an A++ work !!!
  • This tutorial hasn't been purchased yet.
  • Posted on Apr 13, 2013 at 7:57:56PM
Posted by :
special_one
special_one
Rating (213):A
Questions Asked: 0
Tutorials Posted: 304,
Earned: $8,946.31
 
A:
Preview: ... purchase   hope ...

The full tutorial is about 15 words long plus attachments.

attachmentlogo

Attachments:
DateTest.java (1K) (Preview)
Date.java (1K) (Preview)
screenshot.jpg (86K) (Preview)