public class datetest {
public static void main(String[] args) {
Scanner S = new Scanner(System.in);
int d , m, y;
// 1- define object(d1) of date class without initialize value.
……………………………………………………………………………………….
// 2- define object(d2) of date class with initialize value ( 23,5,2016)
…………………………………………………………………………………….
System.out.print("Enter year: "); int y = S.nextInt();
System.out.print("Enter month: "); int m = S.nextInt();
System.out.print("Enter day: "); int d= S.nextInt();
//3- set the value day of d1 to d
……………………………………………………..
//4-set the value month of d1 to m
………………………………………………………
//5- set the value year of d1 to y
…………………………………………………….
//6-increment d2
…………………………………
//7-print d1
…………………….
// 8-print only the month of d2
…………………………………….
//9-print only the year of d1
………………………………………..} }
/* JAVA Program to implement teh Date Class with constructor,
Accessor, mutator method and
all other methods*/
import java.util.*;
/*class Date */
class Date
{
//Data fields
private int day;
private int month;
private int year;
//default constructor
public Date()
{
day=0;
month=0;
year=0;
}
//Parameterised constructor toinitialise Date
object
public Date(int d,int m,int y)
{
day=d;
month=m;
year=y;
}
//Accessor method for day
int getDay()
{
return
day;
}
//Accessor method for
month
int getMonth()
{
return month;
}
//Accessor method for year
int getYear()
{
return year;
}
//Mutator method for day
void setDay(int d)
{
day=d;
}
//Mutator method for month
void setMonth(int m)
{
month=m;
}
//Mutator method for year
void setYear(int y)
{
year=y;
}
//increment() to increase day by
1
void increment()
{
day=day+1;
if(day>30) //if day>30, then month=month+1
and day=1
{
month=month+1;
day=1;
}
}
//This mwthod display the date with
slash.
void displaydetail()
{
System.out.println(month + "/" + day + "/" +
year);
}
}
/*Test class as provided in Question*/
public class datetest
{
public static void main(String[] args)
{
Scanner S = new Scanner(System.in);
// 1- define
object(d1) of date class without initialize value.
Date d1=new
Date();
// 2- define
object(d2) of date class with initialize value ( 23,5,2016)
Date d2=new
Date(23,5,2016);
System.out.print("Enter year: "); int y = S.nextInt();
System.out.print("Enter month: "); int m = S.nextInt();
System.out.print("Enter day: "); int d= S.nextInt();
//3- set the
value day of d1 to d
d1.setDay(d);
//4-set the
value month of d1 to m
d1.setMonth(m);
//5- set the value year of d1 to y
d1.setYear(y);
//6-increment d2
d2.increment();
//7-print d1
d1.displaydetail();
// 8-print only the month of d2
System.out.println("Month of d2 " + d2.getMonth());
//9-print only the year of d1
System.out.println("Year of d1 " + d1.getYear());
}
}
/////////////////////////////////////////////////////////
// OUTPUT
///////////////////////////////////////////////////////////

Write a class Date with: Three instance variable : day, month and year all of type...
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 )...
Write a class called Date that represents a date consisting of a year, month, and day. A Date object should have the following methods: public Date(int year, int month, int day) Constructs a new Date object to represent the given date. public void addDays(int days) Moves this Date object forward in time by the given number of days. public void addWeeks(int weeks) Moves this Date object forward in time by the given number of seven-day weeks. public int daysTo( Date...
JAVA programing Question 1 (Date Class): 5 Points Create a class Date with the day, month and year fields (attributes). Provide constructors that: A constructor that takes three input arguments to initialize the day, month and year fields. Note 1: Make sure that the initialization values for the day, month and year fields are valid where the day must be between 1 and 31 inclusive, the month between 1 and 12 inclusive and the year a positive number. Note 2:...
Complete the SpeedDating Class Write the method bodies for the 2 SpeedDating methods. Study the method declarations and Javadoc comments so that you understand what each method is supposed to do. To receive credit for a method, it must use one of the Java loops (your choice). Nested loops are not necessary. Write a Test Class for Your SpeedDating Class Your test class will have a main method that does the following: Create a SpeedDating object Since 1971, Columbus Day...
Examine the following class definition: public class Date private int year; private int month; private int day; public Date() { ...) public void set (int x, int y, int z) { ...) public int getYear() { ...) // returns year public int getMonth() { } // returns month public int get Day () { ...) // returns day //more methods here -- 1 Which of the following statements in a client program correctly prints out the day of the object...
Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...
(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...
You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...
Create a class called Date212 to represent a date. It will store the year, month and day as integers (not as a String in the form yyyymmdd (such as 20161001 for October 1, 2016), so you will need three private instance variables. Two constructors should be provided, one that takes three integer parameters, and one that takes a String. The constructor with the String parameter and should validate the parameter. As you are reading the dates you should check that...
Create a class Circle with one instance variable of type double called radius. Then define an appropriate constructor that takes an initial value for the radius, get and set methods for the radius, and methods getArea and getPerimeter. Create a class RightTriangle with three instance variables of type double called base, height, and hypotenuse. Then define an appropriate constructor that takes initial values for the base and height and calculates the hypotenuse, a single set method which takes new values...