Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

package day;

import java.util.Scanner; public class Day { final static int SUNDAY = 0; final static int MONDAY = 1; final static int TUESDAY = 2; final static int WEDNESDAY = 3; final static int THURSDAY = 4; final static int FRIDAY =5; final static int SATURDAY = 6; public int currentday; public Day(int day) { this.currentday = day; } //a) set day public void setDay(int currentday) { this.currentday = currentday; } //b) print the day public void printDay () { System.out.println(this.toString()); } //c)return the day public int returnDay () { return currentday; } //d) return the next day public int returnTomorrow () { int tomorrow; tomorrow= currentday +1; return tomorrow; } //e) return the previous day public int returnYesterday () { int yesterday=currentday; if(yesterday >0) { yesterday = currentday -1; } else { yesterday= 6; } return yesterday; } //f) calculate and return public int daysAdded(int daysadd) { int newday = currentday + daysadd; newday %= 7; return newday ; } public String dayToString () { switch(this.currentday) { case MONDAY: return "Monday"; case TUESDAY: return "Tuesday"; case WEDNESDAY: return "Wednesday"; case THURSDAY: return "Thursday"; case FRIDAY: return "Friday"; case SATURDAY: return "Saturday"; case SUNDAY: return "Sunday"; } return ""; } public static void main(String[] args) { // TODO code application logic here Scanner scanner = new Scanner(System.in); System.out.println("Original day: "); Day mon = new Day(MONDAY); System.out.println(); mon.printDay(); System.out.println("Tomorrow will be: "); mon.returnTomorrow(); System.out.println("Yesterday was: "); mon.returnYesterday(); System.out.println("In 3 days it will be :"); mon.daysAdded(3); } }

This is what I have so far, I've tried debugging but no dice. What am I doing wrong? Also some tips on my coding would be greatly appreciated!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions

Question

Understand the importance of strategic HR planning.

Answered: 1 week ago

Question

=+C&B (especially taxation) laws, regulations, and practices?

Answered: 1 week ago