how to display one image per day from an array?

Reply

Join Date: Feb 2007
Posts: 14
Reputation: Thendral is an unknown quantity at this point 
Solved Threads: 0
Thendral Thendral is offline Offline
Newbie Poster

how to display one image per day from an array?

 
0
  #1
Apr 28th, 2007
Hai..

I need to display one image per day from an array depending upon the day in jsp/servlet.

Intially i am having 5 images in an array.

Then i want to display

sunday --- 1st image
monday--- 2nd image
tuesday -- 3rd image
wednesday--4th image
thursday -- 5th image
friday -- 1st image
Saturday-- 2nd image

number of images is dynamically changing.

if the array has one image.. daily that one image should display.
if the array has two image, then 1st day--- 1st image. 2nd day--- 2nd image, 3rd day--- again 1st image.

Can any one please tell me the logic to do this? waiting for your reply.

Thank you...
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: how to display one image per day from an array?

 
0
  #2
Apr 30th, 2007
look at the documentation of Calendar.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 14
Reputation: Thendral is an unknown quantity at this point 
Solved Threads: 0
Thendral Thendral is offline Offline
Newbie Poster

Re: how to display one image per day from an array?

 
0
  #3
May 16th, 2007
Hai,

I didnt find out the logic for this.
Kindly tell me some suggestions.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: how to display one image per day from an array?

 
0
  #4
May 16th, 2007
look again... You'll notice you can get the day as a number.
An array is indexed on a number.

Put 2 and 2 together and you'll have insight.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 14
Reputation: Thendral is an unknown quantity at this point 
Solved Threads: 0
Thendral Thendral is offline Offline
Newbie Poster

Re: how to display one image per day from an array?

 
0
  #5
May 17th, 2007
Here is the code. array length is number of records available in the database. that is retrived in a query.

Calendar cal = Calendar.getInstance();
int dayofweek = cal.get(cal.DAY_OF_WEEK);

if(arraylength==2)
{
if(dayofweek==1)
imagenumber=1;
else if(dayofweek==2)
imagenumber=2;
else if(dayofweek==3)
imagenumber=1;
else if(dayofweek==4)
imagenumber=2;
else if(dayofweek==5)
imagenumber=1;
else if(dayofweek==6)
imagenumber=2;
else if(dayofweek==7)
imagenumber=1;
}
else if(arraylength==3)
{
if(dayofweek==1)
imagenumber=1;
else if(dayofweek==2)
imagenumber=2;
else if(dayofweek==3)
imagenumber=3;
else if(dayofweek==4)
imagenumber=1;
else if(dayofweek==5)
imagenumber=2;
else if(dayofweek==6)
imagenumber=3;
else if(dayofweek==7)
imagenumber=1;
}
else if(arraylength==4)
{
if(dayofweek==1)
imagenumber=1;
else if(dayofweek==2)
imagenumber=2;
else if(dayofweek==3)
imagenumber=3;
else if(dayofweek==4)
imagenumber=4;
else if(dayofweek==5)
imagenumber=1;
else if(dayofweek==6)
imagenumber=2;
else if(dayofweek==7)
imagenumber=3;
}
else if(arraylength==5)
{
if(dayofweek==1)
imagenumber=1;
else if(dayofweek==2)
imagenumber=2;
else if(dayofweek==3)
imagenumber=3;
else if(dayofweek==4)
imagenumber=4;
else if(dayofweek==5)
imagenumber=5;
else if(dayofweek==6)
imagenumber=1;
else if(dayofweek==7)
imagenumber=2;
}
else if(arraylength==6)
{
if(dayofweek==1)
imagenumber=1;
else if(dayofweek==2)
imagenumber=2;
else if(dayofweek==3)
imagenumber=3;
else if(dayofweek==4)
imagenumber=4;
else if(dayofweek==5)
imagenumber=5;
else if(dayofweek==6)
imagenumber=6;
else if(dayofweek==7)
imagenumber=1;
}
else if(arraylength==7)
imagenumber = dayofweek;
else if((arraylength>7 && (arraylength<15))
imagenumber=dayofweek+7;
else
imagenumber=arraylength;


I am manually checking array length and assigning the image. I need some dynamic calculation for assigning the image. Also this code works only upto 14 images. I need to display even the array length is 25, 50 etc...

Kindly check it out and give me a solution.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: how to display one image per day from an array?

 
0
  #6
May 17th, 2007
ever heard of division?
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 14
Reputation: Thendral is an unknown quantity at this point 
Solved Threads: 0
Thendral Thendral is offline Offline
Newbie Poster

Re: how to display one image per day from an array?

 
0
  #7
May 17th, 2007
Hai jwenting!

If you know the logic, Post it...
Dont critize the one who is asking for help.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,115
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 470
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: how to display one image per day from an array?

 
0
  #8
May 17th, 2007
Thendral, in my opinion you are complicating your work. Why not to have 7 images in array and then you have no need for additional calculations. Just find out which day of week is currently and call array position to retrive image.

If you still feel funky then you can setup 31 images and acording to day in the month you call relevant image. Then you have image for each day
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: how to display one image per day from an array?

 
0
  #9
May 17th, 2007
How about something like:

imageId = imageArray.length % dayOfMonth;

Change the formula to suit your needs but I hope you get the logic right.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 14
Reputation: Thendral is an unknown quantity at this point 
Solved Threads: 0
Thendral Thendral is offline Offline
Newbie Poster

Re: how to display one image per day from an array?

 
0
  #10
May 18th, 2007
Thank you Peter_Budo and ~S.O.S~...

This is my Project requirement. I cant change the array length as Static one ie 7.

I tried with division and modulo operator. but it is not working. Do you have any other calculations? If so kindly help me out.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC