In Java, 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 the type of day:
You will need two programs:
package DaysOfWeek ;
public class Day
{
/*all the days are declared " final static" so that they can not be
changed in the entire program */
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;
public int ourDay;
/* a. set the day */
public void setDay(int day)
{ourDay = day;}
/* c. return the day */
public Day(int ourDay)// constructor,because we want to execute it
always when the object is created
{this.ourDay = ourDay;} // this is keyword is used to differentiate
local variable from global
/* print the day */
public int getDay()
{return ourDay;}
/*calcotate the day*/
public int followingDay()
{
if (ourDay == SAT)
{return SUN;}
else {ourDay = (ourDay + 1) % 7;}
return ourDay;
}
/*return the previous day*/
public int previousDay()
{
if (ourDay == 0)
{return SAT;}
else {ourDay = (ourDay - 1) % 7;}
return ourDay;
}
/*return the future day*/
public int futureDay(int ourDays)
{return ((ourDay + ourDays) -1 ) % 7;}
public String toString() //these function is written to write
the full name of the day
{
switch (this.ourDay)
{
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 "" ;
}
}
A program to test the various operations on the class Day
import DaysOfWeek.*;
class Implement {
public static void main(String[] args) {
System.out.println("YOUR OPERATIONS ON THE DAY ARE HERE!");
Day myDay = new Day(1);
System.out.print("The current day: " + myDay);
System.out.println();
myDay.setDay(myDay.previousDay());
System.out.print("The previous day: " + myDay);
System.out.println();
myDay.setDay(myDay.followingDay());
myDay.setDay(myDay.followingDay());
System.out.print("The next day: " + myDay);
System.out.println();
myDay.setDay(myDay.futureDay(10));
System.out.print("10 days later: " + myDay);
System.out.println();
}
}
/* output:
The current day: Sunday
The previous day: Saturday
The next day: Monday
10 days later: Wednesday
Completed with exit code: 0
*/
In case of any doubt, you can write in the comments :)
In Java, design and implement the class day that implements the day of the week in...
Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public: static string weekDays[7]; void print() const; string nextDay() const; string prevDay() const; void addDay(int nDays); void setDay(string d); string getDay() const; dayType(); dayType(string d); private: string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...
c++ programming language Instructions In this exercise, you will design the class memberType. Each object of memberType can hold the name of a person, member ID, number of books bought, and amount spent. Include the member functions to perform the various operations on the objects of memberType—for example, modify, set, and show a person’s name. Similarly, up-date, modify, and show the number of books bought and the amount spent. Add the appropriate constructors. Write the definitions of the member functions...
[Java] We have learned the class Clock, which was designed to implement the time of day in a program. Certain application in addition to hours, minutes, and seconds might require you to store the time zone. Please do the following: Derive the class ExtClock from the class Clock by adding a data member to store the time zone. Add necessary methods and constructors to make the class functional. Also write the definitions of the methods and constructors. Write a test...
PLEASE DO IN PSEUDOCODE ; Design and implement a programming (name it NextMeeting) to determine the day of your next meeting from today. The program reads from the user an integer value representing today’s day (assume 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday, etc…) and another integer value representing the number of days to the meeting day. The program determines and prints out the meeting day. Format the outputs following the sample runs below. Sample...
Write a Java program with the following requirements: Rectangle that implements Shape2D - instance variables height, width Block that implements Shape3D - instance variables height, width, depth Add appropriate parameterized constructors for each class. Implement the abstract methods to make each class a Shape2D, Shape3D, or both. Make the main method use each of these to print out the area of a rectangle, and the area and volume of a block.
Design "MyWeek" class: (1) Data members: the class contains one private data field weekList. "weekList" has datatype of ArrayList, which will contain String objects of week/weekend days. There are no duplicated days in the list. Valid days are "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun". The weekList is not necessarily to be ordered (2) Constructors The instance of MyWeek can be constructed with (a) no argument (initialized weekList to empty), or (b) with one String argument which is one valid...
Description: This project focuses on creating a Java class, Date.java, along with a client class, DateCleint.java, which will contain code that utilizes your Date.java class. You will submit both files (each with appropriate commenting). A very similar project is described in the Programming Projects section at the end of chapter 8, which you may find helpful as reference. Use (your own) Java class file Date.java, and a companion DateClient.java file to perform the following: Ask user to enter Today’s...
Using the function you wrote in part 3a (refer to the bottom), write another function that, given the number of days in the month, and the day that the month starts on, the number of days that Inky Blinky Pinky and Clyde will get to play pinball in that month. The function provided will increment the day of the week to the next correct day. Function written in 3a): def pinball(dayOfWeek, dayOfMonth) : if dayOfMonth % 4 ==0: return "Pinky"...
Need help implementing this Java class (Science: day of the week) Zeller's congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is h = (q + (26 * (m + 1)) / 10 + k + k / 4 + j / 4 + 5 * j) % 7 where h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday). q...
Write a Java class that implements the concept of Coins, assuming the following attributes (variables): number of quarters, number of dimes, number of nickels, and number of pennies. Include two constructors (non-argument constructor that assigns 1 to each coin, and another constructor that takes necessary arguments to create an object), needed getter and setter methods, method toString (to print coins objects in a meaningful way), and method equals (to compare two coins objects based on number of coins). Also include...