GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Mar-2006, 01:02
coolio2005 coolio2005 is offline
New Member
 
Join Date: Mar 2006
Posts: 1
coolio2005 is on a distinguished road

Date problem


Hi, just got a question. I'm creating a program which is basically calculating quote for a carpet laying business. Basically, the person has a choice of vinyl and timber (this is user input). If a person chooses vinyl, then the installation cost is 2 business days after the quote (the quote is generated from the system date. so if i ran the program completely compiled today, then today is my quote), and if the choice is timber, then the installation for that is 2 weeks. So basically my program needs to determine which floor type the user wants, and if the quote is generated today (21/3/06) and its vinyl, my program must output “the installation date is on the 23/6/06). And yes, if the choice is timber, then it’ll just output the date from 2 weeks from now exactly. The timber side of things, I have completed fine, but I’m having a problem with the vinyl. Of course, if my quote is generated on Thursday, then the installation laying date should be (on the monday of the following day….as you can imagine, if its done on a Thursday, then it’ll Friday, Saturday, Sunday, Monday …of course, you do not count Saturday and Sunday as business days). So far my code is as follows.

JAVA Code:
static final SimpleDateFormat sdf = new SimpleDateFormat( "dd-MMM-yy" );
static final SimpleDateFormat blob = new SimpleDateFormat( "EEEE" );


(then in main I have this)

JAVA Code:
String dateString = sdf.format( new Date() );

if (FloorCover == 1)
cal.add(Calendar.DATE, 7);
else if (FloorCover == 2)
{

}
// FloorCover is basically just an integer value. So if user wants timber, then FloorCover is just 1, and if user wants vinyl, then FloorCover is 

2.

Of course, you can see my if statement for timber is done (and working), just not sure how to go about doing the vinyl part. Cheers


Just incase you need this, i have these packages.

JAVA Code:
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.*;
Last edited by LuciWiz : 21-Mar-2006 at 01:44. Reason: Please insert your Java code between [java] & [/java] tags
  #2  
Old 21-Mar-2006, 07:07
TurboPT's Avatar
TurboPT TurboPT is online now
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,280
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Date problem


First, you say in the beginning that timber is 2 weeks, but you only add 7 days?
JAVA Code:
cal.add(Calendar.DATE, 7); // 7, not 14 ??

Then for the other part, why not just add the 2 days, and then check the day of the new date? If the new date happens to be Saturday, add two more days, if Sunday add one more day:
JAVA Code:
else if (FloorCover == 2)
{
    cal.add(Calendar.DATE, FloorCover);
    
    int dayOfWeek = cal.get( cal.DAY_OF_WEEK );
    
    if ( dayOfWeek == Calendar.SATURDAY ) 
    {
         cal.add( Calendar.DATE, 2 ); // bump two more days to Monday.
    }
    else if ( dayOfWeek == Calendar.SUNDAY ) 
    {
         cal.add( Calendar.DATE, 1 ); // bump one more day to Monday.
    }
}
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Graphic problem in Unreal Tournament 2004 zerox Computer Software Forum - Games 10 09-Oct-2005 12:31
Runtime Problem involving "printf" in C Program supamakia C Programming Language 2 09-Oct-2005 10:09
a significant problem after installing Xp mohammad Computer Software Forum - Windows 10 09-Aug-2005 07:03
problem on typedef fwongmc C Programming Language 10 24-Dec-2004 03:54
Rookie problem with date format cave monkey MySQL / PHP Forum 4 18-Mar-2004 08:41

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:44.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.