Results 1 to 5 of 5
Thread: Need some tips.
- 02-27-2009, 10:08 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 27
- Rep Power
- 0
Need some tips.
Hi I have some problems with express my self. I doing this kind of exercise: design the class Day that implements the day of week in a program. The program should store the day and be able to perform the following operation of type Day
a. setDayOfWeek must not permit a change to an invalid value
b. printDay prints the day from the receiving instance.
c. getDayOfWeek returns the value of the dayOfWeek
d. nextDay returns the String value of the day that comes after the receiving object.
e. previousDay returns the String value of the day that comes before the receiving object.
f. forwardDays returns the value of the day some integer days after the receiving object. What happens if the input parameter is negative?
g. Default Day constructor sets dayOfWeek to Sunday. Day constructors must ensure that only valid day names are set.
I'm interest if the program what I did to point of my knowledge it's good and I need some tips for the nextDay, previousDay and forwardDays. I think that I have to use a if statements.
Thanks in advance
This is what i did:
package chapt08;
public class Day {
private static final String[] DAYS_OF_WEEK = { "Sunday", "Monday",
"Tusday", "Wednesday", "Thursday", "Friday", "Saturday" };
private String dayOfWeek;
public Day() {
dayOfWeek = DAYS_OF_WEEK[0];
}
public Day(String aString) {
this();
setDayOfWeek(aString);
}
public void setDayOfWeek(String dayName){
for (int i = 0; i < DAYS_OF_WEEK.length; i++) {
if(dayName.equals(DAYS_OF_WEEK[i]));
}
dayOfWeek = dayName;
}
public void printDay(){
System.out.println("The day is " + dayOfWeek);
}
public String getDayOfWeek() {
if (dayOfWeek == Sunday)
System.out.println("Next Day is MONDAY");
return dayOfWeek;
}
public previousDay(){
}
public forwardDays(){
if (dayOfWeek
}
}
- 02-27-2009, 10:20 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
forwardDays , no matter is positive or not, % 7 to get the reminder, "add" the reminder to the day
- 02-27-2009, 12:54 PM #3
== vs equals
Don't use "==" to compare strings.... always use the string .equals() method:Java Code:if (dayOfWeek == Sunday)
Luck,Java Code:if (dayOfWeek.equals("Sunday"))
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-27-2009, 02:28 PM #4
Member
- Join Date
- Feb 2009
- Posts
- 27
- Rep Power
- 0
Thanks, but what to do for a forward day. I Do I have to set other array for forwardDays?
-
Similar Threads
-
tips on crystal report
By kishore in forum New To JavaReplies: 1Last Post: 01-20-2009, 03:23 AM -
give interview tips....
By thirumurugan.sethu in forum New To JavaReplies: 4Last Post: 10-03-2008, 11:45 AM -
I need some advice and tips about my code...
By sukatoa in forum Advanced JavaReplies: 3Last Post: 06-23-2008, 07:29 PM -
First project, need some tips..
By Komala_aradhya in forum New To JavaReplies: 1Last Post: 08-03-2007, 01:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks