mnj83

slip 17

Mar 17th, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. Q1
  2. import java.io.*;
  3.  
  4. abstract class Staff
  5. {
  6. String name,address;
  7. abstract void accept()throws IOException;
  8. abstract void display();
  9. }
  10. class FullTimeStaff extends Staff
  11. {
  12. String dept;
  13. double salary;
  14. void accept() throws IOException
  15. {
  16. DataInputStream dis=new DataInputStream(System.in);
  17. System.out.print("\nEnter Name : ");
  18. name=dis.readLine();
  19. System.out.print("\nEneter Address : ");
  20. address=dis.readLine();
  21. System.out.print("\nEnter Depatment : ");
  22. dept=dis.readLine();
  23. System.out.print("\nEnter Salary : ");
  24. salary=Double.parseDouble(dis.readLine());
  25. }
  26. void display()
  27. {
  28. System.out.println(name+"\t"+address+"\t"+dept+"\t"+salary);
  29. }
  30. }
  31. class PartTimeStaff extends Staff
  32. {
  33. int no_of_hr;
  34. double rate_per_hr;
  35. void accept() throws IOException
  36. {
  37. DataInputStream dis=new DataInputStream(System.in);
  38. System.out.print("\nEnter Name : ");
  39. name=dis.readLine();
  40. System.out.print("\nEneter Address : ");
  41. address=dis.readLine();
  42. System.out.print("\nEnter No. of hour : ");
  43. no_of_hr=Integer.parseInt(dis.readLine());
  44. System.out.print("\nEnter Rate per Hour : ");
  45. rate_per_hr=Double.parseDouble(dis.readLine());
  46. }
  47. void display()
  48. {
  49. System.out.println(name+"\t"+address+"\t"+no_of_hr+"\t"+rate_per_hr);
  50. }
  51. }
  52.  
  53.  
  54. public class StaffDemo
  55. {
  56. public static void main(String args[]) throws IOException
  57. {
  58. DataInputStream dis=new DataInputStream(System.in);
  59. System.out.print("\nHow many objects u want to create = ");
  60. int n=Integer.parseInt(dis.readLine());
  61. System.out.print("\nMENU\n1)FullTimeStaff objects\n2)PartTimeStaff\nENTER YOUR CHOICE 1 OR 2 :");
  62. int choice=Integer.parseInt(dis.readLine());
  63.  
  64. switch(choice)
  65. {
  66. case 1: FullTimeStaff s[]=new FullTimeStaff[n];
  67. System.out.println("ACCEPTING INFORMATION OF FULL TIME STAFF");
  68. for(int i=0;i<n;i++)
  69. { s[i]=new FullTimeStaff();
  70. s[i].accept();
  71. }
  72. System.out.println("\nDISPLAYING INFORMATION OF FULL TIME STAFF ");
  73. System.out.println("\nNAME\tADRESS\tDEPARTMENT\tSALARY");
  74.  
  75. for(int i=0;i<n;i++)
  76. {
  77. s[i].display();
  78. }
  79. break;
  80.  
  81. case 2:
  82. PartTimeStaff t[]=new PartTimeStaff[n];
  83. System.out.println("ACCEPTING INFORMATION OF PART TIME STAFF");
  84. for(int i=0;i<n;i++)
  85. { t[i]=new PartTimeStaff();
  86. t[i].accept();
  87. }
  88. System.out.println("\nDISPLAYING INFORMATION OF FULL TIME STAFF ");
  89. System.out.println("\nNAME\tADRESS\tNUM OF HOUR\tRATE PER HOUR");
  90.  
  91. for(int i=0;i<n;i++)
  92. {
  93. t[i].display();
  94. }
  95. break;
  96.  
  97.  
  98. }
  99.  
  100.  
  101. }
  102. }
  103.  
  104. Q2
  105. Html.file
  106.  
  107. <form method="GET" action="http://localhost:8080/servlets-examples/servlet/LoginServlet">
  108. Login : <input type="text" name="login"><br>
  109. Password : <input type="password" name="password"><br>
  110. <input type="submit"><input type="reset">
  111. </form>
  112.  
  113. import java.io.*;
  114. import javax.servlet.*;
  115. import javax.servlet.http.*;
  116. import java.sql.*;
  117. public class LoginServlet extends HttpServlet
  118. {
  119. public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
  120. {
  121. res.setContentType("text/html");
  122. PrintWriter pw=res.getWriter();
  123.  
  124. try
  125. {
  126. String login=req.getParameter("login");
  127. String password=req.getParameter("password");
  128.  
  129. Connection con=null;
  130. Statement stmt=null;
  131. ResultSet rs=null;
  132.  
  133. Class.forName("org.postgresql.Driver");
  134. con=DriverManager.getConnection("jdbc:postgresql://localhost/tydb","root","");
  135.  
  136. stmt=con.createStatement();
  137. rs=stmt.executeQuery("select * from Login");
  138. boolean flag=false;
  139. while(rs.next())
  140. {
  141. String l=rs.getString(1);
  142. String p=rs.getString(2);
  143.  
  144.  
  145. if(login.equals(l) && password.equals(p))
  146. {
  147. flag=true;
  148. break;
  149. }
  150.  
  151. }
  152. if(flag==true)
  153. {
  154. pw.println("Login Succesfully....");
  155. }
  156. else
  157. {
  158. pw.println("Login Failed....");
  159. }
  160.  
  161. pw.close();
  162. }
  163. catch(Exception e)
  164. {
  165. pw.println(e);
  166. }
  167. }
  168. }
Add Comment
Please, Sign In to add comment