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

Using jGrasp and the Software Development Kit, write a program in response to th

ID: 3537753 • Letter: U

Question

Using jGrasp and the Software Development Kit, write a program in response to the following prompt:

Design and implement the class Day that implements the day of the week in a program. The class Day should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of type Day:

A. Set the day.

B. Print the day.

C. Return the day.

D. Return the next day.

E. Return the previous day.

F. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add four days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.

G. Add the appropriate constructors.

H. Write the definitions of the methods to implement the operations for the class Day, as defined in A through G.

I. Write a program to test various operations on the class Day.

Explanation / Answer

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(SUNDAY); 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(); } }

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