You are on page 1of 58

Practical File

of
Informatics Practices

Made by:- MAHIMA KARMAKAR

Class: XII -B

Roll No.:

Session: 2018- 2019


Informatics Practices Practical File

Index
Sl. Teacher
Topic
No. Sign.
1 Own calculator
2 Eligibilty vote
3 Calculate bill
4 Find day of the week
5 Count number from 1-10
6 Program for combo box
7 Display details of a person
8 Ice cream shop
9 Pizza cafeé
10 Sales shop
11 Loop to print series
12 Program to show nested loop
13 Program to show composite numbers
14 Program to show login process
15 Program for path educo enterprise
16 Program for kiddi land enterprises
17 Sql program for exam
18 Sql program for joint
19 Sql program for joint
20 Sql program for result
21 Program to show class for book
22 Program for sagar electronics
23 HDFC bank
24 Show class for batsman
25 Show palindrome
26 Program to show number of vowels
27 Insertion of data
28 Modification of data
29 Deletion of data
30 Five HTML Program

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question: 1. Write a program to enter two number and calculate (+, -,


*, /, %)?

Solution:

private void PlusActionPerformed(java.awt.event.ActionEvent evt) {


int a,b,c;
a = Integer.parseInt(jTextField1.getText());
b = Integer.parseInt(jTextField2.getText());
c = a + b;
jTextField3.setText(Integer.toString(c));
}

private void MinusActionPerformed(java.awt.event.ActionEvent evt)


{
int a,b,c;
a = Integer.parseInt(jTextField1.getText());
b = Integer.parseInt(jTextField2.getText());
c = a - b;
jTextField3.setText(Integer.toString(c));
}

private void MultiplyActionPerformed(java.awt.event.ActionEvent


evt) {
int a,b,c;
a = Integer.parseInt(jTextField1.getText());
b = Integer.parseInt(jTextField2.getText());

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

c = a * b;
jTextField3.setText(Integer.toString(c));
}

private void DivideActionPerformed(java.awt.event.ActionEvent evt)


{
int a,b,c;
a = Integer.parseInt(jTextField1.getText());
b = Integer.parseInt(jTextField2.getText());
c = a / b;
jTextField3.setText(Integer.toString(c));
}

private void ModulusActionPerformed(java.awt.event.ActionEvent


evt) {
int a,b,c;
a = Integer.parseInt(jTextField1.getText());
b = Integer.parseInt(jTextField2.getText());
c = a % b;
jTextField3.setText(Integer.toString(c));
}

private void ClearActionPerformed(java.awt.event.ActionEvent evt) {


jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}

private void ExitActionPerformed(java.awt.event.ActionEvent evt) {


System.exit(0);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question: 2. Write a program to enter age and check eligible for voting
or not.

Solution:

private void

jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int age;
age = Integer.parseInt(jTextField1.getText());
if(age>=18)
jTextField2.setText("Eligible for Voting");
else
jTextField2.setText("Not Eligible for Voting");
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent


evt) {
System.exit(0);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question: 3. Write a program to enter bill amount and calculate


discount (Cash-20%, Cheque-10%, Credit Card - 5%) and net amount.

Solution:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)


{
double amt, disc, net;
amt = Double.parseDouble(jTextField1.getText());
disc = 0;
if(jRadioButton1.isSelected())
disc=amt*20/100;
else if(jRadioButton2.isSelected())
disc=amt*10/100;
else if(jRadioButton3.isSelected())
disc=amt*5/100;
net = amt - disc;
jTextField2.setText(Double.toString(disc));
jTextField3.setText(Double.toString(net));
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

private void jButton2ActionPerformed(java.awt.event.ActionEvent


evt) {
System.exit(0); }
Question: 4. Write a java program to enter day number and print day
name.

Solution:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)


{
String day;
int n = Integer.parseInt(jTextField1.getText());
switch(n)
{
case 1: day="Monday"; break;
case 2: day="Tuesday"; break;
case 3: day="Wednesday"; break;
case 4: day="Thursday"; break;
case 5: day="Friday"; break;
case 6: day="Saturday"; break;
case 7: day="Sunday"; break;
default:day="Invalid Day no.";
}
jTextField2.setText(day);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

private void jButton2ActionPerformed(java.awt.event.ActionEvent


evt) {
System.exit(0);
}

Question: 5. Write a program to print natural number till N.

Solution:

private void jButton1ActionPerformed


(java.awt.event.ActionEvent evt)
{
int i,n;
n = Integer.parseInt(jTextField1.getText());
for(i=1; i<=n; i++)
{
jTextArea1.append(i+" ");
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent


evt) {
System.exit(0);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question 6: Write a java program to enter bill amount and select type
of member (Platinum -18%, Gold-8%, Silver-5%).

Solution:

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
System.exit(0);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent
evt) {
double amt, disc, net;
amt = Double.parseDouble(jTextField1.getText());
disc = 0;
String type = (String)jComboBox1.getSelectedItem();
if(type.equals("Platinum"))
disc=amt*18/100;
else if(type.equals("Gold"))
disc=amt*8/100;
else if(type.equals("Silver"))
disc=amt*5/100;
net = amt - disc;

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

jTextField2.setText(Double.toString(disc));
jTextField3.setText(Double.toString(net)); }
Question 7: Write java code to enter person details and store into
textarea.

Solution:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)


{
String name,add,mobile;
int age;
name = jTextField1.getText();
age = Integer.parseInt(jTextField2.getText());
add = jTextField3.getText();
mobile = jTextField4.getText();
jTextArea1.append("Name : "+name+"\n");
jTextArea1.append("Age : "+age+"\n");
jTextArea1.append("Address : "+add+"\n");
jTextArea1.append("Mobile : "+mobile+"\n");
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent


evt) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

jTextField4.setText("");
jTextArea1.setText("");
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent


evt) {
System.exit(0);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question 8: Write java code to select ice cream and enter quantity
then calculate total amount.

Solution:

double price=0.0,amt;
int qty=Integer.parseInt(txtqty.getText());
String ice = (String) list1.getSelectedValue();
if(ice.equals("vanila"))
{
price=100;
}
else if(ice.equals("strawbery"))
{
price=100;
}
else if(ice.equals("butterscatch"))
{
price=150;
}
else if(ice.equals("chocolate"))

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

{
price=200;
}
else if(ice.equals("tutti-frutti"))
{
price=150;
}
else if(ice.equals("mango"))
{
price=180;
}
txtprice.setText(" "+price);
amt=price*qty;
txtamt.setText((""+amt));
lblresult.setText("you have to pay Rs."+amt);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question : 9. Write java code to calculate Pizza bill.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)


{
double rate, qty, top, total;
qty = Double.parseDouble(jTextField2.getText());
rate = 0;
if(jRadioButton1.isSelected())
rate=200;
else if(jRadioButton2.isSelected())
rate = 300;
top =0;
if(jCheckBox1.isSelected())
top+=50;
if(jCheckBox2.isSelected())
top+=50;
if(jCheckBox3.isSelected())
top+=50;
total = qty * (rate + top);

jTextField3.setText(Double.toString(top));

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

jTextField4.setText(Double.toString(total));
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent


evt) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jRadioButton1.setSelected(true);
jCheckBox1.setSelected(false);
jCheckBox2.setSelected(false);
jCheckBox3.setSelected(false);
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent


evt) {
System.exit(0);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question 10: Write java code to enter four quarter sale amount and
calculate total amount of yearly sales.

Solution:

int a = Integer.parseInt(txt1.getText());
int b = Integer.parseInt(txt2.getText());
int c = Integer.parseInt(txt3.getText());
int d = Integer.parseInt(txt4.getText());
int e = a+b+c+d;
txt5.setText(""+e);

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question. 11. Design a GUI application to print from highest to


lowest

private void jButton1ActionPerformed(java.awt.event.ActionEventevt)


{
int a=Integer.parseInt(txthighest.getText());
int b=Integer.parseInt(txtsmallest.getText());
inti;
for(i=b;i<=a;i++)
{
resultlb.setText(resultlb.getText()+i+",");

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question 12: Write java code to print the following pattern:


1
12
123
1234
Solution:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)


{
int i, j;
for(i=1; i<=4; i++)
{
for(j=1; j<=i; j++)
{
jTextArea1.append(j+ " ");
}
jTextArea1.append("\n");
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent


evt) {
System.exit(0);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question: 13. Write Java program to calculate simple interest and


compound interest.

Solution:

private void CalculateActionPerformed


(java.awt.event.ActionEvent evt)
{
double p,r,t,i;
p = Double.parseDouble(jTextField1.getText());
r = Double.parseDouble(jTextField2.getText());
t = Double.parseDouble(jTextField3.getText());
if(jRadioButton1.isSelected())
{
i = (p*r*t)/100;
jTextField4.setText(i+" ");
}
else if(jRadioButton2.isSelected())
{
i = p* Math.pow( (1+ r/100),t) - p;
i = Math.round(i);
jTextField4.setText(i+" ");
}
}

private void ClearActionPerformed


(java.awt.event.ActionEvent evt)
{
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
}

private void ExitActionPerformed(java.awt.event.ActionEvent evt)


{
System.exit(0);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question: 14. Write java program to enter user id and password then
check It is valid or not?

Solution:
import javax.swing.JOptionPane;
private void LoginActionPerformed(java.awt.event.ActionEvent evt) {
String user, pass;
user = jTextField1.getText();
pass = new String(jPasswordField1.getPassword());

if (user.equals("Karan Sharma"))
{
if (pass.equals("delhi36"))
{
JOptionPane.showMessageDialog(null,"Login successfully");
}
else
{
JOptionPane.showMessageDialog(null,"Password Invalid !!!");
}
}
else
{
JOptionPane.showMessageDialog(null,"User ID Invalid");
}
}

private void CancelActionPerformed


(java.awt.event.ActionEvent evt)
{
System.exit(0);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question: 15. Avon India is a cycle manufacturer company. The HRD


department manages 100’s employees on regular basis. The company
provides salary on two categories : Temporary employee and
permanent employee.

Solution:
private void CalculateActionPerformed
(java.awt.event.ActionEvent evt)
{
double basic, overtime,cca,hra,salary, otamount, netamount,days;
if(jRadioButton1.isSelected())
{
// Temporary Employee 250 per day and overtime 50 per hour
days = Double.parseDouble(jTextField7.getText());
overtime = Double.parseDouble(jTextField8.getText());
salary = days*250;
otamount = overtime * 50;
netamount=salary + otamount;
jTextField9.setText(salary+"");
jTextField11.setText(otamount+"");
jTextField10.setText(netamount+"");
}
else if(jRadioButton2.isSelected())
{
basic = Double.parseDouble(jTextField3.getText());
overtime = Double.parseDouble(jTextField4.getText());
cca=500;
otamount = overtime * 75;
hra = basic * 10/100;
salary = basic+cca+hra;
netamount = salary + otamount;
jTextField5.setText(hra+"");
jTextField6.setText(cca+"");
jTextField9.setText(salary+"");
jTextField11.setText(otamount+"");
jTextField10.setText(netamount+"");
}
}

private void ClearActionPerformed

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

(java.awt.event.ActionEvent evt)
{
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField7.setText("");
jTextField8.setText("");
jTextField9.setText("");
jTextField10.setText("");
jTextField11.setText("");
jRadioButton1.setSelected(true);
}

private void ExitActionPerformed(java.awt.event.ActionEvent evt)


{
System.exit(0);
}

private void jRadioButton1ActionPerformed


(java.awt.event.ActionEvent evt)
{
jTextField7.setEditable(true);
jTextField8.setEditable(true);
jTextField3.setEditable(false);
jTextField4.setEditable(false);

private void jRadioButton2ActionPerformed


(java.awt.event.ActionEvent evt)
{
jTextField7.setEditable(false);
jTextField8.setEditable(false);
jTextField3.setEditable(true);
jTextField4.setEditable(true);

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question 16: During a special sale at a store, a 10% discount is taken


on purchases over Rs. 1000/-. Write a program that asks for the
amount of purchases, and then calculate the discounted price.
Solution:
private void CalculateActionPerformed
(java.awt.event.ActionEvent evt)
{
double amt,disc,net;
amt = Double.parseDouble(jTextField1.getText());
disc = 0;
if(amt > 1000)
{
disc = amt * 10/100;
}
net = amt - disc;
jTextField2.setText(disc+"");
jTextField3.setText(net+"");
}
private void ExitActionPerformed(java.awt.event.ActionEvent evt)
{
System.exit(0);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question 17. Write SQL command to create the table Exam.

Solution:

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question 18: In a database create the following tables with suitable


constraints:

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question 19.

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

1) To list the names of those students, who have obtained division as


first in the ascending order of name

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

2) To display a report listing NAME, SUBJECT, and annual stipend


received assuming the stipend column has monthly stipend

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

3) To count number of students, who have either Accounts or


Informatics as Subject.

Question 21. Define a class Book with following description (book


name, author, price). It also display the content.

Solution:

public class Book


{
String bookname;
String author;
int price;
public Book()
{
bookname="Informatics Practices";
author="Sumita Arora";
price=350;
}
public void Display()
{
System.out.println("Book Name : "+bookname);
System.out.println("Author Name : "+author);
System.out.println("Price : "+price);
}
public static void main(String args[])

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

{
Book b1 = new Book();
b1.Display();
}
}

Question. 22. Design the Sagar Electronics sale the Item (LCD TV -
25000, LED TV - 40000, Music System - 10000, Radio - 2000), and
Calculate Tax (12% of Total) and net Amount.

Solution:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)


{
int qty, index;
double rate, tax, total,net;
qty = Integer.parseInt(jTextField2.getText());
index = jComboBox1.getSelectedIndex();
if(index == 0)
rate = 25000;

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

else if(index == 1)
rate = 40000;
else if(index == 2)
rate = 10000;
else
rate = 2000;
total = rate * qty;
tax = total * 12/100;
net = total + tax;
jTextField1.setText(Double.toString(rate));
jTextField3.setText(Double.toString(tax));
jTextField4.setText(Double.toString(net));
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent


evt) {
System.exit(0);
}

Question 23. Desgin the HDFC Bank to select the Loan Type with Rate
of Interest ( Car Loan - 10%, House Loan - 8.5%, Education Loan-5%).
and Calculate Interest Amount(Compound Interest) and Net Amount.

Solution:

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
System.exit(0);
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent


evt) {
double p,r,t,ci,amt;
p = Double.parseDouble(jTextField1.getText());
t = Double.parseDouble(jTextField2.getText());
r=0;
if(jRadioButton1.isSelected())
r=10;
else if(jRadioButton2.isSelected())
r=8.5;
else if(jRadioButton3.isSelected())
r=5.0;
amt = p*Math.pow((1+r/100), t);
amt = Math.round(amt);
ci = amt - p;
jTextField3.setText(Double.toString(ci));
jTextField4.setText(Double.toString(amt));
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question 24. Define the class Batsman with following specification:


Data Members:
 bcode Integer
 bname String
 innings, notout Integer
 runs Integer
 batavg Integer
 calcavg() Calculate average
Member Methods:
 readdata() Function input the value
 displaydata() Function to show the data

public class Batsman extends javax.swing.JFrame {


int bcode;
String bname;
int inning,notout;
int runs;
int batavg;
void calcavg()
{
batavg = runs / inning;

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

}
void readdata()
{
bcode = Integer.parseInt(jTextField1.getText());
bname = jTextField2.getText();
inning = Integer.parseInt(jTextField3.getText());
notout = Integer.parseInt(jTextField4.getText());
runs = Integer.parseInt(jTextField5.getText());

}
void displaydata()
{
jTextField6.setText(Integer.toString(batavg));
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
System.exit(0);
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent


evt) {
Batsman obj = new Batsman();
obj.readdata();
obj.calcavg();
obj.displaydata();
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question: 25. Write a program to enter a string and check Palindrome


or not.

Solution:
private void PalindromeCheckerActionPerformed
(java.awt.event.ActionEvent evt)
{
String str, rev="";
str = jTextField1.getText();
for(int i = str.length()-1; i>=0; i--)
{
rev = rev + str.charAt(i);
}
if(str.equalsIgnoreCase(rev))
jTextField2.setText(str+" is a Palindrome.");
else
jTextField2.setText(str+" is not a Palindrome.");
}

private void ExitActionPerformed


(java.awt.event.ActionEvent evt)
{
System.exit(0);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question 26: Write java code to enter string and count number of
vowels.

Solution:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)


{
int i, n=0;
String s = jTextField1.getText();
for(i=0; i<s.length(); i++)
{
char ch = s.charAt(i);
ch = Character.toLowerCase(ch);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
n++;
}
jTextField2.setText(n+"");
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent


evt) {
System.exit(0);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question 27: Write java program to add the student details(Rollno,


Name, Subject) in database table.

Solution:
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;

private void InsertActionPerformed(java.awt.event.ActionEvent evt)


{
DefaultTableModel obj = (DefaultTableModel)jTable1.getModel();
try
{
Class.forName("java.sql.DriverManager");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost/test","root","");
Statement stmt =(Statement)con.createStatement();
String rollno, name, subject;
rollno = jTextField1.getText();
name = jTextField2.getText();
subject = jTextField3.getText();
String query = "Insert into student values
("+rollno+",'"+name+"','"+subject+"');";
stmt.executeUpdate(query);
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
ResultSet rs = stmt.executeQuery("select * from student;");
while(obj.getRowCount()>0)
{
obj.removeRow(0);
}
while(rs.next())
{
String roll = rs.getString(1);
String sname = rs.getString(2);
String sub = rs.getString(3);
obj.addRow(new Object[]{roll,sname,sub});
}
rs.close();

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

stmt.close();
con.close();

}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage());
}
}

private void ExitActionPerformed(java.awt.event.ActionEvent evt)


{
System.exit(0);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question: 28. Write java program to update the Student record in


database table.

Solution:
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;

private void ExitActionPerformed(java.awt.event.ActionEvent evt)


{
System.exit(0);
}
private void UpdateActionPerformed
(java.awt.event.ActionEvent evt) {
DefaultTableModel obj = (DefaultTableModel)jTable1.getModel();
try
{
Class.forName("java.sql.DriverManager");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost/test","root","");
Statement stmt =(Statement)con.createStatement();
String rollno, name, subject;
rollno = jTextField1.getText();
name = jTextField2.getText();
subject = jTextField3.getText();
String query = "Update student set name='"+name+"', subject
='"+subject+"' where rollno ="+rollno+";";
stmt.executeUpdate(query);
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
ResultSet rs = stmt.executeQuery("select * from student;");
while(obj.getRowCount()>0)
{
obj.removeRow(0);
}
while(rs.next())
{
String roll = rs.getString(1);
String sname = rs.getString(2);

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

String sub = rs.getString(3);


obj.addRow(new Object[]{roll,sname,sub});
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
private void SearchActionPerformed
(java.awt.event.ActionEvent evt) {
try
{
String rollno = jTextField1.getText();
Class.forName("java.sql.DriverManager");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost/test","root","");
Statement stmt =(Statement)con.createStatement();
String query = "select * from student where rollno = "+rollno+";";
ResultSet rs = stmt.executeQuery(query);
if(rs.next())
{
String name = rs.getString(2);
String sub = rs.getString(3);
jTextField2.setText(name);
jTextField3.setText(sub);
jTextField2.setEditable(true);
jTextField3.setEditable(true);
Update.setEnabled(true);
}
else
{
jTextField2.setText("Not Available");
jTextField3.setText("Not Available");
jTextField2.setEditable(false);
jTextField3.setEditable(false);
Update.setEnabled(false);
}
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

catch (Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Question: 29. Write java program to delete the student details from
database table.

Solution:
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;

private void SearchActionPerformed


(java.awt.event.ActionEvent evt) {
try {
String rollno = jTextField1.getText();
Class.forName("java.sql.DriverManager");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost/test","root","");
Statement stmt =(Statement)con.createStatement();
String query = "select * from student where rollno =
"+rollno+";";
ResultSet rs = stmt.executeQuery(query);
if(rs.next()) {
String name = rs.getString(2);
String sub = rs.getString(3);
jTextField2.setText(name);
jTextField3.setText(sub);
jTextField2.setEditable(true);
jTextField3.setEditable(true);
Delete.setEnabled(true);
}
else {
jTextField2.setText("Not Available");
jTextField3.setText("Not Available");
jTextField2.setEditable(false);
jTextField3.setEditable(false);
Delete.setEnabled(false);
}
}
catch (Exception e) {
JOptionPane.showMessageDialog(null,e.getMessage());
}
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

private void DeleteActionPerformed


(java.awt.event.ActionEvent evt) {
DefaultTableModel obj = (DefaultTableModel)jTable1.getModel();
try {
Class.forName("java.sql.DriverManager");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost/test","root","");
Statement stmt =(Statement)con.createStatement();
String rollno, name, subject;
rollno = jTextField1.getText();
name = jTextField2.getText();
subject = jTextField3.getText();
String query = "Delete From student where rollno ="+rollno+";";
stmt.executeUpdate(query);
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
ResultSet rs = stmt.executeQuery("select * from student;");
while(obj.getRowCount()>0) {
obj.removeRow(0);
}
while(rs.next()) {
String roll = rs.getString(1);
String sname = rs.getString(2);
String sub = rs.getString(3);
obj.addRow(new Object[]{roll,sname,sub});
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}

private void ExitActionPerformed(java.awt.event.ActionEvent evt)


{
System.exit(0);
}

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

HTML

<html>
<head>
<title>LAXMI PUBLIC SCHOOL</title>
</head>
<body bgcolor="BLUE" >
<font face="Arial" style="BOLD" color="Black" size="6">
<p align="CENTER"> LAXMI PUBLIC SCHOOL</p>
<img src="A.jpg">
</BODY>
</html>

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

<html>
<head>
<title>Career Options in Multimedia</title>
</head>
<body bgcolor="PINK" ALINK="BLUE" VLINK="Blue">
<CENTER>
<TABLE BORDER = "5" color = "Green" cellpadding="2" cellspacing="2" width =
"40%">
<CAPTION color="BLUE">Course Charges</CAPTION>
<TR><TH bgcolor = "Cyan">Course Name</TH><TH bgcolor = "Cyan">Monthly
Charges</TH></TR>
<TR><TD>Graphic Designing</TD><TD>Rs.25000</TD></TR>
<TR><TD>Game Designing</TD><TD>Rs.35000</TD></TR>
<TR><TD>Web Designing</TD><TD>Rs.15000</TD></TR>
<TR><TD>Print & Puhlishing</TD><TD>Rs.10000</TD></TR>
</TABLE>
</CENTER>
</BODY>
</html>

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

<html>
<head>
<title>
Online Games</title>
</head>
<OL>
<LI><A href="puzzle.html">Puzzle Games</A></LI>
<UL TYPE="square">
<LI>Tetris</LI>
<LI>Cubis</LI>
</UL>
<LI><A href="card.html">Card Games</A></LI>
<ul type="i">
<li>Solitaire</LI>
<li>Hearts</LI>
</ul>
<LI><A href="Action.html">Action Games</A></LI>

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

<ul type="a">
<li>Boom</LI>
<li>Final Assault</LI>
</ul>
</OL>
</CENTER>
</BODY>
</html>

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

<form method="post"
action="mailto:youremail@email.com">
Select your favorite cartoon characters.<br>
<input type="checkbox" name="toon"
value="Goofy">Goofy<br>
<input type="checkbox" name="toon"
value="Donald">Donald<br>
<input type="checkbox" name="toon"
value="Bugs">Bugs Bunny<br>
<input type="checkbox" name="toon"
value="Scoob">Scooby Doo<br>
</form>

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019


Informatics Practices Practical File

<form method="post"
action="mailto:youremail@email.com">
College Degree?
<select name="degree">
<option>Choose One</option>
<option>Some High School</option>
<option>High School Degree</option>
<option>Some College</option>
<option>Bachelor's Degree</option>
<option>Doctorate</option>
<input type="submit" value="Email Yourself">
</select>
</form>

Made by: Mahima Karmakar Class: XII – B Session: 2018 - 2019

You might also like