[Show all top banners]

Slackdemic
Replies to this thread:

More by Slackdemic
What people are reading
Subscribers
:: Subscribe
Back to: St. Xavier's and St. Mary's Refresh page to view new replies
 Java Help

[Please view other pages to see the rest of the postings. Total posts: 37]
PAGE:   1 2 NEXT PAGE
[VIEWED 20860 TIMES]
SAVE! for ease of future access.
The postings in this thread span 2 pages, View Last 20 replies.
Posted on 09-28-06 6:38 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Any serious Java people in here? For some reasons, the following code doesn't work for leap year. Any help/suggestion is appreciated.

The classes are Date and TestDate:


public void addMonth(int m)
{
month = month + m;
if (month>12)
{
month-=12;
addYear(1);
}

}

public boolean isLeap(int y)
{
if (y%100==0)
{
if (y%400==0)
return true;
else
return false;
}
else if (y%4==0)
return true;
return false;
}

public void addDay(int d)
{
day = day + 1;
if (day>28)
{
if (month==2)
{
if (isLeap(year))
{
if (day>29)
{
day-=29;
addMonth(1);
return;
}
else
return;
}
day-=28;
addMonth(1);
}
else
if ((month==4||month==6||month==9||month==11)&&day>30)
{
day-=30;
addMonth(1);
}
else
if (day>31)
{
day-=31;
addMonth(1);
}
}
}
public void addYear(int y)
{
{
year += y;
if (month==2)
if (day==29)
if (!isLeap(year))
{
setMonth(3);
setDay(1);
}
}

}

public String toString()
{
String d=""+day,m=""+month,y=""+year;
if (d.length()<2)
d="0"+d;
if (m.length()<2)
m="0"+m;
while (y.length()<4)
y="0"+y;
return m + "/"+ d + "/" + y; //return the value of
} //concatenated month, day, and year
}
 
Posted on 09-28-06 8:44 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

public boolean isLeap(int y){
if(y%4==0)
return true;
else
return false;
}



************


public void addDay(int d) {
day=d+1;
if(day > 28)
{
if((month==2)&&(isLeap(year))){
day-=28;
addMonth(1);
}
else if((month==2)&&(!isLeap(year))){
day-=28;
addMonth(1);
}
...
Leap year is always divisible by 4. I don't know why you are using y%400 and y%100.
 
Posted on 09-28-06 8:47 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Slackdemic, the definition of leap year is wrong in your isLeap(int y) method.

1. Every year divisible by 4 is a leap year.
2. But every year divisible by 100 is NOT a leap year
3. Unless the year is also divisible by 400, then it is still a leap year.
 
Posted on 09-28-06 8:52 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Yes, I also got that from this website, too. Thanks!

www.timeanddate.com/date/leapyear.html
 
Posted on 09-28-06 8:54 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Don't worry. Help is on the way. I just dialed 991.
 
Posted on 09-28-06 8:59 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Didn't mean to be rude earlier, guys, but what I did is good:

Every year divisible by 4 is a leap year.
But every year divisible by 100 is NOT a leap year
Unless the year is also divisible by 400, then it is still a leap year.

The year that is divisible by 100 is not leap year UNLESS it is divisible by 400! See there? That's exactly what I did. See the if loop:

Posted on 09-28-06 6:38 PM Reply | Notify Admin
ny serious Java people in here? For some reasons, the following code doesn't work for leap year. Any help/suggestion is appreciated.

The classes are Date and TestDate:


public void addMonth(int m)
{
month = month + m;
if (month>12)
{
month-=12;
addYear(1);
}

}

public boolean isLeap(int y)
{
if (y%100==0)
{
if (y%400==0)
return true; -----------> means, if it is divisible by 100 AND 400, return true
else
return false; ------>if it is divisible ONLY by 100....return false..
}
else if (y%4==0)
return true;
return false;
}
 
Posted on 09-28-06 9:01 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

If you are really trying to figure it out, I will say you, have quite a sense of humor. If you are just playing, stop it, I am stressed!
 
Posted on 09-28-06 9:01 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

but you haven't included all conditions...

everything should be inside one if condition..in nested form
starting with yr%4
 
Posted on 09-28-06 9:01 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

And that message is for (somebody's) lovebird.
 
Posted on 09-28-06 9:06 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Sajhauser:

I think there are two conditions for the leap year:

One, the year that is divisible by 4 (which is at last).
Two, the year that is divisible by 100 AND (then) 400.

I don't think they have to be within one pair of braces...or maybe I can make it that way, but I don't think that is the problem...!
 
Posted on 09-28-06 9:08 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

argggg....
check out here
http://users.dickinson.edu/~braught/courses/cs132f01/classes/code/LeapYear.src.html

you haven't really followed the definition kyaaaaaa!
 
Posted on 09-28-06 9:16 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hyatteri! that is just the definition. I think I have "really" followed the dang definition. I know how to google, too, Sajhauser (:P)

Anyway, thanks, let me play with it...I am kind of afraid to post all my codes for you all so you would know what exactly I am talking...This is one of the big assignments that is due tomorrow, and I assume there are other guys from my class that know how to google like you and I. :P
 
Posted on 09-28-06 9:25 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

{
f (y%100==0)
{
if (y%400==0)
return true; -----------> means, if it is divisible by 100 AND 400, return true
else
return false; ------>if it is divisible ONLY by 100....return false..
}
else if (y%4==0)
return true;
return false;
}

--well , as per my reading, you should have following conditions

1) the year is divisible by 4 (NOT the sufficient condition, so you have to look into)
(a) is the year divisible by 4 and not by 100? if yes, it's a leap year else not
(b) is the year divisible by 4 and by 100? (NOT the sufficient condition, so you have to look into)
(i)is the year also divisible by 400 as well? if yes, it's a leap year, else not

obviously, it's not a leap yr if its not divisible by 4.

sajhauser is right and she provided the link as well. you should have gone through it :P

LooTe
 
Posted on 09-28-06 9:27 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

you haven't applied the dang logic behind the definition!
you have made assumption as if there are only 2 condition, when, infact there are 3..so you have to first check by 4. the definition first tells you to check with 4, right?

// Is theYear Divisible by 4?
if (theYear % 4 == 0) {

// Is theYear Divisible by 4 but not 100?
if (theYear % 100 != 0) {
System.out.println(theYear + " is a leap year.");
}
// Is theYear Divisible by 4 and 100 and 400?
else if (theYear % 400 == 0) {
System.out.println(theYear + " is a leap year.");
}
// It is Divisible by 4 and 100 but not 400!
else {
System.out.println(theYear + " is not a leap year.");
}
}
// It is not divisible by 4.
else {
System.out.println(theYear + " is not a leap year.");
}
 
Posted on 09-28-06 9:48 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

You are right guys! I have been misplacing 400, 100, and 4.

The program is whole lot more than that, but Thanks!!! You all rock!....Wish me good luck!
 
Posted on 09-28-06 10:25 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Good luck! and don't pre-judge me okay!
 
Posted on 09-28-06 10:42 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I was not "pre-judging you, Sajhauser...My problem was actually the wrong output which didn't have much connection with the right or wrong definition of leap year. And, I was stressed.

It was my understanding that was not correct. Maybe, I am little slow. :P Maybe, really, at times.

The leap year is something that is divisible by 4 BUT NOT divisible by 100. But anything that is divisible 100 and 400 is still leap year. There are three conditions there:

1. Anything divisible by 4 is leap year.
2. BUT if it is not leap year if it is divisible by 100.
3. It is leap year if it is divisible by 100 and 400.

This is what I did and it went well.
{
/*if(y % 4 ==0 ) { // divisible by 4
if(y % 400 ==0) //leap year is
{
if(y %100 ==0)
{
return false;
}
return true;
}
return true;
}
return false;
}*/

Coincidentally, I get the right output, too. And, I am done!

Thank you!
 
Posted on 09-28-06 10:58 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 









Error Occurred While Processing Request









The web site you are accessing has experienced an unexpected error.

Please contact the website administrator.

















The following information is meant for the website developer for debugging purposes.



Error Occurred While Processing Request






















































































Datasource spradhan-sajhadb could not be found.






 



The error occurred in D:\inetpub\ramjham\fixunicode\fixunicode.cfm: line 5


























































































3 : </cfquery> 
4 : <cfif getthread.recordcount eq 0>error<cfelse>
5 : <cfoutput>#getthread.threadname#</cfoutput></cfif><cfelseif isdefined("url.articleid")><cfquery username="spradha_sanman" password="sajhasql" name="getthread" datasource="spradhan-sajhadb" dbtype="ODBC">
6 : select message from tblarticles where articleid = '#url.articleid#'
7 : </cfquery>

























DATASOURCE   spradhan-sajhadb



Resources:




















Browser   ColdFusion
Remote Address   74.86.124.120
Referrer  
Date/Time   19-Nov-09 03:14 AM














Stack Trace




at cffixunicode2ecfm1866134693.runPage(D:\inetpub\ramjham\fixunicode\fixunicode.cfm:5)




at cffixunicode2ecfm1866134693.runPage(D:\inetpub\ramjham\fixunicode\fixunicode.cfm:5)





java.sql.SQLException: Datasource spradhan-sajhadb could not be found.
	at coldfusion.sql.DataSrcImpl.validate(DataSrcImpl.java:95)
	at coldfusion.sql.SqlImpl.validate(SqlImpl.java:279)
	at coldfusion.tagext.sql.QueryTag.doStartTag(QueryTag.java:467)
	at cffixunicode2ecfm1866134693.runPage(D:\inetpub\ramjham\fixunicode\fixunicode.cfm:5)
	at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:196)
	at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:370)
	at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
	at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:279)
	at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
	at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
	at coldfusion.filter.PathFilter.invoke(PathFilter.java:86)
	at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
	at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:74)
	at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
	at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
	at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
	at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
	at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
	at coldfusion.CfmServlet.service(CfmServlet.java:175)
	at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
	at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
	at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
	at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
	at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
	at jrun.servlet.FilterChain.service(FilterChain.java:101)
	at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
	at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
	at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
	at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
	at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
	at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
	at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
	at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
	at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)






View/Share this post only
 
lootekukur
Posted on 09-28-06 11:03 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?      









Error Occurred While Processing Request









The web site you are accessing has experienced an unexpected error.

Please contact the website administrator.

















The following information is meant for the website developer for debugging purposes.



Error Occurred While Processing Request






















































































Datasource spradhan-sajhadb could not be found.






 



The error occurred in D:\inetpub\ramjham\fixunicode\fixunicode.cfm: line 5


























































































3 : </cfquery> 
4 : <cfif getthread.recordcount eq 0>error<cfelse>
5 : <cfoutput>#getthread.threadname#</cfoutput></cfif><cfelseif isdefined("url.articleid")><cfquery username="spradha_sanman" password="sajhasql" name="getthread" datasource="spradhan-sajhadb" dbtype="ODBC">
6 : select message from tblarticles where articleid = '#url.articleid#'
7 : </cfquery>

























DATASOURCE   spradhan-sajhadb



Resources:




















Browser   ColdFusion
Remote Address   74.86.124.120
Referrer  
Date/Time   19-Nov-09 03:11 AM














Stack Trace




at cffixunicode2ecfm1866134693.runPage(D:\inetpub\ramjham\fixunicode\fixunicode.cfm:5)




at cffixunicode2ecfm1866134693.runPage(D:\inetpub\ramjham\fixunicode\fixunicode.cfm:5)





java.sql.SQLException: Datasource spradhan-sajhadb could not be found.
	at coldfusion.sql.DataSrcImpl.validate(DataSrcImpl.java:95)
	at coldfusion.sql.SqlImpl.validate(SqlImpl.java:279)
	at coldfusion.tagext.sql.QueryTag.doStartTag(QueryTag.java:467)
	at cffixunicode2ecfm1866134693.runPage(D:\inetpub\ramjham\fixunicode\fixunicode.cfm:5)
	at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:196)
	at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:370)
	at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
	at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:279)
	at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
	at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
	at coldfusion.filter.PathFilter.invoke(PathFilter.java:86)
	at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
	at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:74)
	at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
	at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
	at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
	at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
	at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
	at coldfusion.CfmServlet.service(CfmServlet.java:175)
	at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
	at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
	at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
	at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
	at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
	at jrun.servlet.FilterChain.service(FilterChain.java:101)
	at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
	at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
	at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
	at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
	at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
	at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
	at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
	at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
	at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)






View/Share this post only
 
sajhauser
Posted on 09-28-06 11:25 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?      









Error Occurred While Processing Request









The web site you are accessing has experienced an unexpected error.

Please contact the website administrator.

















The following information is meant for the website developer for debugging purposes.



Error Occurred While Processing Request






















































































Datasource spradhan-sajhadb could not be found.






 



The error occurred in D:\inetpub\ramjham\fixunicode\fixunicode.cfm: line 5


























































































3 : </cfquery> 
4 : <cfif getthread.recordcount eq 0>error<cfelse>
5 : <cfoutput>#getthread.threadname#</cfoutput></cfif><cfelseif isdefined("url.articleid")><cfquery username="spradha_sanman" password="sajhasql" name="getthread" datasource="spradhan-sajhadb" dbtype="ODBC">
6 : select message from tblarticles where articleid = '#url.articleid#'
7 : </cfquery>

























DATASOURCE   spradhan-sajhadb



Resources:




















Browser   ColdFusion
Remote Address   74.86.124.120
Referrer  
Date/Time   19-Nov-09 03:09 AM














Stack Trace




at cffixunicode2ecfm1866134693.runPage(D:\inetpub\ramjham\fixunicode\fixunicode.cfm:5)




at cffixunicode2ecfm1866134693.runPage(D:\inetpub\ramjham\fixunicode\fixunicode.cfm:5)





java.sql.SQLException: Datasource spradhan-sajhadb could not be found.
	at coldfusion.sql.DataSrcImpl.validate(DataSrcImpl.java:95)
	at coldfusion.sql.SqlImpl.validate(SqlImpl.java:279)
	at coldfusion.tagext.sql.QueryTag.doStartTag(QueryTag.java:467)
	at cffixunicode2ecfm1866134693.runPage(D:\inetpub\ramjham\fixunicode\fixunicode.cfm:5)
	at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:196)
	at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:370)
	at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
	at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:279)
	at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
	at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
	at coldfusion.filter.PathFilter.invoke(PathFilter.java:86)
	at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
	at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:74)
	at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
	at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
	at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
	at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
	at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
	at coldfusion.CfmServlet.service(CfmServlet.java:175)
	at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
	at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
	at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
	at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
	at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
	at jrun.servlet.FilterChain.service(FilterChain.java:101)
	at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
	at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
	at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
	at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
	at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
	at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
	at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
	at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
	at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)






View/Share this post only
 


PAGE:   1 2 NEXT PAGE
Check Archived entries on this thread
Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 30 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
I hope all the fake Nepali refugee get deported
To Sajha admin
All the Qatar ailines from Nepal canceled to USA
MAGA मार्का कुरा पढेर दिमाग नखपाउनुस !
Travel Document for TPS (approved)
MAGA and all how do you feel about Trumps cabinet pick?
Those who are in TPS, what’s your backup plan?
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters