473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Day Class

Hi guys I'm new to java and have no idea how what to do with this problem. If someone can tell me weather I'm on the right track or not that will be great. Any help will be appreciated. The problem is:

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 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 a day by adding # of days to current day.
(ie. if current day is Monday and we add 3 days then new day
is Thursday)
g) Add the appropiate constructors // default & set constructors
h) Write the definitins of the methods to implement the
operations for the class Day as defined in a - g
i) Write a program to test various operations on the class Day

This is what i have so far:

Expand|Select|Wrap|Line Numbers
  1. public class Day {
  2.     private int dow;
  3.     int num = 10;
  4.  
  5.     private static String daysOfWeek[] = { "Sunday", "Monday", "Tuesday",
  6.             "Wednesday", "Thursday", "Friday", "Saturday" };
  7.  
  8.     public Day(String strDay){
  9.         for (int i = 0; i < Day.daysOfWeek.length; i++)
  10.             if (strDay.equalsIgnoreCase(Day.daysOfWeek[i])){
  11.                 this.dow = i;
  12.                 return;
  13.             }
  14.         System.err.println("Bad Data in Constructor");
  15.         dow = 0;
  16.     }
  17.  
  18.     public Day(int dow) {
  19.         this.dow = dow;
  20.     }
  21.  
  22.     public int getDow() {
  23.         return dow;
  24.     }
  25.  
  26.     public void setDow(int dow) {
  27.         this.dow = dow;
  28.     }
  29.  
  30.     public int nextDay() {
  31.         int nextDay;
  32.         nextDay = this.dow + 1;
  33.         return nextDay;
  34.     }
  35.  
  36.     public int previousDay() {
  37.         int prevDay;
  38.         prevDay = this.dow - 1;
  39.         return prevDay;
  40.     }
  41.  
  42.     public int calcDay() {
  43.         int newDay;
  44.         this.dow = dow + num;
  45.         newDay = this.dow % 7;
  46.         return newDay;
  47.     }
  48. }
  49.  
Sep 13 '08 #1
2 8280
myusernotyours
188 100+
Hi
Read this...

Regards
Alex.
Sep 13 '08 #2
JosAH
11,448 Expert 8TB
Don't crosspost, it is considered rude.

kind regards,

Jos (moderator)
Sep 13 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
13
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes....
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
38
by: looping | last post by:
For Python developers around. >From Python 2.5 doc: The list of base classes in a class definition can now be empty. As an example, this is now legal: class C(): pass nice but why this...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
5
by: alan | last post by:
Hello world, I'm wondering if it's possible to implement some sort of class/object that can perform mapping from class types to strings? I will know the class type at compile time, like so:...
8
by: Mayur H Chauhan | last post by:
All, For my knowledge, if I declare Class as follow, then it thows compilation error. Protected Class Book End Class Even same for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.