Final.pdf

  • Uploaded by: Ashish Tiwari
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Final.pdf as PDF for free.

More details

  • Words: 3,161
  • Pages: 77
SCHOOL OF ADVANCED SCIENCES Winter Semester 2018-19 Lab Assessment –I Name: GOPAL GUPTA Faculty: Prof. Thippa Reddy Course: Java Programming

Registration No: 16BIT0276 Slot: L41 + L42 Code: CSE1007

Code: import java.util.*; class A { public static void main(String arr[]) { Scanner b= new Scanner(System.in); int x,z; int ans=0; //Jagged array initialized

1

int a[][]=new int[4][]; for(int i=0;i<4;i++) { System.out.println("Enter the number of slow learners in the batch "+i); x=b.nextInt(); if(x%4==0) z=x/4; else z=x/4+1; //Individual Row of jagged array initialized a[i]=new int[z];

for(int j=0;j4) {a[i][j]=4;x=x-4;} else {a[i][j]=x;x=0;} } } System.out.println("\n\nThe Contents of Jagged array are");

for(int i=0;i<4;i++) {

2

for(int n:a[i]) {System.out.print(n); if(n==4)ans++;} System.out.println(); }

System.out.println("\n\nThe number of Tutors with 4 students are (ans) = "+ans);

}

}

OUTPUT:

3

Code: import java.util.*; import java.io.*; public class Chemeqn { public static void main(String[]args) { System.out.println("----------Give The Chemical Equation---------------"); Scanner scan = new Scanner(System.in); String s=new String(); s=scan.nextLine(); s=" "+s; String s1=new String(); String s2="QWERTYUIOPASDFGHJKLZXCVBNM"; for(int i=0;i<=s.length()-2;i++) { char ch=s.charAt(i); char ch1=s.charAt(i+1); 4

if(ch == ' ' && ch1 != '+' && ch1 != '-') { for(int j=i+1;j<=s.length()-1;j++) { char ch2=s.charAt(j); if(s2.indexOf(ch2)==-1) { System.out.print(ch2); } else { i=j; break; } } } } }

}

5

SCHOOL OF ADVANCED SCIENCES Winter Semester 2018-19 Lab Assessment – II Name: GOPAL GUPTA Faculty: Prof. Thippa Reddy Course: Java Programming

Registration No: 16BIT0276 Slot: L41 + L42 Code: CSE1007

Code: import java.util.*; import java.io.*;

class BMI { public static void main(String args[]) { String fname = args[0]; 1

String lname = args[1]; float ht = Float.parseFloat(args[2]); int wt = Integer.parseInt(args[3]); float bmi = (wt)/(ht*ht); System.out.println("Name : "+fname+" "+lname); System.out.println("BMI : "+bmi); if(bmi<18.5) { System.out.println("BMI category : Underweight"); } else if(bmi>=18.5 && bmi<25) { System.out.println("BMI category : Normal (healthy weight)"); } else if(bmi>=25 && bmi<30) { System.out.println("BMI category : Overweight"); } else { System.out.println("BMI category : Obese"); } } } 2

INPUT:

OUTPUT:

3

Code: import java.util.*; public class gene { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter a genome string: "); String genome = sc.nextLine(); boolean found = false; int start = -1; for (int i = 0; i < genome.length() - 2; i++) { String triplet = genome.substring(i, i + 3); 4

if (triplet.equals("ATG")) { start = i + 3; } else if (((triplet.equals("TAG")) || (triplet.equals("TAA")) || (triplet.equals("TGA")))&& (start != -1)) { String gene = genome.substring(start, i); if (gene.length() % 3 == 0) { found = true; System.out.println(gene); start = -1; } } } if (!found) System.out.println("no gene is found"); } }

5

OUTPUT:

6

SCHOOL OF ADVANCED SCIENCES Winter Semester 2018-19 Lab Assessment – III Name: Gopal Gupta Faculty: Prof. Thippa Reddy Course: Java Programming

Registration No: 16BIT0276 Slot: L41 + L42 Code: CSE1007

1

CODE: import java.util.*; import java.io.*;

class Film { String name; String lang; String lead_actor; String category; int duration; Film(String a,String b,String c,String d,int e) { name = a; lang = b; lead_actor = c; category = d; duration = e; } Film() { name = lang = lead_actor = category = null; duration = 0; }

2

void findarnold() { if(this.lead_actor=="Arnold") { System.out.println("Name : "+this.name); System.out.println("Lead Actor : "+this.lead_actor); System.out.println("Language : "+this.lang); System.out.println("Category : "+this.category); System.out.println("Duration : "+this.duration); System.out.println(); } } void findtamil() { if(this.lang=="Tamil" && this.lead_actor=="Rajni") { System.out.println("Name : "+this.name); System.out.println("Lead Actor : "+this.lead_actor); System.out.println("Language : "+this.lang); System.out.println("Category : "+this.category); System.out.println("Duration : "+this.duration); System.out.println(); } }

3

void findcomedy() { if(this.category=="Comedy") { System.out.println("Name : "+this.name); System.out.println("Lead Actor : "+this.lead_actor); System.out.println("Language : "+this.lang); System.out.println("Category : "+this.category); System.out.println("Duration : "+this.duration); System.out.println(); } } }

class FilmMain { public static void main(String args[]) { int i; Film[] f = new Film[5]; f[0] = new Film("Robot 2.0","Tamil","Rajni","Action",3); f[1] = new Film("Dhamaal","Hindi","Circuit","Comedy",2); f[2] = new Film("Terminator","English","Arnold","Action",2); f[3] = new Film("Padmaavat","Hindi","Ranveer Singh","Drama",3); 4

f[4] = new Film("Robot 1.0","Tamil","Rajni","Action",3);

for(i=0;i<5;i++) f[i].findarnold(); for(i=0;i<5;i++) f[i].findtamil(); for(i=0;i<5;i++) f[i].findcomedy(); } }

OUTPUT:

5

CODE: import java.util.Scanner; public interface themepark { int adultfee=500; int childfee=300; void buyticket(int n,int m); void playGame(int a); void count(); public static void main(String args[]) { System.out.println("Which theme park? Queensland or Veegeland?"); Scanner scr=new Scanner(System.in); String theme=scr.nextLine(); System.out.println("Enter no. of adults"); int n=scr.nextInt(); System.out.println("Enter no. of children"); int m=scr.nextInt(); String choice; int game; if("Queensland".equalsIgnoreCase(theme)) { Queensland t2; t2=new Queensland(); t2.buyticket(n,m); 6

System.out.println("Which game do you want to play?"); game=scr.nextInt(); t2.playGame(game); do { System.out.println("Do you want to play another game?"); choice=scr.next(); if(choice.equalsIgnoreCase("yes")) { System.out.println("Which game do you want to play?"); game=scr.nextInt(); t2.playGame(game); } }while(!"no".equalsIgnoreCase(choice)); t2.count(); } else if("Veegeland".equalsIgnoreCase(theme)) { Veegeland t3; t3 = new Veegeland(); t3.buyticket(n,m); System.out.println("Which game do you want to play?"); game=scr.nextInt(); t3.playGame(game); do { System.out.println("Do you want to play another game?"); choice=scr.next(); if(choice.equalsIgnoreCase("yes")) { System.out.println("Which game do you want to play?"); game=scr.nextInt(); t3.playGame(game); } }while(!"no".equalsIgnoreCase(choice)); t3.count(); } } } class Queensland implements themepark { Queensland() { 7

this.Games = new boolean[30]; for(int i=0;i<30;i++) { Games[i]=false; } } @Override public void buyticket(int n,int m) { int totalcost=n*adultfee+childfee*m; System.out.println("The ticket cost is "+totalcost); } boolean Games[]; @Override public void playGame(int a) { if(a>30) { System.out.println("Games till 30 are only available"); } else if(Games[a-1]==false) { Games[a-1]=true; } else if(Games[a-1]==true) { System.out.println("You have already played this game."); } } @Override public void count() { int count=0; for(int j=0;j<30;j++) { if(Games[j]==true) { count++; } } System.out.println("No. of games played is "+count); System.out.println("No. of games left is "+(30-count)); } } 8

class Veegeland implements themepark{ int Games[]; Veegeland() { Games=new int[40]; int j; for(j=0;j<40;j++) { Games[j]=0; } } @Override public void buyticket(int n,int m) { int totalcost=n*adultfee+childfee*m; System.out.println("The ticket cost is "+totalcost); } @Override public void playGame(int a) { if(a<=40) { Games[a-1]=Games[a-1]+1; } else { System.out.println("Only games till 40 are available"); } } @Override public void count() { int count=0; int countmorethanone=0; for(int i=0;i<40;i++) { if(Games[i]>0) { count++; } if(Games[i]>1) { countmorethanone++; 9

} } System.out.println("No. of games played is "+count); System.out.println("No. of games played for more than one time are "+countmorethanone); System.out.println("No. of games not played is "+(40-count)); } }

OUTPUT:

10

SCHOOL OF ADVANCED SCIENCES Winter Semester 2018-19 Lab Assessment – IV Name: Gopal Gupta Faculty: Prof. Thippa Reddy Course: Java Programming

Registration No: 16BIT0276 Slot: L41 + L42 Code: CSE1007

CODE: Prime.java Package primespackage; public class Prime { public static boolean checkForPrime(int n) { boolean flag=true; for(int i=2;i
if(n%i==0) { flag=false; break; } } If(n==1) return false; return flag; } } TwinPrimes.java Import primes.package.*; import java.util.*; class TwinPrimes { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the starting number"); int x = sc.nextInt(); System.out.println("Enter the ending number"); int y = sc.nextInt(); for(int i=x;i<=y;i++)

2

{ if(Prime.checkForPrime(i)) { if(Prime.checkForPrime(i+2)) System.out.println("("+i+","+(i+2)+")"); } } } }

OUTPUT:

3

SCHOOL OF ADVANCED SCIENCES Winter Semester 2018-19 Lab Assessment – V Name: Gopal Gupta Faculty: Prof. Thippa Reddy Course: Java Programming

Registration No: 16BIT0276 Slot: L41 + L42 Code: CSE1007

CODE: import java.util.*; import java.util.regex.Pattern; import java.util.regex.Matcher;

public class exception{

public static void main(String args[]){ Scanner s = new Scanner(System.in); System.out.println("Enter your registration number: "); String r = s.nextLine(); System.out.println("Enter your mobile number: "); 1

String m = s.nextLine(); try{ if(r.length()!=9) throw new IllegalArgumentException("Not Valid Registration Number"); else System.out.println("Valid Registration Number"); if(m.length()!=10) throw new IllegalArgumentException("Not Valid Mobile Number"); else System.out.println("Valid Mobile Number"); } catch(IllegalArgumentException e) { System.out.println(e); } try{ if(Pattern.matches("[^0-9]", m)) throw new NumberFormatException("Not Valid"); else System.out.println("Number conatins all digits"); } catch(NumberFormatException n) { 2

System.out.println(n); } try{ if(Pattern.matches("[^A-Z][^a-z][^0-9]", r)) throw new NoSuchElementException ("Not Valid"); else System.out.println("Registration number contains no character"); } catch(NoSuchElementException w) { System.out.println(w); }}}

OUTPUT:

3

CODE: import java.io.*; import java.util.*; class Donor implements Serializable{ String name; int age; String address; String contact; String group; int dold; Donor(String name,int age,String address,String contact,String group,int dold){ this.name=name; this.age=age; this.address=address; this.contact=contact; this.group=group; this.dold=dold; } public String toString(){ 4

return "name is "+name+" age is "+age+" address is "+address; } }

public class DonorMain{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.println("Enter the number of donors"); int n = sc.nextInt(); sc.nextLine(); try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("1.txt")); Donor[] d=new Donor[n]; for(int i=0;i
System.out.println("Enter group"); String group=sc.nextLine(); System.out.println("Enter date of last donation"); int dold= sc.nextInt(); sc.nextLine(); d[i] = new Donor(name,age,address,contact,group,dold); oos.writeObject(d[i]); } } catch(IOException e){ System.out.println(e); } try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream("1.txt")); for(int i=0;i=6) System.out.println(d); } }catch(Exception e){ System.out.println(e); } } 6

}

OUTPUT:

7

LAB ASSESSMENT Gopal Gupta 16BIT0276 /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javaapplication1; import java.lang.*; /** * * @author guest-1i7MWe */ public class JavaApplication1 { /** * @param args the command line arguments */ public static void main(String[] args) { int i; String S1= "hai hai hello how are you"; String S2= "hai hello I am fine"; String[] word = S2.split(" "); String[] words = S1.split(" "); int wrc=1; int urc=0; double[] freq= new double[100]; double[] freqc= new double[100]; for (i=0;i<words.length;i++) { for(int j=i+1;j<words.length;j++) { if(words[i].equals(words[j])) { wrc=wrc+1; words[j]="0"; } } for(int k=0;k<word.length;k++) { if(words[i].equals(word[k])) { urc = urc+1; word[k]="0"; } }

if(words[i]!="0") System.out.print("S1 "+words[i]+" "+wrc+"/"+words.length+" "); double irc = wrc; double lel = words.length; freq[i] = (wrc/lel)*Math.log(1/lel); System.out.println(freq[i]); wrc=1; urc=urc-1; if(word[i]!="0") if(urc==0) { System.out.println("S2 "+word[i]+"= 0"); } else {System.out.print("S2 "+words[i]+" "+urc+"/"+word.length+" "); double erc = urc; freqc[i] = (erc/lel)*Math.log(1/lel); System.out.println(freqc[i]);} urc=1;

} // TODO code application logic here } } OUTPUT

SCHOOL OF ADVANCED SCIENCES Winter Semester 2018-19 Lab Assessment – IX Name: Gopal Gupta Faculty: Prof. Thippa Reddy Course: Java Programming

Registration No: 16BIT0276 Slot: L41 + L42 Code: CSE1007

CODE: Index.html <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial scale=1.0"> 1<br /> <br /> </head> <body> <div> <form action="welcome" method="post"> Name: <input type="text" name="a"><br><br> College: <input type="text" name="b"><br><br> <input type="submit" value="Go"> </form> </div> </body> </html> Welcome.java import java.io.*; import javax.servlet.*; import javax.servlet.annotation.WebServlet; import javax.servlet.http.*;<br /> <br /> @WebServlet(urlPatterns = {"/welcome"}) public class welcome extends HttpServlet{ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ try{ response.setContentType("text/html"); PrintWriter out = response.getWriter(); String n = request.getParameter("a"); 2<br /> <br /> String q = request.getParameter("b"); Cookie c = new Cookie("Name", n); Cookie c1 = new Cookie("College", q); response.addCookie(c); response.addCookie(c1); out.print("Hi "+n+" from "+q+"Campus"); out.println("<! DOCTYPE html>"); out.println("<body>"); out.println("<form action = 'intermediate'>"); out.println("<input type='submit' value='GO COOKIES'>"); out.println("</form>"); out.println("<form action='httpsession'>"); out.println("<input type='submit' value='GO HTTPSESSION'>"); out.println("</form>"); out.println("</body>"); out.println("</html>"); HttpSession session = request.getSession(); session.setAttribute("name",n); session.setAttribute("College",q);<br /> <br /> }catch(IOException e){} }<br /> <br /> 3<br /> <br /> @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ processRequest(request, response); }<br /> <br /> @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ processRequest(request, response); }<br /> <br /> @Override public String getServletInfo(){ return "Short description"; } } Intermediate.java import java.io.*; import javax.servlet.*; import javax.servlet.annotation.WebServlet; import javax.servlet.http.*;<br /> <br /> @WebServlet(urlPatterns = {"/intermediate"}) public class intermediate extends HttpServlet{ 4<br /> <br /> protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ response.setContentType("text/html; charset=UTF-8"); try (PrintWriter out = response.getWriter()){ Cookie[] c = request.getCookies(); out.print("Stored Data Name: "+c[0].getValue()+" College: "+c[1].getValue()); } }<br /> <br /> @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ processRequest(request, response); }<br /> <br /> @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ processRequest(request, response); }<br /> <br /> @Override public String getServletInfo(){ return "Short description"; }} 5<br /> <br /> OUTPUT:<br /> <br /> 6<br /> <br /> SCHOOL OF ADVANCED SCIENCES Winter Semester 2018-19 Lab Assessment – IX Name: Gopal Gupta Faculty: Prof. Thippa Reddy Course: Java Programming<br /> <br /> Registration No: 16BIT0276 Slot: L41 + L42 Code: CSE1007<br /> <br /> CODE: Index.html <! DOCTYPE html> <html> <head> <title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial scale=1.0"> 1<br /> <br /> </head> <body> <div> <form action="welcome" method="post"> Name: <input type="text" name="a"><br><br> College: <input type="text" name="b"><br><br> <input type="submit" value="Go"> </form> </div> </body> </html> Welcome.java import java.io.*; import javax.servlet.*; import javax.servlet.annotation.WebServlet; import javax.servlet.http.*;<br /> <br /> @WebServlet(urlPatterns = {"/welcome"}) public class welcome extends HttpServlet{ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ try{ response.setContentType("text/html"); PrintWriter out = response.getWriter(); String n = request.getParameter("a"); 2<br /> <br /> String q = request.getParameter("b"); Cookie c = new Cookie("Name", n); Cookie c1 = new Cookie("College", q); response.addCookie(c); response.addCookie(c1); out.print("Hi "+n+" from "+q+"Campus"); out.println("<! DOCTYPE html>"); out.println("<body>"); out.println("<form action = 'intermediate'>"); out.println("<input type='submit' value='GO COOKIES'>"); out.println("</form>"); out.println("<form action='httpsession'>"); out.println("<input type='submit' value='GO HTTPSESSION'>"); out.println("</form>"); out.println("</body>"); out.println("</html>"); HttpSession session = request.getSession(); session.setAttribute("name",n); session.setAttribute("College",q);<br /> <br /> }catch(IOException e){} }<br /> <br /> 3<br /> <br /> @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ processRequest(request, response); }<br /> <br /> @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ processRequest(request, response); }<br /> <br /> @Override public String getServletInfo(){ return "Short description"; } } Intermediate.java import java.io.*; import javax.servlet.*; import javax.servlet.annotation.WebServlet; import javax.servlet.http.*;<br /> <br /> @WebServlet(urlPatterns = {"/intermediate"}) public class intermediate extends HttpServlet{ 4<br /> <br /> protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ response.setContentType("text/html; charset=UTF-8"); try (PrintWriter out = response.getWriter()){ Cookie[] c = request.getCookies(); out.print("Stored Data Name: "+c[0].getValue()+" College: "+c[1].getValue()); } }<br /> <br /> @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ processRequest(request, response); }<br /> <br /> @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ processRequest(request, response); }<br /> <br /> @Override public String getServletInfo(){ return "Short description"; }} 5<br /> <br /> OUTPUT:<br /> <br /> 6<br /> <br /> SCHOOL OF ADVANCED SCIENCES Winter Semester 2018-19 Lab Assessment – X Name: Gopal Gupta Faculty: Prof. Thippa Reddy Course: Java Programming<br /> <br /> Registration No: 16BIT0276 Slot: L41 + L42 Code: CSE1007<br /> <br /> 1<br /> <br /> CODE: Index.html <!DOCTYPE html> <html> <head> <title>E Shop <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0">

E Shop

16BEC0934

Enter Book Title:


Fetchbook.jsp 2

<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@page import="java.sql.*,java.util.ArrayList,java.util.*"%> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> E Shop Page <% Connection con=null; try{ Class.forName("com.mysql.jdbc.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ebookshop","r oot","admin"); String req_title=request.getParameter("title"); PreparedStatement ps=con.prepareStatement("select * from books where title like '%"+req_title+"%'"); ResultSet rs=ps.executeQuery(); %>

16BEC0934

<% while(rs.next()){ int id=rs.getInt("id");

String title=rs.getString("title"); String author=rs.getString("author"); float price=rs.getFloat("price"); int qty=rs.getInt("qty"); %> 3

<% } %>
IdTitleAuthorPriceQty
<%=id%><%=title%><%=author%>< %=price%><%=qty%>
<% }catch(Exception e){System.out.println(e);} %> OUTPUT:

4

5

JAVA LAB ASSESMENT 6 CSE1007 NAME: Gopal Gupta Reg No: 16BIT0276 Q1. Write a program to demonstrate the knowledge of students in multithreading. Eg., Three students A, B and C of B.Tech-IT II year contest for the PR election. With the total strength of 240 students in II year, simulate the vote casting by generating 240 random numbers (1 for student A, 2 for B and 3 for C) and store them in an array. Create four threads to equally share the task of counting the number of votes cast for all the three candidates. Use synchronized method or synchronized block to update the three count variables. The main thread should receive the final vote count for all three contestants and hence decide the PR based on the values received.

Code: import java.util.*; class Vote extends Thread { static int[][] a=new int[3][80]; static int[] count=new int[3]; static{ Random r=new Random(); for(int i=0;i<3;i++) for(int j=0;j<80;j++){ a[i][j]=r.nextInt(3)+1; }} int l,h,r; Vote(String name,int r, int l,int h) {

this.r=r; this.l=l; this.h=h; System.out.println(name+" started"); start(); } public void run() { synchronized(this){ for(int j=l;j
Vote v4=new Vote("T 4",2,0,80); int c1=v1.count(0); int c2=v2.count(1); int c3=v4.count(2); if(c1>c2 && c1>c3) System.out.println("A Wins By "+c1); else if(c2>c3 && c2>c1) System.out.println("B Wins By "+c2); else System.out.println("C Wins By "+c3); } OUTPUT:

Q2. Write a program to demonstrate the knowledge of students in creating and deploying applets. Eg., Draw a ball, filled with default color. Move the ball from top to bottom of the window continuously with its color changed for every one second. The new color of the ball for the next second should be obtained by adding 20 to the current value of Red component, for the second time by adding 20 to the blue component, and for the third time by adding 20 to the blue component, till all reach the final limit 225, after which the process should be repeated with the default color. CODE:

import java.awt.*; import java.applet.*; import java.awt.event.*; import java.io.*; /* */ public class BallMove1 extends Applet implements Runnable{ Thread t; int x,y,count=0; int c1=0,c2=0,c3=0; public void init(){ x=y=50; t=new Thread(this); t.start(); } public void run(){ while(true){

repaint(); count++; y+=10; if(count%3==2){ c1=(c1+20)%255; } else if(count%3==1){ c2=(c2+20)%255; } else{ c3=(c3+20)%255; } tr y{ Thread.sleep(1000); } catch(InterruptedException e){ } } } public void paint(Graphics g){ Color c=new Color(c1,c2,c3); g.setColor(c); g.drawString(x+" "+y,50,50); g.fillOval(x,y,50,50);

} }

How to create Servlet in netbeans IDE - javatpoint

1 of 14

https://www.javatpoint.com/creating-servlet-in-netbeans-ide

ADVERTISEMENT



4/2/2019, 4:32 PM

How to create Servlet in netbeans IDE - javatpoint

2 of 14

https://www.javatpoint.com/creating-servlet-in-netbeans-ide

Creating a servlet in NetBeans IDE:



4/2/2019, 4:32 PM

How to create Servlet in netbeans IDE - javatpoint

3 of 14

https://www.javatpoint.com/creating-servlet-in-netbeans-ide



4/2/2019, 4:32 PM

How to create Servlet in netbeans IDE - javatpoint

4 of 14

https://www.javatpoint.com/creating-servlet-in-netbeans-ide



4/2/2019, 4:32 PM

How to create Servlet in netbeans IDE - javatpoint

5 of 14

https://www.javatpoint.com/creating-servlet-in-netbeans-ide



4/2/2019, 4:32 PM

How to create Servlet in netbeans IDE - javatpoint

6 of 14

https://www.javatpoint.com/creating-servlet-in-netbeans-ide



4/2/2019, 4:32 PM

How to create Servlet in netbeans IDE - javatpoint

7 of 14

https://www.javatpoint.com/creating-servlet-in-netbeans-ide



4/2/2019, 4:32 PM

How to create Servlet in netbeans IDE - javatpoint

8 of 14

https://www.javatpoint.com/creating-servlet-in-netbeans-ide



4/2/2019, 4:32 PM

How to create Servlet in netbeans IDE - javatpoint

9 of 14

https://www.javatpoint.com/creating-servlet-in-netbeans-ide



4/2/2019, 4:32 PM

How to create Servlet in netbeans IDE - javatpoint

10 of 14

https://www.javatpoint.com/creating-servlet-in-netbeans-ide



4/2/2019, 4:32 PM

How to create Servlet in netbeans IDE - javatpoint

11 of 14

https://www.javatpoint.com/creating-servlet-in-netbeans-ide



4/2/2019, 4:32 PM

How to create Servlet in netbeans IDE - javatpoint

12 of 14

https://www.javatpoint.com/creating-servlet-in-netbeans-ide



4/2/2019, 4:32 PM

How to create Servlet in netbeans IDE - javatpoint

13 of 14

<<prev

https://www.javatpoint.com/creating-servlet-in-netbeans-ide

next>> ADVERTISEMENT

Please Share



4/2/2019, 4:32 PM

How to create Servlet in netbeans IDE - javatpoint

14 of 14

https://www.javatpoint.com/creating-servlet-in-netbeans-ide

Learn Latest Tutorials

C. Graphics

Automata

Testing

NumPy

Verbal A.

Reasoning

Verbal A.

Interview

DBMS

DS

DAA

OS

C. Network

Compiler D.

COA

D. Math.

Web Tech.

Cyber Sec.

C

C++

Java

.Net

Python

Programs

Control S.

AWS

Preparation

Aptitude

B.Tech / MCA

ADVERTISEMENT



4/2/2019, 4:32 PM

Screenshots:-

Code:import java.io.*; import java.sql.*; import java.io.IOException; import java.io.PrintWriter;

import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

public class Student extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); int sum[]=new int[10]; /*String n = request.getParameter("name"); String p = request.getParameter("pass");*/ out.println("HA"); try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "1234", "12345"); PreparedStatement ps = con.prepareStatement("select * from studentdetails"); //ps.set(1, n); //ps.setString(2, p); int i = ps.executeUpdate(); ResultSet rs = ps.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); int j=0; while (rs.next()) { sum[j]=rs.getInt(3)+rs.getInt(4)+rs.getInt(5); j++;

}

out.println("\n" +"\n" + "\n" +"\n" + "\n" +"\nStudent Details" +""+"\n"+ "
"); for(int k=0;k<10;k++) { out.println("Student "+(k+1)+" Total Marks:"+sum[k]+" Student avg: "+sum[k]/3); out.println("
"); } //out.println("Go to login page"); out.println(""); } catch (Exception e2) { System.out.println(e2); } } } Screenshots of code:-

Index.html

TODO supply a title <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0">

TODO write content
Press Here to show the student details

Related Documents

Finalpdf-reportcover
June 2020 36

More Documents from ""

Final.pdf
November 2019 9
Da Combo.pdf
November 2019 13
Aluminium Usage.docx
October 2019 57
Share Khan
June 2020 27
Photography
April 2020 27