Wednesday, 24 January 2018

Advancedjava-Slip4



Slip4
Q1. Write a java program to display “Hello Java” message n times on the screen. (Use Runnable Interface).
class mythread implements Runnable
{
Thread t;
public mythread(String title)
{
t=new Thread(this,title);
t.start();
}
public void run()
{
for(int i=0;i<50;i++)
{
System.out.println((i+1)+"ThreadName:"+Thread.currentThread().getName());
try
{
Thread.sleep(100);
}
catch(Exception e)
{
}
}
}
}
public class thread5
{
public static void main(String a [])
{
System.out.println("ThreadName:"+Thread.currentThread().getName());
mythread mt=new mythread("Hello Java");
}
}   

                                                                                                                                    
Q2. Write a JSP program to create an online shopping mall. User must be allowed to do purchase from two pages. Each page should have a page total. The third page should display a bill, which consists of a page total of whatever the purchase has been done and print the total.       (Use Session)



Page1.html

<form method='post' action='page1.jsp'>
<h3>Page 1</h3>
<h4>Select Your Product:</h4>
<input type='checkbox' name='prod' value=10>Pencil<br>
<input type='checkbox' name='prod' value=30>Pen<br>
<input type='checkbox' name='prod' value=5>Eraser<br>
<input type='checkbox' name='prod' value=8>Scale<br>
<input type='checkbox' name='prod' value=45>Note Book<br>
<input type='submit'><input type='reset'>
</form>                                                                                                                                              

page1.jsp

<%
String s[] = request.getParameterValues("prod");
int tot=0;
for(int i=0;i<s.length;i++){
tot+=Integer.parseInt(s[i]);
}
session.setAttribute("tot1", tot);
response.sendRedirect("Page2.html");
%>


Page2.html
<form method='post' action='page2.jsp'>
<h3>Page 2</h3>
<h4>Select Your Product:</h4>
<input type='checkbox' name='prod' value=1300>Jeans<br>
<input type='checkbox' name='prod' value=500>Shirt<br>
<input type='checkbox' name='prod' value=2500>Saree<br>
<input type='checkbox' name='prod' value=750>Trouser<br>
<input type='checkbox' name='prod' value=400>T-Shirt<br>
<input type='submit'><input type='reset'>
</form>




page2.jsp
<%
String s[] = request.getParameterValues("prod");
int tot=0;
for(int i=0;i<s.length;i++){
tot+=Integer.parseInt(s[i]);
}
int tot1 = Integer.parseInt(session.getAttribute("tot1").toString());
%>
<table border=1>
<tr><td><b>Page 1:</b></td><td>Rs.<%=tot1%>/-</td></tr>
<tr><td><b>Page 2:</b></td><td>Rs.<%=tot%>/-</td></tr>
<tr><td><b>Grand Total:</b></td><td>Rs.<%=tot1+tot%>/-</td></tr>
</table>