Question

JAVA LANGUAGE create an empty Java file called Date build it to find any syntax errors...

JAVA LANGUAGE

  1. create an empty Java file called Date
  2. build it to find any syntax errors and eliminate them
  3. identify each member of this class and write your answer in a comment
    1. There are four different types of class member: constant, instance variable, constructor, and method
    2. identify a method as class method if it is static

/*
* Java program: Date.java
*
* Define the class Date
*/
import java.time.LocalDateTime;
public class Date
{
private static final int daysEachYear = 365;
private int year;
private int month;
private int date;
public Date(int y, int m, int d)
{
year = y;
month = m;
date = d;
}
public Date(int y)
{
year = y;
month = 1;
date = 1;
}
public void setYear(int y)
{
year = y;
}
public void setMonth(int m)
{
month = m;
}
public void setDate(int d)
{
date = d;
}
public int getYear()
{
return year;
}
public int getMonth()
{
return month;
}
public int getDate()
{
return date;
}
public void displayDate()
{
System.out.printf("\nThe date is %d/%d/%d\n", month, date, year);
}
public static void displayCurrentTime()
{
System.out.println("\nThe current date & time is: " +
LocalDateTime.now());
}
} //end class Date

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Java code with comments

/*
 * Java program: Date.java
 *
 * Define the class Date
 */
import java.time.LocalDateTime;
public class Date
{
    //constant
    private static final int daysEachYear = 365;
    //instance variable
    private int year; //year
    private int month;//month
    private int day;//day
    //Overload constructor

    /**
     * set all the instance variable
     * @param y
     * @param m
     * @param d
     */
    public Date(int y, int m, int d)
    {
        year = y;
        month = m;
        day = d;
    }
    //Constructor with one Parameter

    /**
     * set year to passed argument variable
     * and set month to 1 and day to 1
     * @param y
     */
    public Date(int y)
    {
        year = y;
        month = 1;
        day = 1;
    }
    //Note:- all getters and setters are member methods
    //to set and get instance variables
// SETTERS
    /**
     * set year
     * @param y
     */
    public void setYear(int y)
    {
        year = y;
    }

    /**
     * set month
     * @param m
     */
    public void setMonth(int m)
    {
        month = m;
    }

    /**
     * set day
     * @param d
     */
    public void setDay(int d)
    {
        day = d;
    }
    //getters

    /**
     *
     * @return year
     */
    public int getYear()
    {
        return year;
    }

    /**
     *
     * @return month
     */
    public int getMonth()
    {
        return month;
    }

    /**
     *
     * @return day
     */
    public int getDay()
    {
        return day;
    }
    // member method
    /**
     * print date on console
     */
    public void displayDate()
    {
        System.out.printf("\nThe day is %d/%d/%d\n", month, day, year);
    }
    // class method
    /**
     * display current time
     */
    public static void displayCurrentTime()
    {
        System.out.println("\nThe current day & time is: " +
                LocalDateTime.now());
    }
} //end class Date

//================ test class=====================

public class Main {
    public static void main(String[] args)
    {
        Date date = new Date(2019);
        date.displayDate();
        Date.displayCurrentTime();
        Date date1 = new Date(2019,10,20);
        date1.displayDate();
    }
}

//============= output ===================

//If you need any help regarding this solution ........... please leave a comment ........ thanks...

Add a comment
Know the answer?
Add Answer to:
JAVA LANGUAGE create an empty Java file called Date build it to find any syntax errors...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • public class Date { private int month; private int day; private int year; /** default constructor...

    public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); } /** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy )...

  • Need help figuring out what would be the all 12 days output public class Date {...

    Need help figuring out what would be the all 12 days output public class Date {    private int day;    private int month;    private int year;       private static int tracker;       public Date()    {        this(1, 1, 2000);        System.out.println("4");    }       public Date(int year)    {        this(1, 1, year);        System.out.println("3");    }       public Date(int month, int year)    {        this(1, month,...

  • (IN JAVA ) Given the class Date that can prints the date in numerical form. Some...

    (IN JAVA ) Given the class Date that can prints the date in numerical form. Some applications might require the date to be printed in another form, such as March 24, 2005. Please do the following: Derive the class ExtDate so that the date can be printed either form. Add a data member to the class ExtDate so that the month can also be stored in string form. Add a method to output the month in the string format followed...

  • I'm having trouble with the daysSince() Method in bold at the end of the program public...

    I'm having trouble with the daysSince() Method in bold at the end of the program public class Date { static final int [] daysInMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; private int day, month, year; public Date() { day = 1; month = 1; year = 2000; } public Date(int d, int m, int y) { day = d; month = m; year = y; } public Date (String s) { setDate(s);...

  • CO 3) Demonstrate encapsulation by creating a declaration file from the following UML diagram: (Note) The...

    CO 3) Demonstrate encapsulation by creating a declaration file from the following UML diagram: (Note) The declaration file is the header file (.h file) and implementation file is the .cpp file. Date 0 - num Date: static int - day: int - month: int - year int +Date0 +Date(int, int, int) +Date(Date &) +Date0 +get Day0: int +setDay (nt): void +getMonth int +setMonth (int): void +getYear int +setYear(int) void +dis play Date0: void

  • Programming Exercise 11-8 PROBLEM:The class dateType defined in Programming Exercise 6 prints the date in numerical...

    Programming Exercise 11-8 PROBLEM:The class dateType defined in Programming Exercise 6 prints the date in numerical form. Some applications might require the date to be printed in another form, such as March 24, 2019. Derive the class extDateType so that the date can be printed in either form. Add a member variable to the class extDateType so that the month can also be stored in string form. Add a member function to output the month in the string format, followed...

  • Write a class Date with: Three instance variable : day, month and year all of type...

    Write a class Date with: Three instance variable : day, month and year all of type int. Define the following public methods for the class Date: A constructor Date() without parameter, make the date 1-1-2000   A constructor Date(int d, int m, int y) with parameters that provide the values attributes. Include accessor methods: getDay getMonth getYear Include mutator methods: setDay: make sure that day between 1 to 30 setMonth: make sure that month between 1 to 12 setYear A method...

  • The class dateType is designed to implement the date in a program, but the member function...

    The class dateType is designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the data members. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and the year are checked before storing the date into the data members. Add a function member, isLeapYear, to check whether a year is a leap...

  • C++ problem 11-6 In Programming Exercise 2, the class dateType was designed and implemented to keep...

    C++ problem 11-6 In Programming Exercise 2, the class dateType was designed and implemented to keep track of a date, but it has very limited operations. Redefine the class dateType so that it can perform the following operations on a date, in addition to the operations already defined: Set the month. Set the day. Set the year. Return the month. Return the day. Return the year. Test whether the year is a leap year. Return the number of days in...

  • I need to create a Java class file and a client file that does the following:  Ask user to enter Today’s date in the fo...

    I need to create a Java class file and a client file that does the following:  Ask user to enter Today’s date in the form (month day year): 2 28 2018  Ask user to enter Birthday in the form (month day year): 11 30 1990  Output the following: The date they were born in the form (year/month/day). The day of the week they were born (Sunday – Saturday). The number of days between their birthday and today’s...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT