tag:blogger.com,1999:blog-31939397760970589012024-02-20T08:16:29.355-08:00Just Learned!!Hello and welcome to my Online Blog.
My name is Roshan Fernando and I am a blogger from Sri Lanka. If you are looking for information about c sharp,asp.net, java, php, sql, you have come to the right place. I have failed and I have been successful. These are my stories.
Enjoy!!Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-3193939776097058901.post-65183504004919593432012-01-07T07:43:00.000-08:002012-01-07T07:43:04.506-08:006 job market trends.<blockquote>since the start of the recession in December 2007, the United States has lost 8.4 million jobs. Yet, employers are finally feeling a renewed sense of hiring optimism, according to a new survey from CareerBuilder and USA TODAY.
For the third consecutive quarter, more hiring managers and human resource professionals are projecting they will increase headcount in the next three months while fewer are expecting staff cuts. </blockquote><a href="http://edition.cnn.com/2010/LIVING/worklife/04/01/cb.job.market.trends/index.html"></a>Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-5783257709571710602012-01-04T20:25:00.000-08:002012-01-07T03:26:25.591-08:00Self AwarenessSelf Awareness is having a clear perception of your personality, including strengths, weaknesses, thoughts, beliefs, motivation, and emotions. Self Awareness allows you to understand other people, how they perceive you, your attitude and your responses to them in the moment.
We might quickly assume that we are self aware, but it is helpful to have a relative scale for awareness. If you have ever been in an auto accident you may have experienced everything happening in slow motion and noticing details of your thought process and the event. This is a state if heightened awareness. With practice we can learn to engage these types of heightened states and see new opportunities for interpretations in our thoughts, emotions, and conversations.
<a href="http://www.pathwaytohappiness.com/self-awareness.htm">More Details</a>Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-58039398810745089852011-12-06T21:44:00.001-08:002012-01-07T03:27:45.516-08:00.Net framework 4.5<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<iframe src="http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-834T/player?w=960&h=544" frameBorder="0" scrolling="no" ></iframe>
</div>
ASP.Net request validation is a feature that automatically protects ASP.Net applications from XSS attacks. Request validation in asp.net triggers error when it found HTML markup in any of the input data. But some real life applications still require HTML data in some of the input fields. For e.g. When receiving feedback from user, you may need to get the feedback as HTML. Prior to 4.5 the developers have the ability to switch off the request validation either in page level or for the entire application. Even though this was helpful, for accepting HTML markup from any one field in the page, you were required to disable the validation for entire page or disable it for entire application.
ASP.Net 4.5 brings some improvements to the request validation features. There is a new attribute introduced to httpRuntime element called requestValidationMode. You can set value for this attribute to 4.5 so that new improvements will be applied to your application.Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-46324194427078610672011-10-24T21:14:00.001-07:002011-10-24T21:14:51.291-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="http://www.linkedin.com/news?actionBar=&articleID=861393440&ids=cPcUd3sSdzkUb3cMcz8UdPARe2MNc3cQdj0RdzwIc3gQcPAPcjoU&aag=true&freq=weekly&trk=eml-tod-b-ttle-96&ut=2HiV0rdQbSAkY1">The 147 Companies That Control Everything</a></div>Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-21741181899010101362011-10-24T04:27:00.000-07:002011-10-24T04:27:44.224-07:00ASP.NET THEMES<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="font-family: Arial,Helvetica,sans-serif;">
Hi Folks,,</div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
today i am going to write about an old feature of asp.net , but thought this may help you. </div>
<div style="font-family: Arial,Helvetica,sans-serif;">
Long story short, i think every body knows what theming is . so let's start to look how to implement it .</div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
First of all there is a special folder type for themes in ASP.net , which is called APP_THEMES. </div>
<div style="font-family: Arial,Helvetica,sans-serif;">
Before you start with you need to add App_theme folder to your web site/application.</div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
Go to your project right click on it and Select <span style="color: blue;">Add >>> Add ASP.NET Folder >> Theme</span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
Bravo now you have the theme folder . Next what you have to do create folders for each of theme you want..</div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="background-color: white;"><span style="color: yellow;"><span style="color: orange;">e.g</span>.</span><i> </i></span><i>Let's<span style="background-color: white;"></span> say you want three themes according to user types , which will be Pre paid / Postpaid and For Unregistered Guests . what you will be doing is creating three folders and name it accordingly.</i></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
Then for each folder you can add separate css file which will be used to dress your web pages.</div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="color: orange;">e.g.</span> with in the prepaid folder you can add prepaid.<span style="color: blue;">css</span> file. and especially you can add skin file also which will used to decorate your controls.</div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
e.g. you want all the text-box of your web page to have black border when you select a specific theme. what you can do is you can add a skin file to , specific theme folder and give a name for it and then add some thing like this </div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="background-color: magenta; font-family: Arial,Helvetica,sans-serif;">
<asp:TextBox: runat="server" <i>border ="Blah blach balcj,,....."</i>/> .<span><span style="background-color: white;"></span></span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
Last the interesting part . How to change the themes ?</div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
there are two options you can use web.config to set a them. this is useful when you are developing a product and you want to give the product to separate customers with different looks,.</div>
<div style="font-family: Arial,Helvetica,sans-serif;">
this is how to you can do it . in the web config system.web section</div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<b><span style="color: #38761d;"> <pages theme="theme name"></pages> </span></b></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<b><span style="color: #38761d;"> </span></b><span style="color: #38761d;"><span style="color: black;">Other option is to change the theme on the fly.which means dynamically changing the theme,</span></span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="color: #38761d;"><span style="color: black;">protected <span style="background-color: lime;">override </span>void <span style="color: lime;">OnPreInit</span>(EventArgs e) {</span></span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="color: #38761d;"><span style="color: black;"> <span style="background-color: #b4a7d6;">Page.Theme = "ThemeName";</span></span></span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="color: #38761d;"><span style="color: black;">}</span></span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="color: #38761d;"><span style="color: black;"><br /></span></span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="color: #38761d;"><span style="color: black;">That's all ..</span></span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="color: #38761d;"><span style="color: black;"><br /></span></span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="color: #38761d;"><span style="color: black;">Thanks</span></span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<b><span style="color: #38761d;"> </span></b></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
</div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<br /></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-3033277020312990812011-02-20T23:15:00.000-08:002011-02-20T23:15:08.366-08:00Dynamically Load Controls to a web page<div style="color: blue;"><i><b style="font-family: Arial,Helvetica,sans-serif;">Hi folks !!!</b></i></div><div style="color: blue;"><br />
</div>this is something simple, and thought it will be important for all of you. recently, I had a requirement of adding various controls to a certain page according to the current type of the user. Let's say , we have a user which can be swap between three <i style="color: blue;"><b>states</b></i>. lets say ,<br />
<br />
<ul style="color: magenta;"><li><i><b>state A </b></i></li>
<li><i><b>state B</b></i></li>
<li><i><b>state C</b></i></li>
</ul>and each state has its own properties and descriptions, So ideal decision is to develop three different <i><b>usercontrols </b></i>for the states, correct???<br />
So i have developed the three <i><b>usercontrols</b></i>. Then we i have option of<br />
<br />
<ul><li>either adding to all three usersontrols to the page and hiding it according to the state</li>
<li>Or, i would prefer adding the relevant usercontrol from the server side it self to the <i><b>page </b></i>and pass the page to the <i><b>client</b></i>.</li>
</ul>in this scenario, i prefer to go with the second option, because of the performance and the elegance.<br />
<i> // create a control </i><br />
<b style="color: blue;">Control </b>cntrlUCstate= new <b style="color: blue;">Control</b>(); <br />
<i>// Load that control </i><br />
<span style="color: blue;">cntrlUCstate </span>= <span style="color: blue;">LoadControl</span>(<i><b>"relative path of the control"</b></i>);<br />
<i><span style="color: red;">// assume that you are using an update panel.(<span style="color: black;"> </span></span><b><span style="color: red;"><span style="color: black;">aupAccBal is the update panel</span>)</span></b></i><br />
<b>aupAccBal</b><i>.ContentTemplateContainer.Controls.Add(<b>cntrlUCstate</b></i><i>); </i><br />
<br />
<i>if you want , you can clear the control collection as well. </i><br />
<i><b><span style="color: magenta;">aupAccBal.ContentTemplateContainer.Controls.Clear();</span><span style="background-color: red;"></span></b> </i><br />
<i><br />
</i><br />
<br />
<i><b>Thanks N enjoy!!! </b></i><i><br />
</i><br />
<i><br />
</i>Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-61900083545532677712011-02-03T02:16:00.000-08:002011-02-03T02:16:47.613-08:00Set a value from the top SQL<b><i>Hi Folks!!</i></b><br />
<br />
This is what something i have went wrong with. I wanted to set a value which was returning from the top clause,<br />
what i tried was<br />
<blockquote style="color: red;"><b>SELECT @Variable = Top 1 <<column>> FROM <<table>> </b></blockquote>Certainly that gave me <b>errors </b>.<br />
So few searches from internet has solved my problem. <br />
<br />
this was the solution for it.<br />
<blockquote><i><b>SET @Variable =( SELECT Top 1 <<column>> FROM <<table>>) </b></i></blockquote><br />
<i>Njoy!</i><br />
<br />
<br />
<br />
<br />
<blockquote> </blockquote>Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-88049793389722983022011-01-23T20:46:00.000-08:002011-01-23T20:46:49.057-08:00Treap algorithm java<!--[if !mso]> <style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style> <![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves>false</w:TrackMoves> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/> <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/> <w:Word11KerningPairs/> <w:CachedColBalance/> <w:UseFELayout/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--> <m:smallfrac m:val="off"> <m:dispdef> <m:lmargin m:val="0"> <m:rmargin m:val="0"> <m:defjc m:val="centerGroup"> <m:wrapindent m:val="1440"> <m:intlim m:val="subSup"> <m:narylim m:val="undOvr"> </m:narylim></m:intlim> </m:wrapindent><!--[endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" Priority="39" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" Name="toc 9"/> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/> <w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/> <w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/> <w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-language:EN-US;}
</style> <![endif]--><!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="2050"/> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> <o:rules v:ext="edit"> <o:r id="V:Rule1" type="connector" idref="#_x0000_s1040"/> <o:r id="V:Rule2" type="connector" idref="#_x0000_s1051"/> <o:r id="V:Rule3" type="connector" idref="#_x0000_s1035"/> <o:r id="V:Rule4" type="connector" idref="#_x0000_s1065"/> <o:r id="V:Rule5" type="connector" idref="#_x0000_s1031"/> <o:r id="V:Rule6" type="connector" idref="#_x0000_s1064"/> <o:r id="V:Rule7" type="connector" idref="#_x0000_s1047"/> <o:r id="V:Rule8" type="connector" idref="#_x0000_s1057"/> <o:r id="V:Rule9" type="connector" idref="#_x0000_s1045"/> <o:r id="V:Rule10" type="connector" idref="#_x0000_s1044"/> <o:r id="V:Rule11" type="connector" idref="#_x0000_s1046"/> <o:r id="V:Rule12" type="connector" idref="#_x0000_s1039"/> <o:r id="V:Rule13" type="connector" idref="#_x0000_s1037"/> <o:r id="V:Rule14" type="connector" idref="#_x0000_s1062"/> <o:r id="V:Rule15" type="connector" idref="#_x0000_s1060"/> <o:r id="V:Rule16" type="connector" idref="#_x0000_s1063"/> <o:r id="V:Rule17" type="connector" idref="#_x0000_s1050"/> <o:r id="V:Rule18" type="connector" idref="#_x0000_s1036"/> <o:r id="V:Rule19" type="connector" idref="#_x0000_s1029"/> </o:rules> </o:shapelayout></xml><![endif]--> </m:defjc></m:rmargin></m:lmargin></m:dispdef></m:smallfrac><br />
<h2><span> </span><a href="" name="_Toc283558611">Description of the Algorithm</a></h2><div class="MsoNormal"><br />
</div><div class="MsoNormal">According to the definition of problem set 01, it gives the basic idea of binary search tree insert and then performing relevant rotations to restore the min-heap property. Each insertion to this data structure comprises of a key and a unique priority. </div><h2><a href="" name="_Toc283558612">Conditions</a></h2><div class="MsoNormal"><br />
</div><div class="Default" style="margin: 0in 0in 2.5pt; text-indent: 0in;"><span style="color: windowtext; font-family: Wingdings; font-size: 11pt;"><span>ü<span style="font: 7pt "Times New Roman";"> </span></span></span><i><span style="color: windowtext; font-family: "Calibri","sans-serif"; font-size: 11pt;">if v is a left child of u, then key[v] < key[u]</span></i></div><div class="Default" style="margin: 0in 0in 2.5pt; text-indent: 0in;"><span style="color: windowtext; font-family: Wingdings; font-size: 11pt;"><span>ü<span style="font: 7pt "Times New Roman";"> </span></span></span><i><span style="color: windowtext; font-family: "Calibri","sans-serif"; font-size: 11pt;">if v is a right child of u, then key[v] > key[u]</span></i></div><div class="Default" style="margin: 0in 0in 2.5pt; text-indent: 0in;"><span style="color: windowtext; font-family: Wingdings; font-size: 11pt;"><span>ü<span style="font: 7pt "Times New Roman";"> </span></span></span><i><span style="color: windowtext; font-family: "Calibri","sans-serif"; font-size: 11pt;">if v is a child of u, then priority(v) > priority(u) </span></i></div><h2><a href="" name="_Toc283558613">Assumptions</a></h2><div class="Default" style="margin-bottom: 2.5pt;"><br />
</div><div class="Default" style="margin: 0in 0in 2.5pt; text-indent: 0in;"><span style="color: windowtext; font-family: Wingdings; font-size: 11pt;"><span>ü<span style="font: 7pt "Times New Roman";"> </span></span></span><i><span style="color: windowtext; font-family: "Calibri","sans-serif"; font-size: 11pt;">I expect that user will enter all the requests and then try to view the tree.</span></i></div><div class="Default" style="margin: 0in 0in 2.5pt; text-indent: 0in;"><span lang="EN-GB" style="font-family: Wingdings;"><span>ü<span style="font: 7pt "Times New Roman";"> </span></span></span><i><span style="color: windowtext; font-family: "Calibri","sans-serif"; font-size: 11pt;">User will input valid inputs. (I have not validated the user inputs)</span></i><i><span lang="EN-GB"></span></i></div><div class="MsoNormal"><br />
</div><h2><a href="" name="_Toc283558614">Pseudo Code of the Algorithm</a></h2><div class="MsoNormal"><br />
</div><div class="MsoNoSpacing"><i>Element <b>x</b> </i></div><div class="MsoNoSpacing"><b><i>While</i></b><i> x != root and priority (x) < priority of parent (x)</i></div><div class="MsoNoSpacing" style="margin-left: 2in; text-indent: -1.5in;"><b><i>BEGIN</i></b></div><div class="MsoNoSpacing" style="margin-left: 2in; text-indent: -1.5in;"><i>if<b> </b>current root == nullNode</i></div><div class="MsoNoSpacing" style="margin-left: 2in; text-indent: -1.5in;"><b><i><span> </span>THEN</i></b></div><div class="MsoNoSpacing" style="margin-left: 2in; text-indent: -1.5in;"><b><i><span> </span></i></b><i>root == x;</i></div><div class="MsoNoSpacing" style="margin-left: 2in; text-indent: -1in;"><i>If key of x < =key of parent<span> </span><b>WE CAN CHECK EQUALITY AND LESS THAN IF <span> </span>WE WANT TO <span> </span>ACCEPT DUPLICATE KEYS.</b></i></div><div class="MsoNoSpacing" style="margin-left: 0.5in; text-indent: 0.5in;"><i>Insert into left child. </i></div><div class="MsoNoSpacing" style="margin-left: 0.5in; text-indent: 0.5in;"><i><span> </span>If priority of x > priority of parent </i></div><div class="MsoNoSpacing" style="margin-left: 1in; text-indent: 0.5in;"><b><i>BEGIN</i></b><i> <span> </span>RotateWithLeftChild(x);</i></div><div class="MsoNoSpacing" style="margin-left: 0.5in; text-indent: 0.5in;"><b><i>END IF</i></b></div><div class="MsoNoSpacing" style="text-indent: 0.5in;"><b><i>END IF</i></b></div><div class="MsoNoSpacing" style="margin-left: 0.5in; text-indent: 0.5in;"><i>If key of x > key of parent</i></div><div class="MsoNoSpacing" style="margin-left: 1in; text-indent: 0.5in;"><b><i>BEGIN</i></b></div><div class="MsoNoSpacing" style="margin-left: 1.5in; text-indent: 0.5in;"><i>Insert into left child. </i></div><div class="MsoNoSpacing" style="margin-left: 1.5in; text-indent: 0.5in;"><b><i>THEN</i></b><i><span> </span><span> </span>If priority of x < priority of parent </i></div><div class="MsoNoSpacing" style="margin-left: 2in;"><b><i>BEGIN</i></b></div><div class="MsoNoSpacing" style="margin-left: 2in; text-indent: 0.5in;"><i>RotateWithRightChild(x);</i></div><div class="MsoNoSpacing" style="margin-left: 1.5in; text-indent: 0.5in;"><b><i>END IF</i></b></div><div class="MsoNoSpacing" style="margin-left: 0.5in; text-indent: 0.5in;"><b><i>END IF</i></b><i> </i></div><div class="MsoNoSpacing"><b><i>END WHILE </i></b></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><h2><a href="" name="_Toc283558615">Running time of the Algorithm</a></h2><div class="MsoNormal"><br />
</div><div class="CM8" style="margin: 0in 30.75pt 0.0001pt 30pt; text-align: justify;"><i><span style="font-family: "Calibri","sans-serif"; font-size: 11pt;">A treap with n nodes is equivalent to a randomly built binary search tree with n nodes. Because that assigning priorities to nodes as they are inserted into the treap is the same as inserting to the binary search tree n nodes in the increasing order defined by their priorities. So if we assign the priorities randomly, we get a random order of n priorities, which is the same as a random permutation of the n inputs, so we can view this as inserting the n items in random order. </span></i></div><div class="CM8" style="margin: 0in 30.75pt 0.0001pt 30pt; text-align: justify;"><br />
</div><div class="CM8" style="margin: 0in 30.75pt 0.0001pt 30pt; text-align: justify;"><i><span style="font-family: "Calibri","sans-serif"; font-size: 11pt;">TREAP-INSERT first inserts an item in the tree using the normal binary search tree </span></i></div><div class="CM8" style="margin: 0in 30.75pt 0.0001pt 30pt; text-align: justify;"><i><span style="font-family: "Calibri","sans-serif"; font-size: 11pt;">insert and then performs a number of rotations to restore the min-heap property. The normal binary-search-tree insertion algorithm TREE-INSERT always places the new item at a new leaf of tree. Therefore the time to insert an item into a treap is proportional to the height of a randomly built binary search tree, which as we saw in lecture is <b>O(lg n)</b> in expectation. </span></i></div><div class="CM8" style="margin: 0in 30.75pt 0.0001pt 30pt; text-align: justify;"><i><span style="font-family: "Calibri","sans-serif"; font-size: 11pt;">The maximum number of rotations occurs when the new item receives a priority less than all priorities in the tree. In this case it needs to be rotated from a leaf to the root. An upper bound on the number of rotations is therefore the height of a randomly built binary search tree, which is O(lg n) in expectation. </span></i></div><div class="CM8" style="margin: 0in 30.75pt 0.0001pt 30pt; text-align: justify;"><i><span style="font-family: "Calibri","sans-serif"; font-size: 11pt;">Because each rotation take constant time, the expected time to rotate is <b>O(lg n).</b></span></i></div><div class="Default"><br />
</div><div class="MsoNormal"><br />
</div><b><span style="font-size: 14pt; line-height: 115%;"></span></b><b><span style="font-size: 14pt; font-style: normal; line-height: 115%;"></span></b> <div class="MsoNoSpacing"><b><span style="font-size: 14pt;"></span></b></div><div class="MsoNoSpacing"><b><br />
<span style="font-size: 14pt;"></span></b></div><div class="MsoNormal"><b><span style="font-size: 14pt; line-height: 115%;"><br clear="all" style="page-break-before: always;" /> </span></b><b><span style="font-size: 14pt; font-style: normal; line-height: 115%;"></span></b></div><h2><a href="" name="_Toc283558619"><span style="font-size: 14pt; line-height: 115%;">S</span>ources</a></h2><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;">/* Roshan Fernando</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>* Orginal Author Mark Weiss</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>* 2011-01-15</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>*/</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;">package ProblemSet01;</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><b><i><span style="font-size: 9pt;">// Basic node stored in treaps</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;">import java.util.Random;</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><b><i><span style="font-size: 9pt;">/** Note that this class is not accessible outside</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 9pt;"><span> </span>* of package ProblemSet01</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 9pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;">class TreapNode {</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;">private static Random randomObj = new Random();</span></i></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>// Constructors</span></i></b></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>TreapNode(Comparable theElement) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>this(theElement, null, null, 0);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>TreapNode(Comparable theElement, TreapNode lt, TreapNode rt, int prior) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>element = theElement;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>left = lt;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>right = rt;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>priority = prior;//randomObj.nextInt();</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span><b>/**</b></span></i></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* can use this Overload for the </span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* Auto generated Priorites</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @param theElement</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @param lt</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @param rt</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>TreapNode(Comparable theElement, TreapNode lt, TreapNode rt) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>element = theElement;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>left = lt;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>right = rt;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>priority = randomObj.nextInt();</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>// Friendly data; accessible by other package routines</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>Comparable element;<span> </span>// The data in the node</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>TreapNode left;<span> </span>// Left child</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>TreapNode right;<span> </span>// Right child</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>int priority;<span> </span>// Priority</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span></span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;">}</span></i></div><i><span style="font-family: "Calibri","sans-serif"; font-size: 11pt; line-height: 115%;"><br clear="all" style="page-break-before: always;" /> </span></i> <div class="MsoNormal"><br />
</div><div class="MsoNoSpacing"><b><span style="font-size: 10pt;">/* Roshan Fernando</span></b></div><div class="MsoNoSpacing"><b><span style="font-size: 10pt;"><span> </span>* Orginal Author Mark Weiss</span></b></div><div class="MsoNoSpacing"><b><span style="font-size: 10pt;"><span> </span>* 2011-01-15</span></b></div><div class="MsoNoSpacing"><b><span style="font-size: 10pt;"><span> </span>*/</span></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;">package ProblemSet01;</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;">import java.util.Random;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;">import java.util.Stack;// this is for the printing purpose only.</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;">import java.util.Scanner;</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;">public class Treap {</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>private TreapNode root;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>private static TreapNode nullNode;</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>static <b>// Static initializer for NullNode</b></span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>{</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>nullNode = new TreapNode(null);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>nullNode.left = nullNode.right = nullNode;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>nullNode.priority = Integer.MAX_VALUE;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>public Treap() {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>root = nullNode;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>/**</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* Insert into the tree.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @param x the item to insert.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @param<span> </span>pr the priority</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>public void insert(Comparable x, int pr) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>root = insert(x, root, pr);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>/**</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* Test if the tree is logically empty.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @return true if empty, false otherwise.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>public boolean isEmpty() {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>return root == nullNode;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span><b>/**</b></span></i></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* Print the tree contents in sorted order.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>public void printTree() {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>if (isEmpty()) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>System.out.println("Empty tree");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>} else {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>printTree(root);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span><b>/**</b></span></i></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* Internal Overloaded method to insert into a subtree.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @param x the item to insert.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @param t the node that roots the tree.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @param<span> </span>pr the priority of the new Item.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @return the new root.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>private TreapNode insert(Comparable x, TreapNode t, int pr) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>if (t == nullNode) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>t = new TreapNode(x, nullNode, nullNode, pr);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>} else if (x.compareTo(t.element) <= 0) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>t.left = insert(x, t.left, pr);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>if (t.left.priority <= t.priority) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>t = rotateWithLeftChild(t);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>} else if (x.compareTo(t.element) > 0) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>t.right = insert(x, t.right, pr);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>if (t.right.priority < t.priority) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>t = rotateWithRightChild(t);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>return t;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span><b>/**</b></span></i></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* Internal Overloaded method to insert into a subtree.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* for auto Generated priority.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @param x the item to insert.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @param t the node that roots the tree.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @return the new root.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>private TreapNode insert(Comparable x, TreapNode t) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>if (t == nullNode) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>t = new TreapNode(x, nullNode, nullNode);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>} else if (x.compareTo(t.element) <= 0) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span><span> </span>t.left = insert(x, t.left);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>if (t.left.priority < t.priority) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>t = rotateWithLeftChild(t);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>} else if (x.compareTo(t.element) > 0) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>t.right = insert(x, t.right);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>if (t.right.priority < t.priority) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>t = rotateWithRightChild(t);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>return t;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span></span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;">/**</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* Internal method to print a subtree in sorted order.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @param t the node that roots the tree.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>private void printTree(TreapNode t) {</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>if (t != t.left) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>printTree(t.left);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>System.out.println(t.element.toString() + "\t[" + t.priority + "]");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>printTree(t.right);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>/**</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* Rotate binary tree node with left child.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>private static TreapNode rotateWithLeftChild(TreapNode k2) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>TreapNode k1 = k2.left;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>k2.left = k1.right;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>k1.right = k2;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>return k1;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>/**</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* Rotate binary tree node with right child.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>private static TreapNode rotateWithRightChild(TreapNode k1) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>TreapNode k2 = k1.right;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>k1.right = k2.left;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>k2.left = k1;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>return k2;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>/**</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* Generates a letter,</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* Duplicates are allowed.</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @return char Alphabet</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>private static char letterGenerate() {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>char alphabet[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>Random generator = new Random();</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>return alphabet[generator.nextInt(25)];</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span></span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;">/**</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* just to print the treap</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>public void displayTree() {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>System.out.println("<span> </span>! ... Visual Tree<span> </span>... !");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>Stack globalStack = new Stack();</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>globalStack.push(root);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>int nBlanks = 32;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>boolean isRowEmpty = false;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>System.out.println("......................................................");</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>while (isRowEmpty == false) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>Stack localStack = new Stack();</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>isRowEmpty = true;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>for (int j = 0; j < nBlanks; j++) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>System.out.print(" ");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span><span> </span>while (globalStack.isEmpty() == false) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>TreapNode temp = (TreapNode) globalStack.pop();</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>if (temp != null && temp.element != null) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>System.out.print(temp.element + "[" + temp.priority + "]");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span><span> </span>localStack.push(temp.left);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>localStack.push(temp.right);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>if (temp.left != null || temp.right != null) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>isRowEmpty = false;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>} else {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>System.out.print("--");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>localStack.push(null);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>localStack.push(null);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>for (int j = 0; j < nBlanks * 2 - 2; j++) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>System.out.print(" ");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>} <b>// end while globalStack not empty</b></span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>System.out.println();</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>nBlanks /= 2;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>while (localStack.isEmpty() == false) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>globalStack.push(localStack.pop());</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>} <b>// end while isRowEmpty is false</b></span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>System.out.println("......................................................");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span><b>/**</b></span></i></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* for manual input to the tree</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @param obj</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>* @return Treap</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 10pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>private static Treap manualInput(Treap objTreap) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>Scanner objRead = new Scanner(System.in);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>boolean isContinue = true;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>try {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>do {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>System.out.println("Please Enter a Literal ");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>char element = objRead.next().trim().charAt(0);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>System.out.println("Please enter a priority (Integer)");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>int pr = objRead.nextInt();</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>objTreap.insert(element, pr);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>System.out.println("if you want to continue press 1,\n<span> </span>press any other key to exit.");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>isContinue = objRead.next().trim().equals("1");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>} while (isContinue);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span>} catch (Exception e) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 10pt;"><span> </span></span></i><i><span style="font-size: 9pt;"><span> </span>System.out.println("Error " + e.getMessage());</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>} finally {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>return objTreap;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><b><i><span style="font-size: 9pt;"><span> </span>/**</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 9pt;"><span> </span>* auto Generated Insert to tree</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 9pt;"><span> </span>* @param objTreap</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 9pt;"><span> </span>* @return objTreap</span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 9pt;"><span> </span>*/</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>private static Treap autoGenerate(Treap objTreap) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>Scanner objRead = new Scanner(System.in);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>boolean isContinue = true;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>do {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>char c = letterGenerate();</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>int pr = new Random().nextInt();</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>System.out.println("Generated Alphabel character\t" + c + " priority [" + pr + "]");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap.insert(c, pr);</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>System.out.println("if you want to continue press 1,\n<span> </span>press any other key to exit.");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>isContinue = objRead.next().trim().equals("1");</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>} while (isContinue);</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>return objTreap;</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><b><i><span style="font-size: 9pt;"><span> </span></span></i></b></div><div class="MsoNoSpacing"><b><i><span style="font-size: 9pt;">// Test program</span></i></b></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>public static void main(String[] args) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>Treap objTreap = new Treap();</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span><b>// checking the given values with their priorities.</b></span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap.insert('A', 10);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap.insert('B', 7);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap.insert('E', 23);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap.insert('G', 4);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap.insert('H', 5);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap.insert('K', 65);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap.insert('I', 73);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap.insert('C', 25);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap.insert('D', 9);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap.insert('F', 2);<span> </span></span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span></span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>Scanner objRead = new Scanner(System.in);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>System.out.println("Press 0 for auto Generation, Press 1 for Manual inputs");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span><span> </span>int intOption = objRead.nextInt();</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>switch (intOption) {</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>case 0:</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap = autoGenerate(objTreap);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>break;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>case 1:</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap = manualInput(objTreap);</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>break;</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span><span> </span>default:</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>System.out.println("Errorneous input");</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>System.out.println("! ... in Order Traversal ... !");</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap.printTree();</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>objTreap.displayTree();</span></i></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;"><span> </span>}</span></i></div><div class="MsoNoSpacing"><i><span style="font-size: 9pt;">}</span></i><i><span style="font-size: 10pt;"><br clear="all" style="page-break-before: always;" /> </span></i></div>Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-70014812731165034682011-01-17T01:13:00.000-08:002011-01-17T01:30:42.174-08:00Pass Values using queryString<i><b>Hi folks !!!!</b></i><br />
<blockquote>Again guys this is also about web pages, do you ever wanted to pass a value from a page to another , this is the most fundamental way of doing it . </blockquote> So lets say you have a <i><b>textBox </b></i>accepting name of the user , and you want to set that value to a label in next page .<br />
<br />
<i>this is the simple way....</i><br />
<br />
<i><b>// hfCode is a hiddenField and txtLogin is my textbox, and Login ,code are my parameters.</b></i><br />
<blockquote><pre id="pre0" lang="cs" style="margin-top: 0pt;"><i>Response.Redirect(<span class="code-string">"</span><span class="code-string">URladdress.aspx?Login="</span> +
<span class="code-keyword"></span>txtLogin.Text + <span class="code-string">"</span><span class="code-string">&Code="</span> +
<span class="code-keyword"></span>hfCode.Value);</i></pre></blockquote><br />
<b><i>So in the receiving end or the page all you have to do is ,</i></b><br />
<br />
if (Request.QueryString["Login"] != null && Request.QueryString["Code"])<br />
{ <br />
<blockquote><blockquote><blockquote><pre id="pre3" lang="cs" style="margin-top: 0pt;">lblWelcome.Text = "Welcome "+ Request.QueryString["Login"]</pre></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><pre id="pre3" lang="cs" style="margin-top: 0pt;">+" "+
Request.QueryString["Code"];</pre></blockquote></blockquote></blockquote> }<br />
<br />
<br />
<i>That's all, </i><br />
<i>Enjoy.</i> <br />
<br />
<b><i>P.S. make sure to check that parameters are not null before accessing </i></b><br />
<br />
<blockquote></blockquote><br />
<br />
<br />
<blockquote><pre id="pre0" lang="cs" style="margin-top: 0pt;"></pre></blockquote>Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-51527483734621286082011-01-11T01:31:00.000-08:002011-01-11T01:31:11.560-08:00Unload event handler javaScript<i><b>Hey Folks !!!</b></i><br />
<i><br />
</i><br />
<i>this is simple javaScript to handle the Unload event.</i><br />
<i>this is the Script for that .. </i><br />
<i>And on your HTML page declare like this.</i><br />
<br />
<html><br />
<b><i>//call the function here </i></b><br />
<body OnUnload="unloadHandle()"> <br />
</html><br />
<br />
<br />
<br />
<script language="javascript" type="text/javascript"><br />
function unloadHandle() {<br />
try{<br />
<i> <b> get the element which decide whether to fire the action.</b></i><br />
<i><b> may be hiddenfield</b></i>.<br />
<br />
var val = document.getElementById("hfGenerateClick");<br />
<i><b>//ideal would be if the value != "1" then fire .. </b></i><br />
if(val.value == "1")<br />
alert("nice");<br />
else<br />
confirm("are you sure ?");<br />
}<br />
catch(err)<br />
{alert(err.description);}<br />
} <br />
<br />
</script>Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-3106598825263520022011-01-05T00:44:00.000-08:002011-01-05T00:45:42.721-08:00send c# Web request (http/https)<b>Hey folks..!!!</b><br />
<i>this is something i wanted to do while developing a web application.. i just wanted post some data to verify my site working accordingly.</i><br />
<i>Hope this one will be helpful.</i><br />
WebRequest request = WebRequest.Create("<i><b>your site address"</b></i>));<br />
request.Method = "POST";<br />
<blockquote><i><b> //Cast if it is https simply for the secured connections</b></i></blockquote> <b><i> // ((HttpWebRequest)request).ProtocolVersion = HttpVersion.Version10;</i></b><br />
string postData = <i><b>"yout data";</b></i><br />
byte[] byteArray = Encoding.UTF8.GetBytes(postData);<br />
request.ContentType = "application/x-www-form-urlencoded";<br />
request.ContentLength = byteArray.Length;<br />
Stream dataStream = request.GetRequestStream();<br />
dataStream.Write(byteArray, 0, byteArray.Length);<br />
dataStream.Close();<br />
WebResponse response = request.GetResponse();<br />
<i><b> // get the response</b></i><br />
dataStream.Close();<br />
response.Close();<br />
}<br />
<br />
<i><b>P.S.</b></i><br />
<i><b>remenber to add </b></i><br />
<i><b><br />
</b></i><br />
<i><b>using System.IO;<br />
using System.Net;</b></i>Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-7948791060602628852011-01-05T00:00:00.000-08:002011-01-05T00:17:56.262-08:00<i><b> hi folks !!</b></i><br />
<i>this is C# about sending ping request.</i><br />
<br />
private <i>void </i>HostPing(string host, int timeout)<br />
{<br />
<blockquote><i><b>//host can be an ip </b></i></blockquote> Ping pingSender = new Ping();<br />
PingOptions options = new PingOptions();<br />
<b><i><br />
// Use the default Ttl value which is 128,<br />
// but change the fragmentation behavior.</i></b><br />
options.DontFragment = true;<br />
<b><i><br />
// Create a buffer of 32 bytes of data to be transmitted.</i></b><br />
string data = "dsfgsdfgsdfgsdfgdsfg ";<br />
byte[] buffer = Encoding.ASCII.GetBytes(data);<br />
<br />
PingReply reply = pingSender.Send(host, timeout, buffer, options);<br />
<i><b> // check reply.Status if ya want ... </b></i><br />
<br />
// return (reply.Status == IPStatus.Success);<br />
<br />
}<br />
<br />
<i><b> //this is to send a request with the port defined</b></i><br />
private void checkHostAndPortAvailability(string host, int port)<br />
{<br />
IPHostEntry IPHost = new IPHostEntry();<br />
IPHost = Dns.GetHostEntry(host);<br />
<br />
IPAddress IPAddr = IPHost.AddressList[0];<br />
<br />
try<br />
{<br />
<br />
TcpClient TcpCli = new TcpClient();<br />
TcpCli.Connect(IPAddr, port);<br />
TcpCli.Close();<br />
<blockquote><i>//if succussful reach here, else go to catch</i></blockquote> }<br />
catch (Exception ex)<br />
{<br />
<i> // error handling code</i><br />
}<br />
} <br />
<b><br />
</b><br />
<b>N.B.</b><br />
<b><br />
</b><br />
<br />
<b>using System.Net.NetworkInformation;<br />
using System.Net.Sockets; <i>note to add these usings</i></b>Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-68110685934715425332011-01-04T22:37:00.000-08:002011-01-04T22:37:43.435-08:00Crystal report Function to format with leading Zeroes..<b>hey folks .. </b><br />
<br />
this is something that i have come across while doing some development .<br />
my requirement was to format integer database column with<i> leading zeroes </i>with <b><i>Crystal Report</i></b>.<br />
<br />
i have a <i>dataset </i>called <b>OrderDetails </b>and i am formatting it to have 10 digits where the leading digits will be filled with zeroes.<b style="background-color: #9fc5e8;"> <span style="color: white;">e.g. </span><i style="color: white;">21 </i><span style="color: white;">will be </span><i style="color: white;">0000000021</i></b><br />
<blockquote><b><span style="font-size: small;"><br />
</span></b></blockquote><br />
<b><span style="font-size: small;"><i>this is how i did it.</i></span></b><br />
in crystal report you have to write a function . <i>(write click formula field then select new)</i><br />
<br />
<blockquote>ReplicateString ("0",10-Length(cstr ({OrderDetails.Id},0,""))) +cstr({OrderDetails.Id},0,"") </blockquote>simple like this<br />
<b><i>P.S remember save,press x+2 button to validate and add this to your report lol ...!!!!</i></b>Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-75604785127758167752011-01-03T21:36:00.000-08:002011-01-03T21:36:03.088-08:00java Shopping Cart with swingpackage OnlineShop;<br />
<br />
import javax.swing.*;<br />
import java.awt.*;<br />
import java.awt.event.*;<br />
<br />
<br />
public class Login<br />
{<br />
<br />
protected JFrame jfrmLogin = new JFrame ("Login");<br />
protected JPasswordField txtPassword = new JPasswordField(10);<br />
protected JTextField txtLoginName = new JTextField(10);<br />
protected JPanel jplLogin = new JPanel(null);<br />
protected JLabel lblMessage = new JLabel("");<br />
protected JButton btnSubmit = new JButton("Login");<br />
protected JButton btnCancel = new JButton("Cancel");<br />
<br />
<br />
public static void main(String[] args)<br />
{<br />
new Login().display();<br />
JFrame.setDefaultLookAndFeelDecorated(true);<br />
}<br />
<br />
void display()<br />
{<br />
<br />
JLabel lblLoginName = new JLabel("Login Name");<br />
JLabel lblPassword = new JLabel("Password");<br />
<br />
Container contPane = jfrmLogin.getContentPane();<br />
<br />
lblLoginName.setLabelFor(txtLoginName);<br />
<br />
lblPassword.setLabelFor(txtPassword);<br />
<br />
lblLoginName.setBounds(50,50,100,20);<br />
txtLoginName.setBounds(150,50, 150, 20);<br />
txtLoginName.setText("admin");<br />
lblPassword.setBounds(50,80,100,20);<br />
txtPassword.setBounds(150,80, 150, 20);<br />
txtPassword.setText("admin123");<br />
<br />
btnSubmit.setBounds(150,120,100,25);<br />
<br />
lblMessage = new JLabel();<br />
jplLogin.add(lblLoginName);<br />
jplLogin.add(txtLoginName);<br />
jplLogin.add(lblPassword);<br />
jplLogin.add(txtPassword);<br />
jplLogin.add(btnSubmit);<br />
jplLogin.add(lblMessage);<br />
<br />
lblMessage.setFont(new Font("Calibri", Font.ITALIC, 15));<br />
lblMessage.setForeground(Color.darkGray);<br />
contPane.add(jplLogin);<br />
contPane.add(lblMessage,BorderLayout.PAGE_START);<br />
<br />
<br />
<br />
txtPassword.setText("admin123");<br />
txtLoginName.setText("admin");<br />
btnSubmit.addActionListener(new MyActionListener(this));<br />
btnCancel.addActionListener(new MyActionListener(this));<br />
<br />
<br />
<br />
<br />
<br />
<br />
jfrmLogin.getRootPane().setDefaultButton(btnSubmit);<br />
jfrmLogin.setSize(375,275);<br />
jfrmLogin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
jfrmLogin.setVisible(true);<br />
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();<br />
<br />
// Determine the new location of the window<br />
int w = jfrmLogin.getSize().width;<br />
int h = jfrmLogin.getSize().height;<br />
int x = (dim.width-w)/2;<br />
int y = (dim.height-h)/2;<br />
<br />
<br />
jfrmLogin.setLocation(x, y);<br />
<br />
}<br />
}<br />
<br />
class MyActionListener implements ActionListener<br />
{<br />
Login objLog;<br />
MyActionListener(Login log)<br />
{<br />
this.objLog = log;<br />
}<br />
<br />
public void actionPerformed(ActionEvent e)<br />
{<br />
User objUser = new User();<br />
objLog.lblMessage.setFont(new Font("Trebuchet Ms", Font.PLAIN, 14));<br />
objLog.lblMessage.setForeground(Color.BLACK);<br />
<br />
if (e.getSource() == objLog.btnSubmit)<br />
{<br />
if(objLog.txtLoginName.getText().isEmpty() || objLog.txtPassword.getText().isEmpty())<br />
{<br />
objLog.lblMessage.setText("Login Name / Password required to Login");<br />
objLog.jplLogin.setBackground(Color.RED);<br />
objLog.jfrmLogin.repaint();<br />
}<br />
else<br />
{<br />
if (objLog.txtLoginName.getText().equals(objUser.getLoginName()) && objLog.txtPassword.getText().equals(objUser.getPassword()))<br />
{<br />
objLog.jplLogin.setBackground(Color.GREEN);<br />
objLog.jfrmLogin.setVisible(false);<br />
new ProductSelection(objUser).display();<br />
objLog.jfrmLogin.dispose();<br />
}<br />
else<br />
{<br />
objLog.jplLogin.setBackground(Color.RED);<br />
objLog.lblMessage.setText("Incorrect login name / password");<br />
objLog.jfrmLogin.repaint();<br />
}<br />
}<br />
}<br />
<br />
if (e.getSource() == objLog.btnCancel)<br />
{<br />
System.exit(0);<br />
}<br />
}<br />
<br />
<br />
<br />
}<br />
<br />
image path had hard coded<br />
<br />
package OnlineShop;<br />
<br />
/**<br />
*<br />
* @author Roshan<br />
*/<br />
import java.awt.*;<br />
import java.awt.event.*;<br />
import javax.swing.*;<br />
import javax.swing.border.LineBorder;<br />
import java.util.*;<br />
<br />
public class ImagePanel<br />
{<br />
ProductSelection productSel;<br />
<br />
ImagePanel(ProductSelection pro)<br />
{<br />
productSel =pro;<br />
}<br />
<br />
JPanel hpPanel(User authUser)<br />
{<br />
JPanel panelLaptopHp = new JPanel();<br />
panelLaptopHp.add(this.CreateJPanel(new Product(115000, "HP Pavilion DV6 3061", "<html>Core i7 1.6GHz, 6GB DDR3,<br>640GB,1GB VGA,<br>Win7</html>"),"Laptop_HP_1.jpg", authUser));<br />
panelLaptopHp.add(this.CreateJPanel(new Product(85000, "HP Pavilion dv5t series", "<html>Core i3 2.6GHz, 2GB DDR3,<br>640GB,1GB VGA,<br>Win7</html>"),"Laptop_HP_2.jpg", authUser));<br />
panelLaptopHp.add(this.CreateJPanel(new Product(105000, "HP Pavilion dv4 series", "<html>Core i5 2.6GHz, 4GB DDR3,<br>500GB,1GB VGA,<br>Win7</html>"),"Laptop_HP_3.jpg", authUser));<br />
panelLaptopHp.add(this.CreateJPanel(new Product(115000, "HP Pavilion dm3t series", "<html>Core dual core 2.4 GHz,<br> 6GB DDR2,320GB,512MB VGA,<br>Win7</html>"),"Laptop_HP_4.jpg", authUser));<br />
return panelLaptopHp;<br />
}<br />
<br />
JPanel dellPanel(User authUser)<br />
{<br />
<br />
JPanel panelLaptopDell= new JPanel();<br />
<br />
panelLaptopDell.add(this.CreateJPanel(new Product(95000, " dell 620", "<html>Core dual core 2.6GHz,<br> 2GB DDR2,<br>320GB,1GB VGA,<br>DOS </html>"),"Laptop_Dell_1.jpg", authUser));<br />
return panelLaptopDell;<br />
<br />
}<br />
<br />
JPanel iBMDeskPanel (User authUser){<br />
JPanel panelIBM = new JPanel();<br />
<br />
panelIBM.add(this.CreateJPanel(new Product(55000, "IBM PC 300 products (Type 6344, 6345)", "<html>Core i3 1.6GHz,<br> 4GB DDR2,<br>320GB,512 MB VGA,<br>Win7</html>"),"Desktop_IBM_1.jpg", authUser));<br />
panelIBM.add(this.CreateJPanel(new Product(49890, "IBM PC 300GL and PC 300XL products", "<html>Core core2-duo 2.6GHz,<br> 2GB DDR3,<br>500GB,1GB VGA,<br>Win7</html>"),"Desktop_IBM_2.jpg", authUser));<br />
panelIBM.add(this.CreateJPanel(new Product(38585, "IBM PC 300PL products (Types 6562, 6592, 6862, 6892)", "<html>Core i7 1.6GHz,<br> 6GB DDR3,<br>640GB,1GB VGA<br>,Win7</html>"),"Desktop_IBM_3.jpg", authUser));<br />
panelIBM.add(this.CreateJPanel(new Product(62000, "IBM PC 300PL products (Types 6565, 6566, 6584, 6594, 6595, 6872, 6890)", "<html>Core i7 1.6GHz,<br> 6GB DDR3,<br>640GB,1GB VGA,<br>Win7</html>"),"Desktop_IBM_4.jpg", authUser));<br />
return panelIBM;<br />
<br />
}<br />
<br />
JPanel hPDeskPanel (User authUser){<br />
JPanel panelHP = new JPanel();<br />
panelHP.add(this.CreateJPanel(new Product(55000, "HP PC products d220 ", "<html>Core i7 1.6GHz,<br> 6GB DDR3,<br>640GB,1GB VGA,<br>Dos</html>"),"Desktop_HP_1.jpg", authUser));<br />
panelHP.add(this.CreateJPanel(new Product(49890, "HP PC and PC 300XL d325", "<html>Core i3 2.6GHz,<br> 6GB DDR3,<br>640GB,1GB VGA,<br>Dos</html>"),"Desktop_HP_2.jpg", authUser));<br />
panelHP.add(this.CreateJPanel(new Product(38585, "HP PC products dc5000", "<html>Core i5 3.2GHz,<br> 4GB DDR3,<br>640GB,1GB VGA,<br>DOs</html>"),"Desktop_HP_3.jpg", authUser));<br />
panelHP.add(this.CreateJPanel(new Product(62000, "HP PC products rp5000", "<html>Core i7 1.6GHz,<br> 6GB DDR3,<br>640GB,1GB VGA,<br>Dos</html>"),"Desktop_HP_4.jpg", authUser));<br />
return panelHP;<br />
}<br />
<br />
JPanel compaqPanel(User authUser) {<br />
JPanel panelLaptopCq = new JPanel();<br />
panelLaptopCq.add(this.CreateJPanel(new Product(65000, " Compaq 620", "<html>Core i3 2.6GHz,<br> 2GB DDR2,<br>320GB,<br>1GB VGA,Dos</html>"),"Laptop_CoQ_1.jpg", authUser));<br />
panelLaptopCq.add(this.CreateJPanel(new Product(75000, "Compaq 420", "<html>Core i5 2.6GHz,<br> 4GB DDR2,<br>500GB,<br>2GB VGA,Dos</html>"),"Laptop_CoQ_2.jpg", authUser));<br />
return panelLaptopCq;<br />
}<br />
<br />
JPanel hardDiskPanel(User authUser){<br />
JPanel panelHardDisk = new JPanel();<br />
panelHardDisk.add(this.CreateJPanel(new Product(5880, "Maxtor", "<Html>Internal<br>500 GB</html>"),"HardDisk_1.jpg", authUser));<br />
panelHardDisk.add(this.CreateJPanel(new Product(13000, "SeaGate", "<Html>External<br>1 TB</html>"),"HardDisk_2.jpg", authUser));<br />
panelHardDisk.add(this.CreateJPanel(new Product(11500, "Toshiba", "<Html>External<br>1 TB</html>"),"HardDisk_3.jpg", authUser));<br />
panelHardDisk.add(this.CreateJPanel(new Product(11500, "Samsung", "<Html>External<br>500 GB</html>"),"HardDisk_4.jpg", authUser));<br />
return panelHardDisk;<br />
}<br />
<br />
JPanel keyBoardPanel(User authUser){<br />
JPanel panelkeyBoard = new JPanel();<br />
panelkeyBoard.add(this.CreateJPanel(new Product(800, "HP", "<Html>Wireless<br>Professional</html>"),"KeyBoard_1.jpg", authUser));<br />
panelkeyBoard.add(this.CreateJPanel(new Product(1200, "A4 tech", "<Html>Wireless<br>Flexible</html>"),"KeyBoard_2.jpg", authUser));<br />
panelkeyBoard.add(this.CreateJPanel(new Product(1200, "HP", "<Html>PS/2<br>Classic</html>"),"KeyBoard_3.jpg", authUser));<br />
panelkeyBoard.add(this.CreateJPanel(new Product(1240, "HP", "<Html>Wireless<br>flexible</html>"),"KeyBoard_4.jpg", authUser));<br />
return panelkeyBoard;<br />
}<br />
<br />
JPanel mousePanel(User authUser){<br />
JPanel panelMouse = new JPanel();<br />
panelMouse.add(this.CreateJPanel(new Product(850, "Mega Box", "<Html>Optical</html>"),"Mouse_1.jpg", authUser));<br />
panelMouse.add(this.CreateJPanel(new Product(750, "A4 tech", "<Html>PS/2</html>"),"Mouse_2.jpg", authUser));<br />
panelMouse.add(this.CreateJPanel(new Product(1050, "Microsoft", "<Html>WireLess</html>"),"Mouse_3.jpg", authUser));<br />
panelMouse.add(this.CreateJPanel(new Product(1150, "Microsoft", "<Html>WireLess gaming</html>"),"Mouse_4.jpg", authUser));<br />
return panelMouse;<br />
}<br />
<br />
JPanel speakerPanel(User authUser){<br />
JPanel panelSpeaker = new JPanel();<br />
<br />
panelSpeaker.add(this.CreateJPanel(new Product(900, " Creative", "<html>2 channel<br> 600 w</html>"),"Speaker_1.jpg", authUser));<br />
panelSpeaker.add(this.CreateJPanel(new Product(1500, "Divoom", "<html>2 channel<br> 800 w</html>"),"Speaker_2.jpg", authUser));<br />
panelSpeaker.add(this.CreateJPanel(new Product(3500, "JBL", "<html>4 channel<br> 800 w</html>"),"Speaker_3.jpg", authUser));<br />
panelSpeaker.add(this.CreateJPanel(new Product(1500, "Sony", "<html>2 channel<br> 800 w</html>"),"Speaker_4.jpg", authUser));<br />
return panelSpeaker;<br />
}<br />
<br />
JPanel mornitorPanel(User authUser){<br />
JPanel panelMorintor = new JPanel();<br />
<br />
panelMorintor.add(this.CreateJPanel(new Product(12000, "HP", "<html>Aspect Ratio:3M color<br> LED</html"),"Mornitor_1.jpg", authUser));<br />
panelMorintor.add(this.CreateJPanel(new Product(14990, "PixelView", "<html>Aspect Ratio:3M color<br> LED<</html"),"Mornitor_2.jpg", authUser));<br />
panelMorintor.add(this.CreateJPanel(new Product(14990, "BenQ", "<html>Aspect Ratio:3M color<br> LCD<</html"),"Mornitor_3.jpg", authUser));<br />
panelMorintor.add(this.CreateJPanel(new Product(14990, "Samsung", "<html>Aspect Ratio:3M color</html"),"Mornitor_4.jpg", authUser));<br />
return panelMorintor;<br />
}<br />
<br />
JPanel motherBoardPanel(User authUser){<br />
JPanel panelMotherBoard= new JPanel();<br />
panelMotherBoard.add(this.CreateJPanel(new Product(6250, "FoxConn ", "<HTML>A 780 GM</HTML>"),"MB_1.jpg", authUser));<br />
panelMotherBoard.add(this.CreateJPanel(new Product(6400, "MSI ", "<HTML>X 68</HTML>"),"MB_2.jpg", authUser));<br />
panelMotherBoard.add(this.CreateJPanel(new Product(8500, "Intel", "<HTML>LGA 775</HTML>"),"MB_3.jpg", authUser));<br />
panelMotherBoard.add(this.CreateJPanel(new Product(6500, "Asus ", "<HTML>LGA 795</HTML>"),"MB_4.jpg", authUser));<br />
return panelMotherBoard;<br />
}<br />
<br />
JPanel vGAPanel(User authUser){<br />
JPanel panelVGA= new JPanel();<br />
panelVGA.add(this.CreateJPanel(new Product(7750, " Nvdia 620 fx", "<HTML>Memory 1 GB</HTML>"),"VGA_1.jpg", authUser));<br />
panelVGA.add(this.CreateJPanel(new Product(7220, "Nvidia 420 fx ", "<HTML>Memory 512 MB</HTML>"),"VGA_2.jpg", authUser));<br />
panelVGA.add(this.CreateJPanel(new Product(7220, "ATI Radeon 8500 mx", "<HTML>Memory 512 MB</HTML>"),"VGA_3.jpg", authUser));<br />
panelVGA.add(this.CreateJPanel(new Product(7220, "ATI Radeon 6500 mx", "<HTML>Memory 256 MB</HTML>"),"VGA_4.jpg", authUser));<br />
return panelVGA;<br />
}<br />
<br />
JPanel processorPanel(User authUser){<br />
JPanel panelProcessor= new JPanel();<br />
panelProcessor.add(this.CreateJPanel(new Product(8000, "Intel", "<html>i7<br>FSB 800hz</html>"),"Processor_1.jpg", authUser));<br />
panelProcessor.add(this.CreateJPanel(new Product(5500, "Intel", "<html>i5<br>FSB 1024hz</html>"),"Processor_2.jpg", authUser));<br />
panelProcessor.add(this.CreateJPanel(new Product(4020, "AMD 64", "<html>i7<br>FSB 800hz</html>"),"Processor_3.jpg", authUser));<br />
panelProcessor.add(this.CreateJPanel(new Product(5000, "Intel Core 2", "<html>64 bit<br>FSB 800hz</html>"),"Processor_4.jpg", authUser));<br />
return panelProcessor;<br />
}<br />
<br />
JPanel casingPanel(User authUser){<br />
JPanel panelCasing= new JPanel();<br />
panelCasing.add(this.CreateJPanel(new Product(1000, " Mercury", "<html><br>ATX</html>"),"Casing_1.jpg", authUser));<br />
panelCasing.add(this.CreateJPanel(new Product(1000, "Sysnon", "<html><br>ATX</html>"),"Casing_2.jpg", authUser));<br />
panelCasing.add(this.CreateJPanel(new Product(1500, "Apple", "<html><br>ATX</html>"),"Casing_3.jpg", authUser));<br />
panelCasing.add(this.CreateJPanel(new Product(1250, "Gigabyte", "<html><br>ATX</html>"),"Casing_4.jpg", authUser));<br />
return panelCasing;<br />
}<br />
<br />
JPanel ramPanel(User authUser){<br />
JPanel panelRam = new JPanel();<br />
<br />
panelRam.add(this.CreateJPanel(new Product(3000, "Kingston ", "<html>2GB<br>DDR2</html>"),"Ram_1.jpg", authUser));<br />
panelRam.add(this.CreateJPanel(new Product(4500, "Gigabyte", "<html>2GB<br>DDR3</html>"),"Ram_2.jpg", authUser));<br />
panelRam.add(this.CreateJPanel(new Product(6000, "Trancend", "<html>4GB<br>DD/r2</html>"),"Ram_3.jpg", authUser));<br />
panelRam.add(this.CreateJPanel(new Product(8500, "eSys", "<html>4GB<br>DDR3</html>"),"Ram_4.jpg", authUser));<br />
return panelRam;<br />
}<br />
private JPanel CreateJPanel(Product p,String img,User authUser)<br />
{<br />
JPanel panelProduct= new JPanel(new FlowLayout(FlowLayout.CENTER,7,8));<br />
panelProduct.setPreferredSize(new Dimension(200,250));<br />
ImageIcon icon = new ImageIcon("src//Images//"+img);<br />
JLabel label = new JLabel(p.getDescription());<br />
<br />
label.setVerticalTextPosition(JLabel.BOTTOM);<br />
label.setHorizontalTextPosition(JLabel.CENTER);<br />
label.setForeground(Color.BLACK);<br />
label.setIcon(icon);<br />
label.setForeground(Color.BLUE);<br />
label.setFont(new Font("Trebuchet", Font.BOLD, 12));<br />
label.setToolTipText("<HTml>"+p.getName()+"<br> "+p.getDescription());<br />
<br />
JLabel lblprice = new JLabel( "Rs. "+p.getPrice());<br />
lblprice.setVerticalTextPosition(JLabel.BOTTOM);<br />
lblprice.setHorizontalTextPosition(JLabel.CENTER);<br />
JCheckBox jchkBoxHpLap = new JCheckBox("Buy");<br />
<br />
JComboBox jcmbQty = new JComboBox(new Integer[]{1,2,3,4,5,6,7,8,9,10});<br />
p.setQuantity((Integer)jcmbQty.getSelectedItem());<br />
jcmbQty.addActionListener(new ComboListener(p));<br />
<br />
jchkBoxHpLap.addItemListener(new MyCheckBoxListener(p,authUser,productSel));<br />
<br />
panelProduct.add(label,BorderLayout.NORTH);<br />
panelProduct.add(lblprice,BorderLayout.CENTER);<br />
panelProduct.add(jchkBoxHpLap);<br />
panelProduct.add(jcmbQty);<br />
panelProduct.setBorder(new LineBorder(Color.cyan,1));<br />
<br />
return panelProduct;<br />
}<br />
}<br />
<br />
class MyCheckBoxListener implements ItemListener {<br />
<br />
User customer;<br />
Product product;<br />
ProductSelection prodSel;<br />
<br />
MyCheckBoxListener(Product p, User authUser,ProductSelection prodSel) {<br />
customer = authUser;<br />
this.product = p;<br />
this.prodSel = prodSel;<br />
}<br />
<br />
public void itemStateChanged(ItemEvent e) {<br />
<br />
if (e.getStateChange() == ItemEvent.SELECTED)<br />
customer.purchasedProducts.add(product);<br />
else<br />
customer.purchasedProducts.remove(product);<br />
<br />
this.updateJList(customer.purchasedProducts);<br />
<br />
}<br />
<br />
void updateJList(ArrayList<Product> arr)<br />
{<br />
prodSel.listmodel.clear();<br />
double dblAmount = 0.0;<br />
<br />
for (Product p : arr)<br />
{<br />
prodSel.listmodel.addElement(p.getName()+" "+p.getPrice()+" x"+p.getQuantity());<br />
dblAmount += p.getPrice()*p.getQuantity();<br />
}<br />
<br />
prodSel.lblAmount.setText("Total Amount : "+dblAmount);<br />
prodSel.Amount = dblAmount;<br />
}<br />
<br />
}<br />
class ComboListener implements ActionListener{<br />
Product selPro;<br />
ComboListener(Product p){<br />
this.selPro = p;<br />
}<br />
public void actionPerformed(ActionEvent e) {<br />
JComboBox jcmbQty = (JComboBox)e.getSource();<br />
selPro.setQuantity((Integer)jcmbQty.getSelectedItem());<br />
}<br />
<br />
}<br />
<br />
package OnlineShop;<br />
<br />
/**<br />
*<br />
* @author Roshan<br />
*/<br />
public class Product {<br />
<br />
private double price;<br />
private String name;<br />
private String description;<br />
private int quantity;<br />
Product(double price , String name,String description){<br />
this.price = price;<br />
this.name = name;<br />
this.description = description;<br />
<br />
}<br />
protected void setQuantity(int qnt){<br />
this.quantity = qnt;<br />
}<br />
protected double getPrice(){<br />
return this.price;<br />
}<br />
protected String getName(){<br />
return this.name;<br />
}<br />
protected String getDescription(){<br />
return this.description;<br />
}<br />
protected int getQuantity(){<br />
return this.quantity;<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
package OnlineShop;<br />
<br />
/**<br />
*<br />
* @author Roshan<br />
*/<br />
import java.awt.*;<br />
import java.awt.Color;<br />
import java.awt.event.ActionEvent;<br />
import java.awt.event.ActionListener;<br />
import javax.swing.*;<br />
import javax.swing.border.LineBorder;<br />
<br />
import javax.swing.event.TreeSelectionEvent;<br />
import javax.swing.event.TreeSelectionListener;<br />
import javax.swing.tree.DefaultMutableTreeNode;<br />
import javax.swing.tree.TreeSelectionModel;<br />
<br />
public class ProductSelection {<br />
<br />
protected User buyer;<br />
protected JTree tree;<br />
protected JFrame frame;<br />
protected JList purchaseProduct;<br />
protected JPanel currentPanel;<br />
protected JPanel jplLaptopHP;<br />
protected JPanel jplLaptopCQ;<br />
protected JPanel jplLaptopDell;<br />
protected JPanel jplDesktopIBM;<br />
protected JPanel jplDesktopHP;<br />
protected JPanel jplHardDisk;<br />
protected JPanel jplMornitor;<br />
protected JPanel jplMouse;<br />
protected JPanel jplSpeaker;<br />
protected JPanel jplKeyBoard;<br />
protected JPanel jplMotherBoard;<br />
protected JPanel jplVGA;<br />
protected JPanel jplProcessor;<br />
protected JPanel jplRAM;<br />
protected JPanel jplCasing;<br />
protected DefaultListModel listmodel;<br />
protected JLabel lblAmount;<br />
protected JPanel jpnlAmount;<br />
protected double Amount;<br />
private javax.swing.JDialog jDialog1;<br />
<br />
ProductSelection(User authUser) {<br />
this.buyer = authUser;<br />
currentPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 80, 40));<br />
ImagePanel lp = new ImagePanel(this);<br />
this.jplLaptopHP = lp.hpPanel(authUser);<br />
this.jplLaptopCQ = lp.compaqPanel(authUser);<br />
this.jplLaptopDell = lp.dellPanel(authUser);<br />
this.jplDesktopIBM = lp.iBMDeskPanel(authUser);<br />
this.jplDesktopHP = lp.hPDeskPanel(authUser);<br />
this.jplKeyBoard = lp.keyBoardPanel(authUser);<br />
this.jplMornitor = lp.mornitorPanel(authUser);<br />
this.jplMouse = lp.mousePanel(authUser);<br />
this.jplSpeaker = lp.speakerPanel(authUser);<br />
this.jplMotherBoard = lp.motherBoardPanel(authUser);<br />
this.jplHardDisk = lp.hardDiskPanel(authUser);<br />
this.jplVGA = lp.vGAPanel(authUser);<br />
this.jplProcessor = lp.processorPanel(authUser);<br />
this.jplRAM = lp.ramPanel(authUser);<br />
this.jplCasing = lp.casingPanel(authUser);<br />
}<br />
<br />
void display() {<br />
User ObjUser = new User();<br />
frame = new JFrame("WELCOME " + ObjUser.getLoginName().toUpperCase() + " !");<br />
JScrollPane scroll = new JScrollPane();<br />
<br />
DefaultMutableTreeNode root = new DefaultMutableTreeNode("ECSE501 Computers");<br />
DefaultMutableTreeNode nodeLaptop = new DefaultMutableTreeNode("Laptop");<br />
root.add(nodeLaptop);<br />
//****************************<br />
DefaultMutableTreeNode nodeLaptopHp = new DefaultMutableTreeNode(" HP");<br />
DefaultMutableTreeNode nodeLaptopCq = new DefaultMutableTreeNode(" Compaq");<br />
DefaultMutableTreeNode nodeLaptopDell = new DefaultMutableTreeNode(" Dell");<br />
nodeLaptop.insert(nodeLaptopHp, 0);<br />
nodeLaptop.insert(nodeLaptopCq, 1);<br />
nodeLaptop.insert(nodeLaptopDell, 2);<br />
<br />
//*******************************<br />
DefaultMutableTreeNode nodeDesktop = new DefaultMutableTreeNode("Desktop");<br />
DefaultMutableTreeNode nodeDeskTopIBM = new DefaultMutableTreeNode("Desk-IBM");<br />
DefaultMutableTreeNode nodeDeskTopHp = new DefaultMutableTreeNode("Desk-HP");<br />
nodeDesktop.insert(nodeDeskTopIBM, 0);<br />
nodeDesktop.insert(nodeDeskTopHp, 1);<br />
root.add(nodeDesktop);<br />
//*****************************************<br />
DefaultMutableTreeNode nodeAccessories = new DefaultMutableTreeNode("Accessories");<br />
DefaultMutableTreeNode nodeKeyBoard = new DefaultMutableTreeNode("KeyBoard");<br />
DefaultMutableTreeNode nodeMornitor = new DefaultMutableTreeNode("Mornitor");<br />
DefaultMutableTreeNode nodeMouse = new DefaultMutableTreeNode("Mouse");<br />
DefaultMutableTreeNode nodeSpeaker = new DefaultMutableTreeNode("Speaker");<br />
<br />
nodeAccessories.insert(nodeKeyBoard, 0);<br />
nodeAccessories.insert(nodeMornitor, 1);<br />
nodeAccessories.insert(nodeMouse, 2);<br />
nodeAccessories.insert(nodeSpeaker, 3);<br />
<br />
root.add(nodeAccessories);<br />
DefaultMutableTreeNode nodeAssemble = new DefaultMutableTreeNode("Assemble");<br />
DefaultMutableTreeNode nodeMotherBoard = new DefaultMutableTreeNode("MotherBoard");<br />
<br />
DefaultMutableTreeNode nodeHardDisk = new DefaultMutableTreeNode("HardDisk");<br />
DefaultMutableTreeNode nodeVGA = new DefaultMutableTreeNode("VGA");<br />
DefaultMutableTreeNode nodeProcessor = new DefaultMutableTreeNode("Processor");<br />
DefaultMutableTreeNode nodeCasing = new DefaultMutableTreeNode("Casing");<br />
DefaultMutableTreeNode nodeRAM = new DefaultMutableTreeNode("RAM");<br />
<br />
nodeAssemble.insert(nodeMotherBoard, 0);<br />
nodeAssemble.insert(nodeHardDisk, 1);<br />
nodeAssemble.insert(nodeVGA, 2);<br />
nodeAssemble.insert(nodeProcessor, 3);<br />
nodeAssemble.insert(nodeRAM, 4);<br />
nodeAssemble.insert(nodeCasing, 5);<br />
<br />
root.add(nodeAssemble);<br />
<br />
//*******************************************<br />
<br />
JPanel jpnlTree = new JPanel();<br />
tree = new JTree(root);<br />
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);<br />
<br />
<br />
tree.addTreeSelectionListener(new MyTreeSelectionListener(this, buyer));<br />
<br />
<br />
jpnlTree.add(new JScrollPane(tree));<br />
jpnlTree.setBackground(Color.LIGHT_GRAY);<br />
jpnlTree.setSize(new Dimension(100, 500));<br />
listmodel = new DefaultListModel();<br />
purchaseProduct = new JList(listmodel);<br />
<br />
purchaseProduct.setPreferredSize(new Dimension(240, 490));<br />
purchaseProduct.setLayoutOrientation(JList.VERTICAL);<br />
purchaseProduct.setBorder(new LineBorder(Color.GRAY, 3));<br />
JPanel jpnlList = new JPanel(new FlowLayout(FlowLayout.CENTER, 40, 20));<br />
jpnlList.setBorder(new LineBorder(Color.DARK_GRAY, 3));<br />
<br />
jpnlList.setPreferredSize(new Dimension(265, JFrame.HEIGHT));<br />
JLabel lblPurchase = new JLabel("Your Cart");<br />
lblPurchase.setFont(new Font("Calibri", Font.BOLD, 15));<br />
lblPurchase.setForeground(Color.darkGray);<br />
JButton btnPurchase = new JButton("Purchase");<br />
btnPurchase.setActionCommand("Purchase");<br />
btnPurchase.addActionListener(new MyRemActionListener(this));<br />
<br />
jpnlList.add(lblPurchase);<br />
<br />
JScrollPane scrollPane = new JScrollPane(purchaseProduct);<br />
scrollPane.setPreferredSize(new Dimension(250, 490));<br />
jpnlList.add(scrollPane, BorderLayout.CENTER);<br />
<br />
//jpnlList.add(new JScrollPane(purchaseProduct));<br />
<br />
<br />
jpnlList.add(btnPurchase);<br />
this.lblAmount = new JLabel("here i am ");<br />
<br />
lblAmount.setFont(new Font("Calibri", Font.BOLD, 14));<br />
<br />
<br />
this.lblAmount = new JLabel();<br />
jpnlList.setBackground(Color.LIGHT_GRAY);<br />
<br />
jpnlAmount = new JPanel(new FlowLayout(FlowLayout.CENTER, 80, 40));<br />
jpnlAmount.add(lblAmount);<br />
jpnlAmount.setBorder(new LineBorder(Color.DARK_GRAY, 3));<br />
<br />
JPanel jpnlgreet = new JPanel();<br />
jpnlgreet.setBackground(Color.GREEN);<br />
JLabel lblGreet = new JLabel("WELCOME TO ECSE501 COMPUTERS ");<br />
lblGreet.setFont(new Font("Calibri", Font.BOLD, 16));<br />
jpnlgreet.add(lblGreet);<br />
JLabel lblBanner = new JLabel();<br />
lblBanner.setIcon(new ImageIcon("src//Images//Banner.jpg"));<br />
<br />
currentPanel.add(lblBanner, BorderLayout.CENTER);<br />
frame.getContentPane().add(jpnlList, BorderLayout.EAST);<br />
frame.getContentPane().add(currentPanel, BorderLayout.CENTER);<br />
frame.getContentPane().add(jpnlgreet, BorderLayout.NORTH);<br />
frame.getContentPane().setBackground(Color.WHITE);<br />
frame.getContentPane().add(jpnlTree, BorderLayout.WEST);<br />
frame.getContentPane().add(jpnlAmount, BorderLayout.PAGE_END);<br />
frame.setSize(1250, 900);<br />
frame.setVisible(true);<br />
<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
<br />
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();<br />
<br />
// Determine the new location of the window<br />
int w = frame.getSize().width;<br />
int h = frame.getSize().height;<br />
int x = (dim.width - w) / 2;<br />
int y = (dim.height - h) / 2;<br />
<br />
// Move the window<br />
frame.setLocation(x, y);<br />
<br />
}<br />
}<br />
<br />
class MyTreeSelectionListener implements TreeSelectionListener {<br />
<br />
ProductSelection tr;<br />
User authUser;<br />
<br />
MyTreeSelectionListener(ProductSelection tr, User authUser) {<br />
this.tr = tr;<br />
this.authUser = authUser;<br />
<br />
}<br />
<br />
public void valueChanged(TreeSelectionEvent e) {<br />
<br />
try {<br />
if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("HP")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplLaptopHP);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1250, 901);<br />
<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("Compaq")) {<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplLaptopCQ);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1251, 901);<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("Dell")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplLaptopDell);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1251, 900);<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("Desk-IBM")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplDesktopHP);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1252, 902);<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("Desk-HP")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplDesktopIBM);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1253, 901);<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("KeyBoard")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplKeyBoard);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1254, 900);<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("Mornitor")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplMornitor);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1250, 905);<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("Mouse")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplMouse);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1250, 906);<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("Speaker")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplSpeaker);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1250, 907);<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("MotherBoard")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplMotherBoard);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1250, 910);<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("HardDisk")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplHardDisk);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1250, 901);<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("VGA")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplVGA);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1250, 902);<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("Processor")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplProcessor);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1250, 915);<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("RAM")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplRAM);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1251, 901);<br />
} else if (tr.tree.getLastSelectedPathComponent().toString().trim().equals("Casing")) {<br />
<br />
tr.currentPanel.removeAll();<br />
tr.currentPanel.add(tr.jplCasing);<br />
tr.currentPanel.invalidate();<br />
tr.currentPanel.validate();<br />
tr.frame.setSize(1251, 902);<br />
}<br />
} catch (Exception ex) {<br />
}<br />
<br />
}<br />
}<br />
<br />
class MyRemActionListener implements ActionListener {<br />
<br />
ProductSelection prodSel;<br />
<br />
MyRemActionListener(ProductSelection prodSel) {<br />
this.prodSel = prodSel;<br />
}<br />
<br />
public void actionPerformed(ActionEvent e) {<br />
<br />
if (e.getActionCommand().equals("Purchase")) {<br />
if (!prodSel.listmodel.isEmpty()) {<br />
Object obj[] = {"Pay", "Back"};<br />
Object Pay[] = {"Credi Card", "Cash"};<br />
int showOptionObj = JOptionPane.showOptionDialog(null, "Please, select your Option", "Option", JOptionPane.YES_NO_OPTION, JOptionPane.OK_OPTION, null, obj, obj[0]);<br />
boolean isback = false;<br />
<br />
switch (showOptionObj) {<br />
case 0:<br />
prodSel.frame.setVisible(true);<br />
JOptionPane.showMessageDialog(null, "<html> <b>Your Amount is " + prodSel.Amount + "</b></html>");<br />
//System.exit(0);<br />
break;<br />
case 1:<br />
prodSel.frame.setVisible(true);<br />
isback = true;<br />
break;<br />
default:<br />
System.exit(0);<br />
}<br />
<br />
if (!isback) {<br />
int showOptionPay = JOptionPane.showOptionDialog(null, "Please, select Payment Method", "Payment", JOptionPane.YES_NO_OPTION, JOptionPane.OK_OPTION, null, Pay, Pay[0]);<br />
<br />
switch (showOptionPay) {<br />
case 0:<br />
prodSel.frame.setVisible(true);<br />
JOptionPane.showInputDialog(null, "Enter Credit Card Number", "PayPal", JOptionPane.PLAIN_MESSAGE);<br />
JOptionPane.showMessageDialog(null, "Thank You! your items will be deliverd with in next two working days.", "Credited", JOptionPane.INFORMATION_MESSAGE);<br />
System.exit(0);<br />
break;<br />
case 1:<br />
prodSel.frame.setVisible(true);<br />
JOptionPane.showMessageDialog(null, "Thank You! your items will be deliverd with in next two working days.", "Receipt", JOptionPane.INFORMATION_MESSAGE);<br />
System.exit(0);<br />
break;<br />
default:<br />
System.exit(0);<br />
}<br />
}<br />
} else {<br />
JOptionPane.showMessageDialog(null, "Your Cart is Empty, Please select items to purchase", "Empty Cart", JOptionPane.ERROR_MESSAGE);<br />
}<br />
<br />
}<br />
<br />
<br />
}<br />
}<br />
package OnlineShop;<br />
import java.util.ArrayList;<br />
<br />
<br />
/**<br />
*<br />
* @author Roshan<br />
*/<br />
<br />
public class User {<br />
String password = "admin123";<br />
String loginName = "admin";<br />
<br />
ArrayList<Product> purchasedProducts = new ArrayList<Product>();<br />
<br />
protected String getPassword (){<br />
return this.password;<br />
}<br />
protected String getLoginName(){<br />
return this.loginName;<br />
}<br />
}Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com1tag:blogger.com,1999:blog-3193939776097058901.post-45317333441028372222011-01-03T21:28:00.000-08:002011-01-03T21:28:03.411-08:00caculator with javapublic class ArithmeticAddition extends ArithmeticExpression {<br />
<br />
public double Evaluate(double dblFValue,double dblSValue){<br />
return dblFValue+dblSValue;<br />
}<br />
}<br />
<br />
public class ArithmeticDivision extends ArithmeticExpression {<br />
<br />
<br />
public double Evaluate(double dblFValue, double dblSValue) {<br />
if (dblSValue != 0)<br />
return dblFValue/dblSValue;<br />
else<br />
return 0;<br />
}<br />
<br />
}<br />
<br />
public abstract class ArithmeticExpression {<br />
<br />
ArithmeticExpression(){}<br />
public ArithmeticExpression(double dblFValue,double dblSValue) {<br />
<br />
}<br />
<br />
<br />
private double _dblValue;<br />
<br />
public double getValue(){<br />
return this._dblValue;<br />
}<br />
public void setValue(double dblValue){<br />
this._dblValue= dblValue;<br />
}<br />
<br />
public abstract double Evaluate(double dblFValue,double dblSValue);<br />
<br />
public void Display(String expression){<br />
System.out.println("Expression :\t"+expression);<br />
}<br />
<br />
}<br />
<br />
public class ArithmeticMultiplication extends ArithmeticExpression{<br />
<br />
<br />
public double Evaluate(double dblFValue, double dblSValue) {<br />
return dblFValue*dblSValue;<br />
}<br />
<br />
}<br />
<br />
public class ArithmeticSubstraction extends ArithmeticExpression {<br />
<br />
<br />
public double Evaluate(double dblFValue, double dblSValue) {<br />
return dblFValue- dblSValue;<br />
}<br />
<br />
<br />
}<br />
<br />
import java.util.Scanner;<br />
public class Calculator {<br />
public static void main(String[] args) {<br />
<br />
Scanner scnRead =new Scanner (System.in);<br />
System.out.println("Enter :");<br />
String strExpression = scnRead.nextLine(); <br />
int ParseExpression = new Calculator().ParseExpression(strExpression);<br />
System.out.println(ParseExpression);<br />
}<br />
<br />
private int ParseExpression(String expression)<br />
{<br />
int winningLevel = 0;<br />
byte winningTokenWeight = 0;<br />
int winningPos = 0;<br />
<br />
int level = 0;<br />
int pos = 0;<br />
<br />
for (char token :expression.toCharArray())<br />
{<br />
pos++;<br />
<br />
switch (token)<br />
{<br />
case '(':<br />
level++;<br />
break;<br />
case ')':<br />
level--;<br />
break;<br />
}<br />
<br />
if (level <= winningLevel)<br />
{<br />
if (OperatorWeight(token) > winningTokenWeight)<br />
{<br />
winningLevel = level;<br />
winningTokenWeight = OperatorWeight(token);<br />
winningPos = pos;<br />
}<br />
}<br />
}<br />
return winningPos;<br />
}<br />
private byte OperatorWeight(char value)<br />
{<br />
switch (value)<br />
{<br />
case '+':<br />
case '-':<br />
return 3;<br />
case '*':<br />
return 2;<br />
case '/':<br />
return 1;<br />
default:<br />
return 0;<br />
}<br />
}<br />
}Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com0tag:blogger.com,1999:blog-3193939776097058901.post-53874903278488498992011-01-03T21:14:00.000-08:002011-01-03T21:14:10.802-08:00javaScript to disable radio button according to a label<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><br />
<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head runat="server"><br />
<title></title><br />
</head><br />
<body><br />
<form id="frm1" runat="server"><br />
<%--<table width="100%"><br />
<tr><br />
<td> <asp:RadioButton ID="rdbBase" Text="Base" runat="server" /> <br />
</td><br />
<td><br />
<asp:RadioButton ID="rdb1" Text="1 year" runat="server" /> <br />
</td><br />
<td><br />
<asp:RadioButton ID="rdb2" Text="2 year" runat="server" /> <br />
<asp:Label ID="Label1" runat="server" Text="hi"></asp:Label><br />
</td><br />
</tr><br />
<tr><br />
<td><asp:RadioButton ID="rdbBotG" Text="BOTG" runat="server" onclick ="test()" GroupName="grpBot"/> <br />
</td><br />
<td colspan="2"></td><br />
</tr><br />
<tr><br />
<td><asp:RadioButton ID="rdbBotGTurbo" Text="Turbo" runat="server" onclick ="test()" GroupName="grpBot"/> <br />
</td><br />
<td colspan="2"></td><br />
</tr><br />
</table>--%><br />
<%--<table ><br />
<tr><br />
<td><br />
<asp:RadioButton ID="RadioButton1" runat="server" onClick ="test()" /><br />
<br />
</td><br />
</tr><br />
<tr><br />
<td><br />
<asp:RadioButton ID="RadioButton2" runat="server" /><br />
<br />
</td><br />
</tr><br />
<tr><br />
<td><br />
<asp:RadioButton ID="RadioButton3" runat="server" Checked="false" /><br />
<br />
</td><br />
</tr><br />
</table>--%><br />
<table><br />
<tr><br />
<td><br />
<asp:GridView ID="gvTest" runat="server" AutoGenerateColumns="False"<br />
GridLines="Horizontal" Width="600px"><br />
<Columns><br />
<asp:TemplateField><br />
<HeaderTemplate><br />
<table cellpadding="0" cellspacing="0" border="0" width="100%"><br />
<tr id="trResidential" runat="server"><br />
<td width="5%" align="left"><br />
</td><br />
<td width="14%" style="text-align: left; color: #3366cc;"><br />
Residential<br />
</td><br />
<td width="20%" style="text-align: center;"><br />
<asp:RadioButton ID="rdbResidBasePackage" <br />
GroupName="gnResidential"<br />
runat="server" /><br />
</td><br />
<td width="20%" style="text-align: center"><br />
<asp:RadioButton ID="rdbResid1Year" <br />
GroupName="gnResidential" runat="server" /><br />
</td><br />
<td width="20%" style="text-align: center"><br />
<asp:RadioButton ID="rdbResid2Year" GroupName="gnResidential"<br />
runat="server" /><br />
<br />
</td><br />
<br />
</tr><br />
<tr><br />
<td width="5%"><br />
</td><br />
<td width="14%" style="text-align: center;"><br />
Speed<br />
</td><br />
<td width="20%" style="text-align: center;"><br />
Base Package<br />
</td><br />
<td width="20%" style="text-align: center"><br />
1 Year<br />
</td><br />
<td width="20%" style="text-align: center"><br />
2 Year<br />
</td><br />
<br />
</tr><br />
</table><br />
</HeaderTemplate><br />
<ItemTemplate><br />
<table cellpadding="0" cellspacing="0" border="0" width="100%"><br />
<tr><br />
<td width="5%"><br />
<br />
<asp:RadioButton ID="rdbTest" runat="server" GroupName="grpT" onclick ="HighlightRow(this)"<br />
/><br />
</td><br />
<td width="14%" style="text-align: center;"><br />
<asp:Label ID="lblName" runat="server" Text='<%# Bind("name")%>'></asp:Label><br />
</td><br />
<td width="20%" style="text-align: right; padding-right: 40px;"><br />
<asp:Label ID="lblBasePackage" runat="server" Text='<%# Bind("speed")%>'></asp:Label><br />
</td><br />
<td width="20%" style="text-align: right; padding-right: 40px;"><br />
<asp:Label ID="lbl1Year" runat="server" Text='<%# Bind("year1")%>'></asp:Label><br />
</td><br />
<td width="20%" style="text-align: right; padding-right: 40px;"><br />
<asp:Label ID="lbl2Year" runat="server" Text='<%# Bind("year2")%>'></asp:Label><br />
</td> <br />
</tr><br />
</table><br />
</ItemTemplate><br />
</asp:TemplateField><br />
</Columns><br />
<br />
<br />
</asp:GridView><br />
</td><br />
</tr><br />
</table><br />
</form><br />
</body><br />
<br />
<script language="javascript" type="text/javascript"><br />
function test() {<br />
try {<br />
<br />
if (document.getElementById("rdbBotGTurbo").checked == true) {<br />
document.getElementById("gvTest").checked = false;<br />
document.getElementById("gvTest").disabled = true;<br />
}<br />
else {<br />
document.getElementById("rdb2").disabled = false;<br />
}<br />
}<br />
catch (err) {<br />
alert(err.description);<br />
}<br />
}<br />
function HighlightRow(chkB) {<br />
try {<br />
<br />
var IsChecked = chkB.checked;<br />
<br />
if (IsChecked) {<br />
<br />
var mylist = chkB.parentNode.parentNode;<br />
//alert(trim(mylist.cells[1].innerHTML)); <br />
if (trim(mylist.cells[1].innerHTML) == "<span id=\"gvTest_ctl03_lblName\">BotGTurbo<\/span>") {<br />
// alert("got it ");<br />
document.getElementById("gvTest_ctl01_rdbResid2Year").checked = false;<br />
document.getElementById("gvTest_ctl01_rdbResid2Year").disabled = true;<br />
<br />
}<br />
<br />
else {<br />
// alert("Enable");<br />
document.getElementById("gvTest_ctl01_rdbResid2Year").disabled = false;<br />
} <br />
}<br />
}<br />
catch (err) {<br />
alert("Err" + err.description);<br />
}<br />
<br />
}<br />
<br />
function trim(stringToTrim) {<br />
return stringToTrim.replace(/^\s+|\s+$/g, "");<br />
}<br />
<br />
</script><br />
<br />
</html><br />
Anonymoushttp://www.blogger.com/profile/03246793416521115357noreply@blogger.com1