473,441 Members | 1,629 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,441 software developers and data experts.

Need help very urgent with a program implementing day class

Hi guys I'm new to java and have no idea how what to do with this problem. If someone can help me get started with this program it'll be really appriciated. 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
Sep 10 '08 #1
5 5302
Laharl
849 Expert 512MB
What do you have so far? We're not going to do your work for you, but we will help with specific questions about code you've written.
Sep 10 '08 #2
Nepomuk
3,112 Expert 2GB
Hi madman228! Welcome to bytes.com!

It's great to have you here!

When you post, please always keep to the Posting Guidelines and when you post code, please post it in [code] ... [/code] tags.

About your question:
Have you ever used more than one class in Java? For example, you would have your main class:
Expand|Select|Wrap|Line Numbers
  1. public class Main {
  2.   public static void main(String[] args) {
  3.     // Your code here
  4.   }
  5. }
and then a second class that I'll just call Mumble for the moment:
Expand|Select|Wrap|Line Numbers
  1. public class Mumble {
  2.   // Global variables here
  3.   public Mumble(...) {
  4.     // This is the constructor. It is called every time you create a new Object from the class "Mumble".
  5.   }
  6.   // More of your code here
  7. }
Now, you should create a new class called Day, right? And what should that class do? Oh yes:
The class Day should store the day, such as Sun for
Sunday.
So, there should be a variable to save the day. (No, not like a superhero! ^^) What datatype would "Sun" be? I'd say: String. So, it would look something like this:
Expand|Select|Wrap|Line Numbers
  1. public class Day {
  2.   private String day;
  3.   // More variables here
  4.   public Day(...)
  5.   {
  6.     // variable initialisations here
  7.   }
  8.   // More stuff here
  9. }
Now, to set a day, you'll need a so called "setter". That's a method normally called something like setValue(datatype variable) (e.g. setDay(String myDay)) which will change the global variable value (here: day). Printing and returning (or "getting" -> a "getter" function) the current day aren't difficult either.

Returning the previous / next day is a bit more complicated. Basically, I see two methods. Either you check which the next day would be by means of a few if clauses:
Expand|Select|Wrap|Line Numbers
  1. if(day.equals("Sun")      return "Mon";
  2. else if(day.equals("Mon") return "Tue";
  3. else ...
and then call that several times for question f), or you have an array of all days and save the day's number in your class as well:
Expand|Select|Wrap|Line Numbers
  1. public class Day {
  2.   private String day;
  3.   private int dayOfTheWeek;
  4.   public String[] days = {"Sun", "Mon", ...};
  5.   // ...
  6. }
and then go through the array with that integer. You can also use that for part f).

Now, you'll have to do the writing of those classes yourself, but what I've given you should be more than enough to get you started.

Otherwise, I'll just wish you the best and hope you enjoy being part of bytes.com!

Greetings,
Nepomuk
Sep 10 '08 #3
JosAH
11,448 Expert 8TB
Just use a GregorianCalendar class and be done with it.

kind regards,

Jos
Sep 10 '08 #4
Nepomuk
3,112 Expert 2GB
Just use a GregorianCalendar class and be done with it.
As it says
Design and implement the class Day...
I doubt that using the GregorianCalendar would be acceptable. ^^ (It's another of these "Do blablabla without using beeeeeep..." tasks.) However, if the OP ever wants to actually use something like that, the GregorianCalendar would certainly be a good idea.

Greetings,
Nepomuk
Sep 10 '08 #5
I'm from Kuwait ..

This is the first time that I register in English site .. but I like this site because I realy got benefit from this site ..

I'm in Kuwait University .. Our Dr. gaves us like this program ::::

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 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 returned is Friday. Similarly, if the 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.



.......................................


and I didn't understand classes any more ..

It will be submitted after two days from naw and I realy don't know haw to solve it :(

can any body help me please ? :l
Dec 25 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

55
by: Alex | last post by:
Hello people, The following is not a troll but a serious request. I found myself in a position where I have to present a Pro/Con list to management and architects in our company with regard to...
3
by: chris | last post by:
Hallo, I am in need of a replacement for the Microsoft Visual Studio .NET. The reason is quiet simple. I develop forms which are used on different microsoft windows platform, and one...
33
by: dembla | last post by:
Hey Frnds can anyone help me in this i need a program in 'c' PROGRAM to print NxN Matrix 9 1 8 1 2 3 2 7 3 as 4 5 6 6 4 5 7 8 9 in sorted form
1
by: Charles | last post by:
Hi all, I need C# code for Implementing MD5 Algorithm.. Hope all would have heard of MD5 Algorith... Does any one have the C# coding for that Algorithm.. please Send... ITs URgent..... Thanks...
1
by: Charles | last post by:
Hi all, I need C# code for Implementing MD5 Algorithm.. Hope all would have heard of MD5 Algorith... Does any one have the C# coding for that Algorithm.. please Send... ITs URgent..... Thanks...
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
3
by: Noremac | last post by:
My google skills must be dwindling. I am trying to determine how in ASP.NET 2.0 I can get the ReturnUrl querystring variable in Forms Authentication to contain the absolute url. Just like others...
1
by: raghavshastri | last post by:
You are to write a C++ program to perform a statistical analysis of the blobs in an image. The image will be a grayscale image in PGM format for simplicity. Here is a sample PGM image with 10...
1
by: javabeginner123 | last post by:
i have a java prob, and i have to solve it fast, but i'm just getting to know it, so plz help me solve it with full code completed, thanks so much. the prob is to create a monter fight and there is...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.