Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Q1
- import java.io.*;
- abstract class Staff
- {
- String name,address;
- abstract void accept()throws IOException;
- abstract void display();
- }
- class FullTimeStaff extends Staff
- {
- String dept;
- double salary;
- void accept() throws IOException
- {
- DataInputStream dis=new DataInputStream(System.in);
- System.out.print("\nEnter Name : ");
- name=dis.readLine();
- System.out.print("\nEneter Address : ");
- address=dis.readLine();
- System.out.print("\nEnter Depatment : ");
- dept=dis.readLine();
- System.out.print("\nEnter Salary : ");
- salary=Double.parseDouble(dis.readLine());
- }
- void display()
- {
- System.out.println(name+"\t"+address+"\t"+dept+"\t"+salary);
- }
- }
- class PartTimeStaff extends Staff
- {
- int no_of_hr;
- double rate_per_hr;
- void accept() throws IOException
- {
- DataInputStream dis=new DataInputStream(System.in);
- System.out.print("\nEnter Name : ");
- name=dis.readLine();
- System.out.print("\nEneter Address : ");
- address=dis.readLine();
- System.out.print("\nEnter No. of hour : ");
- no_of_hr=Integer.parseInt(dis.readLine());
- System.out.print("\nEnter Rate per Hour : ");
- rate_per_hr=Double.parseDouble(dis.readLine());
- }
- void display()
- {
- System.out.println(name+"\t"+address+"\t"+no_of_hr+"\t"+rate_per_hr);
- }
- }
- public class StaffDemo
- {
- public static void main(String args[]) throws IOException
- {
- DataInputStream dis=new DataInputStream(System.in);
- System.out.print("\nHow many objects u want to create = ");
- int n=Integer.parseInt(dis.readLine());
- System.out.print("\nMENU\n1)FullTimeStaff objects\n2)PartTimeStaff\nENTER YOUR CHOICE 1 OR 2 :");
- int choice=Integer.parseInt(dis.readLine());
- switch(choice)
- {
- case 1: FullTimeStaff s[]=new FullTimeStaff[n];
- System.out.println("ACCEPTING INFORMATION OF FULL TIME STAFF");
- for(int i=0;i<n;i++)
- { s[i]=new FullTimeStaff();
- s[i].accept();
- }
- System.out.println("\nDISPLAYING INFORMATION OF FULL TIME STAFF ");
- System.out.println("\nNAME\tADRESS\tDEPARTMENT\tSALARY");
- for(int i=0;i<n;i++)
- {
- s[i].display();
- }
- break;
- case 2:
- PartTimeStaff t[]=new PartTimeStaff[n];
- System.out.println("ACCEPTING INFORMATION OF PART TIME STAFF");
- for(int i=0;i<n;i++)
- { t[i]=new PartTimeStaff();
- t[i].accept();
- }
- System.out.println("\nDISPLAYING INFORMATION OF FULL TIME STAFF ");
- System.out.println("\nNAME\tADRESS\tNUM OF HOUR\tRATE PER HOUR");
- for(int i=0;i<n;i++)
- {
- t[i].display();
- }
- break;
- }
- }
- }
- Q2
- Html.file
- <form method="GET" action="http://localhost:8080/servlets-examples/servlet/LoginServlet">
- Login : <input type="text" name="login"><br>
- Password : <input type="password" name="password"><br>
- <input type="submit"><input type="reset">
- </form>
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import java.sql.*;
- public class LoginServlet extends HttpServlet
- {
- public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
- {
- res.setContentType("text/html");
- PrintWriter pw=res.getWriter();
- try
- {
- String login=req.getParameter("login");
- String password=req.getParameter("password");
- Connection con=null;
- Statement stmt=null;
- ResultSet rs=null;
- Class.forName("org.postgresql.Driver");
- con=DriverManager.getConnection("jdbc:postgresql://localhost/tydb","root","");
- stmt=con.createStatement();
- rs=stmt.executeQuery("select * from Login");
- boolean flag=false;
- while(rs.next())
- {
- String l=rs.getString(1);
- String p=rs.getString(2);
- if(login.equals(l) && password.equals(p))
- {
- flag=true;
- break;
- }
- }
- if(flag==true)
- {
- pw.println("Login Succesfully....");
- }
- else
- {
- pw.println("Login Failed....");
- }
- pw.close();
- }
- catch(Exception e)
- {
- pw.println(e);
- }
- }
- }
Add Comment
Please, Sign In to add comment