
1- design and implement a class datatype that implement the day of the week in the program.the class datatype should store the day, such as sun for sunday. the programe should be able to perform the following operations on an object of type datatype set the day / print the day /return the day/return the next day /return the previous day/ calculate and return the day by adding certain days to the current day.for example if the current day is monday and we add 4 days .the day to be returnd is friday.similarly, if today is tuesday and we add 13 days, the day to be returned is monday/ add the oppropriate constructors.
2-write the definition of the function to implement the operations for the class datatype. alse write aprogram to test various operations on this class.

Here is the Java code:
public class DayType{
final static int SUN = 0;
final static int MON = 1;
final static int TUE = 2;
final static int WED = 3;
final static int THU = 4;
final static int FRI= 5;
final static int SAT = 6;
private int day;
public DayType(int day) {
this.day = day;
}
public void setDay(int day){
this.day = day;
}
public int getDay() {
return day;
}
public void print() {
System.out.println(this.toString());
}
public int nextDay(){
int next;
next = day + 1;
return next;
}
public int previousDay(){
int prevDay;
prevDay = day - 1;
return prevDay;
}
public int addDays(int days) {
return (day + days) % 7;
}
public String toString() {
switch (this.day) {
case SUN:
return "Sunday";
case MON:
return "Monday";
case TUE:
return "Tuesday";
case WED:
return "Wednesday";
case THU:
return "Thursday";
case FRI:
return "Friday";
case SAT:
return "Saturday";
}
return "";
}
public static void main(String[] args) {
System.out.println("******Test Day******");
System.out.println();
System.out.print("Set day: ");
DayType d = new DayType(SUN);
d.print();
System.out.print("Next day: ");
d.setDay(d.nextDay());
d.print();
System.out.print("Previous day: ");
d.setDay(d.previousDay());
d.print();
System.out.print("After 5 days: ");
d.setDay(d.addDays(5));
d.print();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.