JAVA LANGUAGE
/*
* 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
//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...
JAVA LANGUAGE create an empty Java file called Date build it to find any syntax errors...
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 )...
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 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...
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 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 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...
java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the below classes: public class Date { private String month; private String day; private String year; public Date(String month, String day, String year) { this.month = month; this.day = day; this.year = year; } public String getMonth() { return month; } public String getDay() { return day; } public String...
Take your MonthDay class from Assignment #6 and modify it to throw an IllegalArgumentException when the user of the class attempts to pass an invalid value for month and year. Make sure you have your main method(function) in a separate source file demonstrating use of the try/catch block to catch the IllegalArgumentException that the MonthDay class may throw in the event of an invalid month, or year. class MonthDays { private int month; private int year; public MonthDays(int aMonth, int...
#include "stdafx.h" #include <iostream> using namespace std; class dateType { private: int dmonth; int dday; int dyear; public: void setdate (int month, int day, int year); int getday()const; int getmonth()const; int getyear()const; int printdate()const; bool isleapyear(int year); dateType (int month=0, int day=0, int year=0); }; void dateType::setdate(int month, int day, int year) { int numofdays; if (year<=2008) { dyear=year;...