Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6. In Programming Exercise 2, the class dateType was designed and implemented to

ID: 3675880 • Letter: 6

Question

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:
a. Set the month.
b. Set the day.
c. Set the year.
d. Return the month.
e. Return the day.
f. Return the year.
g. Test whether the year is a leap year.
h. Return the number of days in the month. For example, if the date is
3-12-2011, the number of days to be returned is 31 because there are
31 days in March.
i. Return the number of days passed in the year. For example, if the date is
3-18-2011, the number of days passed in the year is 77. Note that the
number of days returned also includes the current day.

j. Return the number of days remaining in the year. For example, if the
date is 3-18-2011, the number of days remaining in the year is 288.
k. Calculate the new date by adding a fixed number of days to the date. For
example, if the date is 3-18-2011 and the days to be added are 25, the
new date is 4-12-2011.
7. Write the definitions of the functions to implement the operations defined
for the class dateType in Programming Exercise 6.

----------------------------------------------
8. 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, 2003. Derive the class extDateType so
that the date can be printed in either form.

-------------------------------------------------------

what is the answer for Q 8 Plz??

Explanation / Answer

6(a-f)

public class Example{
public static void main(String args[]){
int month,day,year;
public void setMonth(int month){
return month;
}
public void setDay(int day){
return day;
}
public void setYear(int year){
return year;
}
Example ex=new Example();
setDay(9);
setMonth(3);
setYear(2016);
System.out.println(day);
System.out.println(month);
System.out.println(year);
}
}

6g)

import java.util.Scanner;

//simple program to check whether year is leap year or not

class Leap
{
public static void main(String[] argus)
{
int year;

Scanner input= new Scanner(System.in);
System.out.println("enter the year, which you want to know,is a leap year or not");
year= input.nextInt();
boolean leapyear= (year%4==0);

System.out.println("leapyear="+leapyear);
}
}

(or)

/*A leap year in the Gregorian calendar has an extra day for February.
*A leap year has 366 days.
*
* Algorithm to find a leap year
* -------------------------------
* if year % 400 = 0, leap year
* else if year % 100 = 0, not a leap year
* else if year % 4 = 0, leap year
* else, not a leap year
*/
public class LeapYearCalculator
{
public static void main(String args[])
{

/*Give the year here which needs to be checked for leap year
* (Assuming that year given here >= 1582 and corresponds to a year in Gregorian calendar)
*/
int year = 2000;

//Flag to store the test result
boolean isLeapYear = false;

if(year % 400 == 0)
{
isLeapYear = true;
}
else if (year % 100 == 0)
{
isLeapYear = false;
}
else if(year % 4 == 0)
{
isLeapYear = true;
}
else
{
isLeapYear = false;
}

//Output the test result
if(isLeapYear)
{
System.out.println("Year "+year+" is a Leap Year");
}
else
{
System.out.println("Year "+year+" is not a Leap Year");
}

}
}

6h)

import java.util.Calendar;

public class MainDays {
public static void main(String[] argv) throws Exception {
Calendar cal = Calendar.getInstance();
int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH); // 28
}
}

6i)

public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);

System.out.println("Enter today's date");
System.out.print("Year: ");
int todayYear = userInput.nextInt();
System.out.print("Month: ");
int todayMonth = userInput.nextInt();
System.out.print("Day: ");
int todayDay = userInput.nextInt();

// Java has January as month 0. Let's not require that the user know.
Calendar today = new GregorianCalendar(todayYear, todayMonth - 1,
todayDay);

System.out.println("Enter date");
System.out.print("Year: ");
int year1 = userInput.nextInt();
System.out.print("Month: ");
int month1 = userInput.nextInt();
System.out.print("Day: ");
int day1 = userInput.nextInt();
Calendar born = new GregorianCalendar(year1, month1 - 1, day1);

double diff = today.getTimeInMillis() - born.getTimeInMillis();
diff = diff / (24 * 60 * 60 * 1000); // hours in a day, minutes in a hour,
// seconds in a minute, millis in a
// second.
System.out.println(Math.round(diff));
}

6j)

public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);

System.out.println("Enter today's date");
System.out.print("Year: ");
int todayYear = userInput.nextInt();
System.out.print("Month: ");
int todayMonth = userInput.nextInt();
System.out.print("Day: ");
int todayDay = userInput.nextInt();

// Java has January as month 0. Let's not require that the user know.
Calendar today = new GregorianCalendar(todayYear, todayMonth - 1,
todayDay);

System.out.println("Enter date");
System.out.print("Year: ");
int year1 = userInput.nextInt();
System.out.print("Month: ");
int month1 = userInput.nextInt();
System.out.print("Day: ");
int day1 = userInput.nextInt();
Calendar born = new GregorianCalendar(year1, month1 - 1, day1);

double diff = today.getTimeInMillis() - born.getTimeInMillis();
diff = diff / (24 * 60 * 60 * 1000); // hours in a day, minutes in a hour,
// seconds in a minute, millis in a
// second.
  
int rem=365-diff;
System.out.println(Remaining days);
System.out.println(rem);
}

6k)

class days
public static void main(String[] args) {
Calendar calendar = new GregorianCalendar(/* remember about timezone! */);
calendar.setTime(date);
calendar.add(Calendar.DATE, 30);
date = calendar.getTime();
}

8)

import java.time.ZonedDateTime;
import java.time.ZonedDateTime;
public class Main {
public static void main(String[] args) {
ZonedDateTime currentTime = ZonedDateTime.now();
System.out.printf("%tA %<tB %<te, %<tY %n", currentTime);
System.out.printf("%TA %<TB %<te, %<tY %n", currentTime);
System.out.printf("%tD %n", currentTime);
System.out.printf("%tF %n", currentTime);
System.out.printf("%tc %n", currentTime);
System.out.printf("%Tc %n", currentTime);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote