SlideShare a Scribd company logo
1 of 52
INFORMATICS PRACTICES
PRACTICAL FILE
RICH HARVEST PUBLIC SCHOOL NEW DELHI
SUBMITTED TO SUBMITTEDBY
MS. MADHUR DEEP NAME: Aman Kumar
CLASS: XII
ROLL No :
INDEX
S.NO. TOPIC
1 Create a GUI application to calculate
commission of salesman.
2 Create a GUI application for a simple
calculator
3 Create Java application to calculate the result
of student (Total and percentage) out of five
subject
4 Create a GUI application to compute and
display payment amount and tax payable .
5 Create GUI application to calculate the
salary of employee details are shown on
respective page.
6 Create Java application to calculate the total
amount of purchasing ,it will accept
payment through three type of credit card.
The discount is given according to given
criteria (Platinum card : 20% discount, Gold:
15%, Silver: 10% of amount)
7 Write a Java program to calculate the
factorial of number by using method.
8 Create a Java application to find greater
number out of two numbers by using
method.
9. Design a GUI application to compute the
sum of digits of a number by using method
10 Design a GUI application using methods to
check the eligibility for voting .
11 Write a program to check whether a string is
palindrome or not?
12 Write a program that displays the swapping
of 2 numbers using:
a) Call By Value
b) Call By Reference
13 Write a program that uses a class to
implement the following for a rectangle class:
a) Calculate area of Rectangle
b) Calculate perimeter of Rectangle
14 Write a program that finds the area of circle
and cylinder using java overriding method
15 Write a program to demonstrate the
abstract class concept for the class
declaration to print the message
16 Create a GUI application using connectivity
that can retrive data from dept table from
my sql database
17 Create a GUI application that obtains record
from tables (say empl) based on three
different criteria .It then display all retrived
records based on all the criteria together in
one table.
18 create a GUI application that computes
calories in meal.
19 Write JAVA application that input number &
find
-number of days in that month
-Table of input number
-First ten evennumbers
20 Write JAVA application that input number
and show the week day
21 SQL QUERIES (20 QUESTIONS)
Q1 Calculate the commission for the salesman according to the following rates:
Sales Commission
Rate
30001
onwards
15%
22001-
30000
10%
12001-
22000
7%
5001-
12000
3%
0-5000 0%
SOLUTION: The GUI for sales commission calculator is as follows:
CODING:
private void CalcButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// obtain input
String txt = SalesTF.getText();
double sales;
sales = Double.parseDouble(txt);
double comm;
// calculate commission
if(sales > 30000)
comm = sales*0.15;
else
if(sales > 22000)
comm = sales*0.10;
else
if(sales > 12000)
comm = sales*0.07;
else
if(sales > 5000)
comm = sales*0.03;
else
comm = 0;
//display output
CommLabel.setText("The Commission is Rs. "+comm);
}
OUTPUT
Q2 create java application to design simple
SOLUTION: The GUI for Simple Calculator is as follows:
CODING:
private void plusBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
opLabel.setText("+");
double num1 = Double.parseDouble(Num1TF.getText());
double num2 = Double.parseDouble(Num2TF.getText());
double num3 = num1 + num2;
Num3TF.setText("" + num3);
}
private void MinusBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
opLabel.setText("-");
double num1 = Double.parseDouble(Num1TF.getText());
double num2 = Double.parseDouble(Num2TF.getText());
double num3 = num1 - num2;
Num3TF.setText("" + num3);
}
private void MulBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
opLabel.setText("*");
double num1 = Double.parseDouble(Num1TF.getText());
double num2 = Double.parseDouble(Num2TF.getText());
double num3 = num1 * num2;
Num3TF.setText("" + num3);
}
private void DivBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
opLabel.setText("/");
double num1 = Double.parseDouble(Num1TF.getText());
double num2 = Double.parseDouble(Num2TF.getText());
double num3 = num1 / num2;
Num3TF.setText("" + num3);
}
private void ModBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
opLabel.setText("%");
double num1 = Double.parseDouble(Num1TF.getText());
double num2 = Double.parseDouble(Num2TF.getText());
double num3 = num1 % num2;
Num3TF.setText("" + num3);
}
OUTPUT
Q3 Create Java application to calculate the result of student (Total and percentage) out of five subject.
SOLUTION: The GUI for Result Calculation is as follows:
CODING
int a,b,c,d,e,t,p;
a=Integer.parseInt(jTextField3.getText());
b=Integer.parseInt(jTextField4.getText());
c=Integer.parseInt(jTextField5.getText());
d=Integer.parseInt(jTextField6.getText());
e=Integer.parseInt(jTextField7.getText());
t=a+b+c+d+e;
p=t/5;
jTextField8.setText(""+t);
jTextField9.setText(""+p);
OUTPUT
Q 4Create a GUI application to compute and display payment amount and tax payable .
SOLUTION: The GUI for compute and display payment amount and tax payable is as follows:
CODING
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int hours = Integer.parseInt(hwTextField.getText());
double prate = Double.parseDouble(prTextField.getText());
double trate = Double.parseDouble(trTextField.getText());
double payAmt = hours* prate ;
double taxAmt = payAmt*trate ;
payamentTF.setText(""+payAmt);
taxTF.setText(""+taxAmt) ;
OUTPUT
Q 5 Create a GUI application to calculate salary of employes.
SOLUTION:
CODING
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Double BasicSalary = Double.parseDouble(BsalaryTF.getText()) ;
Double D =BasicSalary*0.15;
jTextField4.setText(""+ D);
Double H =BasicSalary*0.30;
jTextField5.setText(""+H);
Double P =BasicSalary*0.05;
jTextField6.setText(""+P);
Double NtSalary =((BasicSalary+D+H)-P);
NetSalary.setText(""+NtSalary);
OUTPUT
Bakshish
Q6 Create Java application to accept payment through three type of credit card. The discount is given according
to given criteria (Platinum card : 20% discount, Gold: 15%, Silver: 10% of amount)
SOLUTION: The GUI for discount calculation is as follows:
CODING
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
double TotalCost = Double.parseDouble(jTextField2.getText());
double offer = Double.parseDouble(jTextField3.getText());
double AdditionalOffer =Double.parseDouble(jTextField4.getText());
double netAmt = TotalCost-offer-AdditionalOffer;
jTextField5.setText(""+netAmt);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField4.setText("0");
jTextField5.setText("0");
jTextField4.setEditable(false);
jTextField5.setEditable(false);
double dis = 0;
double amt= Double.parseDouble(jTextField2.getText());
if(platRB.isSelected())
dis=amt*0.20;
else if(silvRB.isSelected())
dis= amt*0.15;
else
dis= amt*0.10;
jTextField3.setText(""+dis);
double add ;
if (amt>25000)
add =amt*0.05;
jTextField4.setText("" +dis );
jButton2.setEnabled(true);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
OUTPUT
PRATHAM
Q 7Write a Java program to calculate the factorial of number by using method.
SOLUTION: The GUI for Factorial Calculation is as follows:
CODING
private void FactorialBtnActionPerformed(java.awt.event.ActionEvent evt)
int a,c;
a=Integer.parseInt(p.getText());
c=fact(a);
q.setText(" "+c);
}
/**
* @param args the command line arguments
*/
private int fact (int x) //Method
{int z=1;
for(int i=1;i<=x;i++)
z=z*i;
return z;
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new factorial().setVisible(true);
}
});
OUTPUT
Q8 Create a Java application to find greater number out of two numbers by using method
SOLUTION: The GUI for Factorial Calculation is as follows:
CODING:
private void FindLargestBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double num1 = Double.parseDouble(num1TF.getText());
double num2 = Double.parseDouble(num2TF.getText());
largest (num1,num2);
}
private void largest (int x, int y) // METHOD
{if (x>y)
resultTF.setText(" First Number is Largest");
else
resultTF.setText(" Second Number is Largest");;
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Largest().setVisible(true);
}
});
OUTPUT
Q9 Design a GUI application using methods that obtains a number in the textfield, computes the sum of
digits and displays it in a label.
SOLUTION: The GUI for Sum Calculation is as follows:
CODING
private void SumBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int num = Integer.parseInt(numTF.getText());
int sum = addDigits(num);
OutLbl.setText(" Sum of its digits is : " +sum);
}
int addDigits (int n) {
int s = 0;
int dig;
while(n > 0) {
dig = n%10;
s = s+dig;
n = n/10;
}
return s;
}
OUTPUT
Q10 create java application to check the eligibilty for voting by using method.
SOLUTION: The GUI to check the eligibilty for voting is as follows:
CODING
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
{
Integer a;
a =Integer.parseInt(jTextField1.getText());
age (a);
}
}
/**
* @param args the command line arguments
*/private void age (int a)
{
if ( a>=18)
jTextField2.setText("eligble for voting" );
else
jTextField2.setText ("not eligible");
}
OUTPUT
Q11 Design a GUI application whether a string is palindrome or not.
SOLUTION: The GUI to check the string is palindrome or not.
CODING
private void SubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String str = strTF.getText();
showPalindrome(str);
}
public void showPalindrome(String s) {
StringBuffer out = new StringBuffer(s);
if(isPalindrome(s))
s = s+": IS a palindrome!";
else
if(isPalindrome2(s))
s = s+": IS NOT a palindrome";
outLbl.setText(s);
}
public boolean isPalindrome(String s) {
StringBuffer reversed = (new StringBuffer(s)).reverse();
return s.equals(reversed.toString());
}
public boolean isPalindrome2(String s) {
StringBuffer reversed = (new StringBuffer(s)).reverse();
return s.equalsIgnoreCase(reversed.toString());
}
OUTPUT
Q12 Create a program that displays the swapping of 2 numbers using:
Call By Value
Call By Reference
SOLUTION: The GUI for Factorial Calculation is as follows:
CODING:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
n1 = Integer.parseInt(num1TF.getText());
n2 = Integer.parseInt(num2TF.getText());
SwapByVal(n1,n2);
Num1Lbl.setText(" " + n1);
Num2Lbl.setText(" " + n2);
MsgLbl.setText("Swapped By VALUE");
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
n1 = Integer.parseInt(num1TF.getText());
n2 = Integer.parseInt(num2TF.getText());
SwapByRef(this);
Num1Lbl.setText(" " + n1);
Num2Lbl.setText(" " + n2);
MsgLbl.setText("Swapped By REFERENCE");
}
void SwapByVal(int a, int b) {
int tmp ;
tmp = a;
a = b;
b = tmp;
}
void SwapByRef(CallMechanism obj) {
int tmp;
tmp = obj.n1;
obj.n1 = obj.n2;
}
OUTPUT
12
Q13: Create a GUI application that uses a class to implement the following for a rectangle class:
Calculate area of Rectangle
Calculate perimeter of Rectangle
SOLUTION: The GUI to Calculate area of Rectangle
And Calculate perimeter of Rectangle
CODING
User defined class in class Volume I
public class Rectangle {
int length;
int breadth;
/** Creates a new instance of Rectangle */
public Rectangle() {
length = 0;
breadth = 0;
}
int area(int L,int B) {
length = L;
breadth = B;
return(length*breadth);
}
int Perimeter(int L,int B) {
length = L;
breadth = B;
return(2*(length + breadth));
}
}
private CalcBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int L,B;
int result = 0;
L = Integer.parseInt(txtLength.getText());
B = Integer.parseInt(txtBreadth.getText());
// Create an object RecObj for Rectangle class
Rectangle RecObj = new Rectangle();
if(jRadioButton1.isSelected())
{
result = RecObj.area(L,B);
}
else
if(jRadioButton2.isSelected())
{
result = RecObj.Perimeter(L,B);
}
txtResult.setText(Integer.toString(result));
}
private void ExitBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0); }
OUTPUT
Q14 Write a program that finds the area of circle and cylinder using java overriding method
SOLUTION: The GUI to calculate the area of circle and cylinder
CODING
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double rad,len;
double AreaC,AreaCy;
rad = Double.parseDouble(txtR.getText());
len = Double.parseDouble(txtL.getText());
Circle cir = new Circle(rad);
Cylinder cyl = new Cylinder(rad,len);
AreaC = cir.getArea();
AreaCy = cyl.getArea();
txtCircle.setText(Double.toString(AreaC));
txtCylinder.setText(Double.toString(AreaCy));
}
class Circle {
protected double radius;
public Circle(double radius) {
this.radius = radius;
}
public double getArea() {
return Math.PI*radius*radius;
}
}
class Cylinder extends Circle {
protected double length;
public Cylinder(double radius,double length) {
super(radius);
this.length = length;
}
public double getArea() {
return 2*super.getArea() + 2*Math.PI*radius*length;
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new INHERITANCE().setVisible(true);
}
});
}
OUTPUT
Q15Design a GUI application to demonstrate the abstract class concept for the class declaration to print the
message.
SOLUTION: The GUI to demonstrate the abstract class concept for the class declaration to print the message.
//CODING:
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
private void PrintMessageActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
subClass sb = new subClass();
sb.print_String();
}
abstract class Message
{
abstract String printData();
public void print_String()
{
jTextField1.setText(printData());
}
}
class subClass extends Message
{
String printData()
{
return " Java Abstract Class Concepts "; } }
OUTPUT
Q16 DesignGUI application using connectivity that canretrieve data from dept table
from My SQL database.
SOLUTION: The GUI that can retrieve data from dept table from My SQL database.
CODING
import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public class DatabaseConnectivity extends javax.swing.JFrame {
/** Creates new form DatabaseConnectivity */
public DatabaseConnectivity() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
depTbl = new javax.swing.JTable();
rtrBtn = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
depTbl.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"DeptNo", "Dname", "Title 3"
}
));
jScrollPane1.setViewportView(depTbl);
rtrBtn.setText("Retrieve Data from Database");
rtrBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rtrBtnActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(148, 148, 148)
.addComponent(rtrBtn)
.addContainerGap(179, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275,
javax.swing.GroupLayout.PREFERRED_SIZE
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
.addComponent(rtrBtn)
.addGap(25, 25, 25))
);
pack();
}// </editor-fold>
private void rtrBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
DefaultTableModel model = ( DefaultTableModel) depTbl.getModel();
try {
Class.forName("java.sql.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost/user","root","admin");
Statement stmt = con.createStatement();
String query = "SELECT * from dept;";
ResultSet rs = stmt.executeQuery(query);
while(rs.next()) {
String dno = rs.getString("deptno");
String dName = rs.getString("dname");
String lc = rs.getString("loc");
model.addRow (new object[] {dno,dName,lc});
}
rs.close();
stmt.close();
con.close();
}
catch (Exception e) {
JOptionPane.showMessageDialog(null,"Error in Connectivity");
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new DatabaseConnectivity().setVisible(true);
}
});
}
OUTPUT
Q17:Create a java GUI applicationthat obtains records from a table(sayempl) basedon
three different criteria.It then displays all retrieved records basedon all the criteria
togetherin one table.
SOLUTION: The GUI that that obtains records from a table(say empl) based on three different
criteria.It then displays all retrieved records based on all the criteria together in one table.
CODING
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Search_From_Database.java
*
*/
package jdbc_2_ques;
/**
*/
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;
public class Search_From_Database extends javax.swing.JFrame {
String msg = "";
/** Creates new form Search_From_Database */
public Search_From_Database() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
criteriaTF = new javax.swing.JTextField();
opCBX = new javax.swing.JComboBox();
srchFldCBX = new javax.swing.JComboBox();
jSeparator1 = new javax.swing.JSeparator();
searchBtn = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
emplTbl = new javax.swing.JTable();
exitBtn = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel1.setText("Specify search criteria below");
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel2.setText("Search Field");
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel3.setText("Criteria");
criteriaTF.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
opCBX.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
opCBX.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "=", "<", ">", "!=" }));
srchFldCBX.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
srchFldCBX.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "empno", "ename", "job",
"sal", "deptno" }));
searchBtn.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
searchBtn.setText("Fetch from database");
searchBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
searchBtnActionPerformed(evt);
}
});
emplTbl.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
emplTbl.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"EmpNo", "EmpName", "Job", "HireDate", "Sal", "DeptNo"
}
));
jScrollPane1.setViewportView(emplTbl);
exitBtn.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
exitBtn.setText("Exit");
exitBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitBtnActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(187, 187, 187)
.addComponent(jLabel1)
.addContainerGap(200, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(srchFldCBX, javax.swing.GroupLayout.PREFERRED_SIZE, 95,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(118, 118, 118)
.addComponent(opCBX, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel2))
.addGap(145, 145, 145)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(criteriaTF, javax.swing.GroupLayout.PREFERRED_SIZE, 111,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(33, 33, 33))
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 581, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(200, 200, 200)
.addComponent(searchBtn)
.addContainerGap(206, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 557, Short.MAX_VALUE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(238, 238, 238)
.addComponent(exitBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 91,
javax.swing.GroupLayout.PREFERRED_SIZE
.addContainerGap(252, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(opCBX, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(srchFldCBX, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(criteriaTF, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(searchBtn)
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 228,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(exitBtn)
.addContainerGap(16, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void searchBtnActionPerformed(java.awt.event.ActionEvent evt)
// TODO add your handling code here:
DefaultTableModel model = ( DefaultTableModel) emplTbl.getModel();
try {
Class.forName("java.sql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/yash","root","admin");
Statement stmt = con.createStatement();
String sfld = (String) srchFldCBX.getSelectedItem();
String op = (String) opCBX.getSelectedItem();
String crit = criteriaTF.getText();
String query = "SELECT empno,ename,job,hiredate,sal,deptno FROM empl WHERE " + " " + op + " " + crit +
";";
ResultSet rs = stmt.executeQuery(query);
int count = 0;
while(rs.next()) {
count++;
model.addRow (new object[] {
rs.getInt(1),rs.getString(2),rs.getString(3),rs.getDate(4),rs.getFloat(5),rs.getInt(6)});
}
msg = msg+"Criteria'"+sfld+""+op+""+crit+"' fetched" + count + "rows.n";
rs.close();
stmt.close();
con.close();
}
catch (Exception e) {
JOptionPane.showMessageDialog(null,"Error in Connectivity");
}
}
private void exitBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JOptionPane.showMessageDialog(null,msg);
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Search_From_Database().setVisible(true);
}
});
OUTPUT
Q18 Create a GUIapplicationthat computes calories in meal.
Screenshot
CODING:
txtCarbo.setText("");
txtFat.setText("");
txtPro.setText("");
txtCal.setText("");
}
floatCarbo,Fat, Prot;
floatTcal = 0;
Carbo=Integer.parseInt(txtCarbo.getText());
Fat=Integer.parseInt(txtFat.getText());
Prot=Integer.parseInt(txtPro.getText());
Tcal=(Carbo/4)+(Fat/9)+(Prot/4);
txtCal.setText(Float.toString(Tcal));
}
OUTPUT
Q19 Write JAVA application that input number & find
-number of days in that month
-Table of input number
-First ten evennumbers
CODING:
private voidjButton1ActionPerformed(java.awt.event.ActionEventevt) {
intn=Integer.parseInt(t1.getText());
for(inti=1;i<=10;i++)
ta.append(""+n+"*"+i+"="+n*i+"n");
:
}
private voidjButton2ActionPerformed(java.awt.event.ActionEventevt) {
intmno=Integer.parseInt(t1.getText());
switch(mno)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
JOptionPane.showMessageDialog(null,"31days");
break;
case 2:
JOptionPane.showMessageDialog(null,"28or29 days");
break;
case 4:
case 6:
case 9:
case 11:
JOptionPane.showMessageDialog(null,"30days");
default:
System.out.print("notmonthnumber");
}
}
private voidjButton3ActionPerformed(java.awt.event.ActionEventevt) {
for(inti=2;i<=20;i=i+2)
{
JOptionPane.showMessageDialog(null,i);}}
OUTPUT
Q20 Write JAVA application that input number and show the week day
private voidjButton1ActionPerformed(java.awt.event.ActionEventevt) {
intno=Integer.parseInt(t1.getText());
switch(no)
{
case 1:
l2.setText("sunday");
break;
case 2:
l2.setText("Monday");
break;
case 3:
l2.setText("Tuesday");
break;
case 4:
l2.setText("Wednesday");
break;
case 5:
l2.setText("Thursday");
break;
case 6:
l2.setText("Friday");
break;
case 7:
l2.setText("Friday");
break;
default:
l2.setText("invaliddayno");
}
OUTPUT
MY-SQL STATEMENTS
Q1. Write MySQL query to create a database named “school”.
Solution: create database school;
Q2: Write MySQL Query to use the database named “school”.
Solution: use school;
Q3: Using SQL statements in mysql,create the tables identified below in the following order (underlined
columns depict primary keys).
(i) Campus(CampusID,CampusName,Street,City,State,Pin,Phone,CampusDiscout)
Solution:
create table Campus(CampusID varchar(20),CampusName varchar(50),Street varchar(50),City
varchar(20),State varchar(20),Pin varchar(10),Phone varchar(10),CampusDicount decimal(2,2);
(ii) Members(MemberID,LastName ,FirstName,CampusAddress ,CampusPhone ,CampusID
,PositionID,ContractDuration).
Solution: create table Members(MemberID varchar(10),LastName varchar(20),FirstName
varchar(20),CampusAddress varchar(50),CampusPhone varchar(20),CampusID
varchar(10),PositionID varchar(10),ContractDuration varchar(20));
(iii) Position(PositionID ,Position ,YearlyMembershipFee).
Solution: Position(PositionID varchar(10),Position varchar(20),YearlyMembershipFee varchar(20));
Q4: Write SQL Statements to show data of table named “Position1”.
Solution: select * from Position1;
Q5: Write a MySQL query to display current date and time.
Solution: select now();
Q6: Write SQL commands to show the output of 3.14*8.
Solution: select 3.14*8;
Q7: Write SQL command to show the output of round(235.327,2).
Solution: select round(235.327,2);
Q8: Write MySQL command to predict the output of mid(‘Banasthali’,4,5).
Solution: select MID(‘Banasthali’,4,5);
Q9: Write MySQL query to predict the output of MOD(16,3).
Solution: select MOD(16,3);
Q10: Tell the output of the MySQL query: select UPPER(‘Banasthali Public School’ AS “School Name”;
Solution: select UPPER (‘Banasthali Public School’ ) AS “School Name”;
Q11: Write a mysql query to predict the output of POWER(4,2).
Solution: select POWER(4,2);
Q12: Write SQL commands for creating a table “student” with the following details:
FIELD NAME DATA TYPE SIZE CONSTRAINT
StudentID integer 5 Unique
LastName Varchar 30
FirstName Varchar 30
Score integer 5
Solution: create table student(StudentID int(5) UNIQUE,LastName varchar(30),FirstName varchar(30),Score
int(5));
Q13: Write SQL command to create a table “customer” with following constraints [SID-Primary Key]
Customer SID(integer),LastName varchar(30),FirstName varchar(30).
Solution: create table customer(CustomerID int(5) PRIMARY KEY,LastName varchar(30),FirstName
varchar(30));
Q14: Write MySQL command to remove the tuples from employee table that have gross salary less than
2200.
Solution: DELETE from employee where GrossSalary<2200;
Q15: Write MySQL query to add a new column tel_number at type integer in table employee.
Solution:ALTER table employee ADD (tel_number int(10));
Q16: Write MySQL command that counts the number of rows of score column in Q12 in table student.
Solution:select COUNT(Score) from student;
Q17: Write SQL query to display the details of all the students whose Last_Name starts with the letter
“S”.
Solution:select * from student where LastName like’S%’;
Q18: Write a query to display name of all students that have distinct (Last_Name) from the table student.
Solution: select DISTINCT LastName from student;
Q19: Write MySQL query to show the structure of the table “student”.
Solution: desc student;
Q20: Write MySQl query to add foreign key through alter table command on the table “orders” which
has the following structure:
COLUMN
NAME
CHARACTERISTIC
SID Primary Key
Last_Name
First_Name
TABLE : orders TABLE : customer
COLUMN
NAME
CHARACTERISTIC
OrderID Primary Key
Amount
OrderDate
CustomerSID Foreign Key
Solution: ALTER table orders ADD FOREIGN KEY(Customer_SID) references customer(SID);

More Related Content

What's hot

Computer science Project for class 11th and 12th(library management system)
Computer science Project for class 11th and 12th(library management system)Computer science Project for class 11th and 12th(library management system)
Computer science Project for class 11th and 12th(library management system)lokesh meena
 
12th CBSE Computer Science Project
12th CBSE Computer Science Project  12th CBSE Computer Science Project
12th CBSE Computer Science Project Ashwin Francis
 
Computer science class 12 project on Super Market Billing
Computer science class 12 project on Super Market BillingComputer science class 12 project on Super Market Billing
Computer science class 12 project on Super Market BillingHarsh Kumar
 
Cbse economics class 12 board project digital india
Cbse economics  class 12 board  project  digital indiaCbse economics  class 12 board  project  digital india
Cbse economics class 12 board project digital indiapranoy_seenu
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL fileRACHIT_GUPTA
 
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12THBANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12THSHAJUS5
 
cbse 12 computer science IP
cbse 12 computer science IPcbse 12 computer science IP
cbse 12 computer science IPD. j Vicky
 
Accounts Comprehensive Project Class 11
Accounts Comprehensive Project Class 11Accounts Comprehensive Project Class 11
Accounts Comprehensive Project Class 11AayushSh
 
Computer Science Investigatory Project Class XII CBSE(Latest Syllabus)(Python...
Computer Science Investigatory Project Class XII CBSE(Latest Syllabus)(Python...Computer Science Investigatory Project Class XII CBSE(Latest Syllabus)(Python...
Computer Science Investigatory Project Class XII CBSE(Latest Syllabus)(Python...ArkaSarkar23
 
CHEMISTRY INVESTIGATORY PROJECT by prerna.pdf
CHEMISTRY INVESTIGATORY PROJECT by prerna.pdfCHEMISTRY INVESTIGATORY PROJECT by prerna.pdf
CHEMISTRY INVESTIGATORY PROJECT by prerna.pdfAmansinghTomar9
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILECOMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILEAnushka Rai
 
12th CBSE Computer Science Project
12th CBSE Computer Science Project12th CBSE Computer Science Project
12th CBSE Computer Science ProjectAshwin Francis
 
PROJECT ON HOTEL MANAGEMENT.pdf
PROJECT ON HOTEL MANAGEMENT.pdfPROJECT ON HOTEL MANAGEMENT.pdf
PROJECT ON HOTEL MANAGEMENT.pdfNakulSingh78
 
Solved Accounting Ratios with Balance Sheet(vertical) and Statement of Profit...
Solved Accounting Ratios with Balance Sheet(vertical) and Statement of Profit...Solved Accounting Ratios with Balance Sheet(vertical) and Statement of Profit...
Solved Accounting Ratios with Balance Sheet(vertical) and Statement of Profit...Dan John
 
Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12Self-employed
 
Node.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterNode.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterSimen Li
 
IP Final project 12th
IP Final project 12thIP Final project 12th
IP Final project 12thSantySS
 
PHYSICAL EDUCATION PRACTICAL FILE ( Class 12th)
PHYSICAL EDUCATION PRACTICAL FILE ( Class 12th)PHYSICAL EDUCATION PRACTICAL FILE ( Class 12th)
PHYSICAL EDUCATION PRACTICAL FILE ( Class 12th)Anushka Rai
 

What's hot (20)

Computer science Project for class 11th and 12th(library management system)
Computer science Project for class 11th and 12th(library management system)Computer science Project for class 11th and 12th(library management system)
Computer science Project for class 11th and 12th(library management system)
 
12th CBSE Computer Science Project
12th CBSE Computer Science Project  12th CBSE Computer Science Project
12th CBSE Computer Science Project
 
Computer science class 12 project on Super Market Billing
Computer science class 12 project on Super Market BillingComputer science class 12 project on Super Market Billing
Computer science class 12 project on Super Market Billing
 
informatics practices practical file
informatics practices practical fileinformatics practices practical file
informatics practices practical file
 
Cbse economics class 12 board project digital india
Cbse economics  class 12 board  project  digital indiaCbse economics  class 12 board  project  digital india
Cbse economics class 12 board project digital india
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
 
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12THBANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
 
cbse 12 computer science IP
cbse 12 computer science IPcbse 12 computer science IP
cbse 12 computer science IP
 
Accounts Comprehensive Project Class 11
Accounts Comprehensive Project Class 11Accounts Comprehensive Project Class 11
Accounts Comprehensive Project Class 11
 
Computer Science Investigatory Project Class XII CBSE(Latest Syllabus)(Python...
Computer Science Investigatory Project Class XII CBSE(Latest Syllabus)(Python...Computer Science Investigatory Project Class XII CBSE(Latest Syllabus)(Python...
Computer Science Investigatory Project Class XII CBSE(Latest Syllabus)(Python...
 
CHEMISTRY INVESTIGATORY PROJECT by prerna.pdf
CHEMISTRY INVESTIGATORY PROJECT by prerna.pdfCHEMISTRY INVESTIGATORY PROJECT by prerna.pdf
CHEMISTRY INVESTIGATORY PROJECT by prerna.pdf
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILECOMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
 
12th CBSE Computer Science Project
12th CBSE Computer Science Project12th CBSE Computer Science Project
12th CBSE Computer Science Project
 
PROJECT ON HOTEL MANAGEMENT.pdf
PROJECT ON HOTEL MANAGEMENT.pdfPROJECT ON HOTEL MANAGEMENT.pdf
PROJECT ON HOTEL MANAGEMENT.pdf
 
Solved Accounting Ratios with Balance Sheet(vertical) and Statement of Profit...
Solved Accounting Ratios with Balance Sheet(vertical) and Statement of Profit...Solved Accounting Ratios with Balance Sheet(vertical) and Statement of Profit...
Solved Accounting Ratios with Balance Sheet(vertical) and Statement of Profit...
 
Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12
 
Digital india
Digital indiaDigital india
Digital india
 
Node.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterNode.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitter
 
IP Final project 12th
IP Final project 12thIP Final project 12th
IP Final project 12th
 
PHYSICAL EDUCATION PRACTICAL FILE ( Class 12th)
PHYSICAL EDUCATION PRACTICAL FILE ( Class 12th)PHYSICAL EDUCATION PRACTICAL FILE ( Class 12th)
PHYSICAL EDUCATION PRACTICAL FILE ( Class 12th)
 

Similar to Informatics Practice Practical for 12th class

New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word documentnidhileena
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answersQuratulain Naqvi
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201rohassanie
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignmentSaket Pathak
 
Report in Java programming and SQL
Report in Java programming and SQLReport in Java programming and SQL
Report in Java programming and SQLvikram mahendra
 
Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)mehul patel
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diplomamustkeem khan
 
The real beginner's guide to android testing
The real beginner's guide to android testingThe real beginner's guide to android testing
The real beginner's guide to android testingEric (Trung Dung) Nguyen
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 solIIUM
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfChen-Hung Hu
 
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8tdc-globalcode
 
COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEWshyamuopeight
 
CIS 115 Exceptional Education - snaptutorial.com
CIS 115   Exceptional Education - snaptutorial.comCIS 115   Exceptional Education - snaptutorial.com
CIS 115 Exceptional Education - snaptutorial.comDavisMurphyB33
 
Cis 115 Education Organization -- snaptutorial.com
Cis 115   Education Organization -- snaptutorial.comCis 115   Education Organization -- snaptutorial.com
Cis 115 Education Organization -- snaptutorial.comDavisMurphyB99
 
Final report mobile shop
Final report   mobile shopFinal report   mobile shop
Final report mobile shopViditsingh22
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALPrabhu D
 

Similar to Informatics Practice Practical for 12th class (20)

New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignment
 
Report in Java programming and SQL
Report in Java programming and SQLReport in Java programming and SQL
Report in Java programming and SQL
 
17 Jo P May 08
17 Jo P May 0817 Jo P May 08
17 Jo P May 08
 
Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diploma
 
The real beginner's guide to android testing
The real beginner's guide to android testingThe real beginner's guide to android testing
The real beginner's guide to android testing
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 sol
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdf
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
Java final lab
Java final labJava final lab
Java final lab
 
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
 
COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEW
 
CIS 115 Exceptional Education - snaptutorial.com
CIS 115   Exceptional Education - snaptutorial.comCIS 115   Exceptional Education - snaptutorial.com
CIS 115 Exceptional Education - snaptutorial.com
 
Cis 115 Education Organization -- snaptutorial.com
Cis 115   Education Organization -- snaptutorial.comCis 115   Education Organization -- snaptutorial.com
Cis 115 Education Organization -- snaptutorial.com
 
Final report mobile shop
Final report   mobile shopFinal report   mobile shop
Final report mobile shop
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
 

Recently uploaded

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

Informatics Practice Practical for 12th class

  • 1. INFORMATICS PRACTICES PRACTICAL FILE RICH HARVEST PUBLIC SCHOOL NEW DELHI SUBMITTED TO SUBMITTEDBY MS. MADHUR DEEP NAME: Aman Kumar CLASS: XII ROLL No :
  • 2. INDEX S.NO. TOPIC 1 Create a GUI application to calculate commission of salesman. 2 Create a GUI application for a simple calculator 3 Create Java application to calculate the result of student (Total and percentage) out of five subject 4 Create a GUI application to compute and display payment amount and tax payable . 5 Create GUI application to calculate the salary of employee details are shown on respective page. 6 Create Java application to calculate the total amount of purchasing ,it will accept payment through three type of credit card. The discount is given according to given criteria (Platinum card : 20% discount, Gold: 15%, Silver: 10% of amount) 7 Write a Java program to calculate the factorial of number by using method. 8 Create a Java application to find greater number out of two numbers by using method. 9. Design a GUI application to compute the sum of digits of a number by using method 10 Design a GUI application using methods to check the eligibility for voting . 11 Write a program to check whether a string is palindrome or not? 12 Write a program that displays the swapping of 2 numbers using: a) Call By Value b) Call By Reference
  • 3. 13 Write a program that uses a class to implement the following for a rectangle class: a) Calculate area of Rectangle b) Calculate perimeter of Rectangle 14 Write a program that finds the area of circle and cylinder using java overriding method 15 Write a program to demonstrate the abstract class concept for the class declaration to print the message 16 Create a GUI application using connectivity that can retrive data from dept table from my sql database 17 Create a GUI application that obtains record from tables (say empl) based on three different criteria .It then display all retrived records based on all the criteria together in one table. 18 create a GUI application that computes calories in meal. 19 Write JAVA application that input number & find -number of days in that month -Table of input number -First ten evennumbers 20 Write JAVA application that input number and show the week day 21 SQL QUERIES (20 QUESTIONS)
  • 4. Q1 Calculate the commission for the salesman according to the following rates: Sales Commission Rate 30001 onwards 15% 22001- 30000 10% 12001- 22000 7% 5001- 12000 3% 0-5000 0% SOLUTION: The GUI for sales commission calculator is as follows: CODING: private void CalcButtonActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: // obtain input String txt = SalesTF.getText(); double sales; sales = Double.parseDouble(txt); double comm; // calculate commission if(sales > 30000) comm = sales*0.15;
  • 5. else if(sales > 22000) comm = sales*0.10; else if(sales > 12000) comm = sales*0.07; else if(sales > 5000) comm = sales*0.03; else comm = 0; //display output CommLabel.setText("The Commission is Rs. "+comm); } OUTPUT
  • 6. Q2 create java application to design simple SOLUTION: The GUI for Simple Calculator is as follows: CODING: private void plusBtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: opLabel.setText("+"); double num1 = Double.parseDouble(Num1TF.getText()); double num2 = Double.parseDouble(Num2TF.getText()); double num3 = num1 + num2; Num3TF.setText("" + num3); } private void MinusBtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: opLabel.setText("-"); double num1 = Double.parseDouble(Num1TF.getText()); double num2 = Double.parseDouble(Num2TF.getText()); double num3 = num1 - num2; Num3TF.setText("" + num3); } private void MulBtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: opLabel.setText("*"); double num1 = Double.parseDouble(Num1TF.getText()); double num2 = Double.parseDouble(Num2TF.getText()); double num3 = num1 * num2; Num3TF.setText("" + num3); }
  • 7. private void DivBtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: opLabel.setText("/"); double num1 = Double.parseDouble(Num1TF.getText()); double num2 = Double.parseDouble(Num2TF.getText()); double num3 = num1 / num2; Num3TF.setText("" + num3); } private void ModBtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: opLabel.setText("%"); double num1 = Double.parseDouble(Num1TF.getText()); double num2 = Double.parseDouble(Num2TF.getText()); double num3 = num1 % num2; Num3TF.setText("" + num3); } OUTPUT
  • 8. Q3 Create Java application to calculate the result of student (Total and percentage) out of five subject. SOLUTION: The GUI for Result Calculation is as follows: CODING int a,b,c,d,e,t,p; a=Integer.parseInt(jTextField3.getText()); b=Integer.parseInt(jTextField4.getText()); c=Integer.parseInt(jTextField5.getText()); d=Integer.parseInt(jTextField6.getText()); e=Integer.parseInt(jTextField7.getText()); t=a+b+c+d+e; p=t/5; jTextField8.setText(""+t); jTextField9.setText(""+p); OUTPUT
  • 9. Q 4Create a GUI application to compute and display payment amount and tax payable . SOLUTION: The GUI for compute and display payment amount and tax payable is as follows: CODING private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { int hours = Integer.parseInt(hwTextField.getText()); double prate = Double.parseDouble(prTextField.getText()); double trate = Double.parseDouble(trTextField.getText()); double payAmt = hours* prate ; double taxAmt = payAmt*trate ; payamentTF.setText(""+payAmt); taxTF.setText(""+taxAmt) ; OUTPUT
  • 10. Q 5 Create a GUI application to calculate salary of employes. SOLUTION: CODING private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { Double BasicSalary = Double.parseDouble(BsalaryTF.getText()) ; Double D =BasicSalary*0.15; jTextField4.setText(""+ D); Double H =BasicSalary*0.30; jTextField5.setText(""+H); Double P =BasicSalary*0.05; jTextField6.setText(""+P); Double NtSalary =((BasicSalary+D+H)-P); NetSalary.setText(""+NtSalary); OUTPUT Bakshish
  • 11. Q6 Create Java application to accept payment through three type of credit card. The discount is given according to given criteria (Platinum card : 20% discount, Gold: 15%, Silver: 10% of amount) SOLUTION: The GUI for discount calculation is as follows: CODING private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { double TotalCost = Double.parseDouble(jTextField2.getText()); double offer = Double.parseDouble(jTextField3.getText()); double AdditionalOffer =Double.parseDouble(jTextField4.getText()); double netAmt = TotalCost-offer-AdditionalOffer; jTextField5.setText(""+netAmt); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { jTextField4.setText("0"); jTextField5.setText("0"); jTextField4.setEditable(false); jTextField5.setEditable(false); double dis = 0; double amt= Double.parseDouble(jTextField2.getText()); if(platRB.isSelected()) dis=amt*0.20; else if(silvRB.isSelected()) dis= amt*0.15; else
  • 12. dis= amt*0.10; jTextField3.setText(""+dis); double add ; if (amt>25000) add =amt*0.05; jTextField4.setText("" +dis ); jButton2.setEnabled(true); } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0); OUTPUT PRATHAM
  • 13. Q 7Write a Java program to calculate the factorial of number by using method. SOLUTION: The GUI for Factorial Calculation is as follows: CODING private void FactorialBtnActionPerformed(java.awt.event.ActionEvent evt) int a,c; a=Integer.parseInt(p.getText()); c=fact(a); q.setText(" "+c); } /** * @param args the command line arguments */ private int fact (int x) //Method {int z=1; for(int i=1;i<=x;i++) z=z*i; return z; } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new factorial().setVisible(true); } });
  • 15. Q8 Create a Java application to find greater number out of two numbers by using method SOLUTION: The GUI for Factorial Calculation is as follows: CODING: private void FindLargestBtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: double num1 = Double.parseDouble(num1TF.getText()); double num2 = Double.parseDouble(num2TF.getText()); largest (num1,num2); } private void largest (int x, int y) // METHOD {if (x>y) resultTF.setText(" First Number is Largest"); else resultTF.setText(" Second Number is Largest");; } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Largest().setVisible(true); } });
  • 17. Q9 Design a GUI application using methods that obtains a number in the textfield, computes the sum of digits and displays it in a label. SOLUTION: The GUI for Sum Calculation is as follows: CODING private void SumBtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: int num = Integer.parseInt(numTF.getText()); int sum = addDigits(num); OutLbl.setText(" Sum of its digits is : " +sum); } int addDigits (int n) { int s = 0; int dig; while(n > 0) { dig = n%10; s = s+dig; n = n/10; } return s; }
  • 19. Q10 create java application to check the eligibilty for voting by using method. SOLUTION: The GUI to check the eligibilty for voting is as follows: CODING private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { { Integer a; a =Integer.parseInt(jTextField1.getText()); age (a); } } /** * @param args the command line arguments */private void age (int a) { if ( a>=18) jTextField2.setText("eligble for voting" ); else jTextField2.setText ("not eligible"); }
  • 21. Q11 Design a GUI application whether a string is palindrome or not. SOLUTION: The GUI to check the string is palindrome or not. CODING private void SubmitButtonActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: String str = strTF.getText(); showPalindrome(str); } public void showPalindrome(String s) { StringBuffer out = new StringBuffer(s); if(isPalindrome(s)) s = s+": IS a palindrome!"; else if(isPalindrome2(s)) s = s+": IS NOT a palindrome"; outLbl.setText(s); } public boolean isPalindrome(String s) { StringBuffer reversed = (new StringBuffer(s)).reverse(); return s.equals(reversed.toString()); } public boolean isPalindrome2(String s) { StringBuffer reversed = (new StringBuffer(s)).reverse(); return s.equalsIgnoreCase(reversed.toString()); }
  • 23. Q12 Create a program that displays the swapping of 2 numbers using: Call By Value Call By Reference SOLUTION: The GUI for Factorial Calculation is as follows: CODING: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: n1 = Integer.parseInt(num1TF.getText()); n2 = Integer.parseInt(num2TF.getText()); SwapByVal(n1,n2); Num1Lbl.setText(" " + n1); Num2Lbl.setText(" " + n2); MsgLbl.setText("Swapped By VALUE"); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: n1 = Integer.parseInt(num1TF.getText()); n2 = Integer.parseInt(num2TF.getText()); SwapByRef(this); Num1Lbl.setText(" " + n1); Num2Lbl.setText(" " + n2); MsgLbl.setText("Swapped By REFERENCE"); }
  • 24. void SwapByVal(int a, int b) { int tmp ; tmp = a; a = b; b = tmp; } void SwapByRef(CallMechanism obj) { int tmp; tmp = obj.n1; obj.n1 = obj.n2; } OUTPUT 12
  • 25. Q13: Create a GUI application that uses a class to implement the following for a rectangle class: Calculate area of Rectangle Calculate perimeter of Rectangle SOLUTION: The GUI to Calculate area of Rectangle And Calculate perimeter of Rectangle CODING User defined class in class Volume I public class Rectangle { int length; int breadth; /** Creates a new instance of Rectangle */ public Rectangle() { length = 0; breadth = 0; } int area(int L,int B) { length = L; breadth = B; return(length*breadth); } int Perimeter(int L,int B) { length = L; breadth = B; return(2*(length + breadth)); } }
  • 26. private CalcBtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: int L,B; int result = 0; L = Integer.parseInt(txtLength.getText()); B = Integer.parseInt(txtBreadth.getText()); // Create an object RecObj for Rectangle class Rectangle RecObj = new Rectangle(); if(jRadioButton1.isSelected()) { result = RecObj.area(L,B); } else if(jRadioButton2.isSelected()) { result = RecObj.Perimeter(L,B); } txtResult.setText(Integer.toString(result)); } private void ExitBtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: System.exit(0); } OUTPUT
  • 27. Q14 Write a program that finds the area of circle and cylinder using java overriding method SOLUTION: The GUI to calculate the area of circle and cylinder CODING private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: double rad,len; double AreaC,AreaCy; rad = Double.parseDouble(txtR.getText()); len = Double.parseDouble(txtL.getText()); Circle cir = new Circle(rad); Cylinder cyl = new Cylinder(rad,len); AreaC = cir.getArea(); AreaCy = cyl.getArea(); txtCircle.setText(Double.toString(AreaC)); txtCylinder.setText(Double.toString(AreaCy));
  • 28. } class Circle { protected double radius; public Circle(double radius) { this.radius = radius; } public double getArea() { return Math.PI*radius*radius; } } class Cylinder extends Circle { protected double length; public Cylinder(double radius,double length) { super(radius); this.length = length; } public double getArea() { return 2*super.getArea() + 2*Math.PI*radius*length; } } /** * @param args the command line arguments */
  • 29. public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new INHERITANCE().setVisible(true); } }); } OUTPUT
  • 30. Q15Design a GUI application to demonstrate the abstract class concept for the class declaration to print the message. SOLUTION: The GUI to demonstrate the abstract class concept for the class declaration to print the message. //CODING: private void ExitActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: System.exit(0); } private void PrintMessageActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: subClass sb = new subClass(); sb.print_String(); } abstract class Message { abstract String printData(); public void print_String() { jTextField1.setText(printData()); } } class subClass extends Message { String printData() { return " Java Abstract Class Concepts "; } } OUTPUT
  • 31.
  • 32. Q16 DesignGUI application using connectivity that canretrieve data from dept table from My SQL database. SOLUTION: The GUI that can retrieve data from dept table from My SQL database. CODING import java.sql.*; import javax.swing.JOptionPane; import javax.swing.table.DefaultTableModel; public class DatabaseConnectivity extends javax.swing.JFrame { /** Creates new form DatabaseConnectivity */ public DatabaseConnectivity() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); depTbl = new javax.swing.JTable(); rtrBtn = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  • 33. depTbl.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { }, new String [] { "DeptNo", "Dname", "Title 3" } )); jScrollPane1.setViewportView(depTbl); rtrBtn.setText("Retrieve Data from Database"); rtrBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rtrBtnActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGap(148, 148, 148) .addComponent(rtrBtn) .addContainerGap(179, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE) .addComponent(rtrBtn) .addGap(25, 25, 25)) ); pack(); }// </editor-fold> private void rtrBtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
  • 34. DefaultTableModel model = ( DefaultTableModel) depTbl.getModel(); try { Class.forName("java.sql.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost/user","root","admin"); Statement stmt = con.createStatement(); String query = "SELECT * from dept;"; ResultSet rs = stmt.executeQuery(query); while(rs.next()) { String dno = rs.getString("deptno"); String dName = rs.getString("dname"); String lc = rs.getString("loc"); model.addRow (new object[] {dno,dName,lc}); } rs.close(); stmt.close(); con.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null,"Error in Connectivity"); } } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new DatabaseConnectivity().setVisible(true); } }); }
  • 36. Q17:Create a java GUI applicationthat obtains records from a table(sayempl) basedon three different criteria.It then displays all retrieved records basedon all the criteria togetherin one table. SOLUTION: The GUI that that obtains records from a table(say empl) based on three different criteria.It then displays all retrieved records based on all the criteria together in one table. CODING /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * Search_From_Database.java * */
  • 37. package jdbc_2_ques; /** */ import java.sql.*; import javax.swing.table.DefaultTableModel; import javax.swing.JOptionPane; public class Search_From_Database extends javax.swing.JFrame { String msg = ""; /** Creates new form Search_From_Database */ public Search_From_Database() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); criteriaTF = new javax.swing.JTextField(); opCBX = new javax.swing.JComboBox(); srchFldCBX = new javax.swing.JComboBox(); jSeparator1 = new javax.swing.JSeparator(); searchBtn = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); emplTbl = new javax.swing.JTable(); exitBtn = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel1.setText("Specify search criteria below"); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel2.setText("Search Field");
  • 38. jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel3.setText("Criteria"); criteriaTF.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N opCBX.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N opCBX.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "=", "<", ">", "!=" })); srchFldCBX.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N srchFldCBX.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "empno", "ename", "job", "sal", "deptno" })); searchBtn.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N searchBtn.setText("Fetch from database"); searchBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { searchBtnActionPerformed(evt); } }); emplTbl.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N emplTbl.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { }, new String [] { "EmpNo", "EmpName", "Job", "HireDate", "Sal", "DeptNo" } )); jScrollPane1.setViewportView(emplTbl); exitBtn.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N exitBtn.setText("Exit"); exitBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitBtnActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  • 39. .addGroup(layout.createSequentialGroup() .addGap(187, 187, 187) .addComponent(jLabel1) .addContainerGap(200, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(35, 35, 35) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(srchFldCBX, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(118, 118, 118) .addComponent(opCBX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel2)) .addGap(145, 145, 145) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3) .addComponent(criteriaTF, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(33, 33, 33)) .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 581, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGap(200, 200, 200) .addComponent(searchBtn) .addContainerGap(206, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 557, Short.MAX_VALUE) .addContainerGap()) .addGroup(layout.createSequentialGroup() .addGap(238, 238, 238) .addComponent(exitBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE .addContainerGap(252, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addGap(31, 31, 31) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2)
  • 40. .addComponent(jLabel3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(opCBX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(srchFldCBX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(criteriaTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(searchBtn) .addGap(18, 18, 18) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(exitBtn) .addContainerGap(16, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void searchBtnActionPerformed(java.awt.event.ActionEvent evt) // TODO add your handling code here: DefaultTableModel model = ( DefaultTableModel) emplTbl.getModel(); try { Class.forName("java.sql.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost/yash","root","admin"); Statement stmt = con.createStatement(); String sfld = (String) srchFldCBX.getSelectedItem(); String op = (String) opCBX.getSelectedItem(); String crit = criteriaTF.getText(); String query = "SELECT empno,ename,job,hiredate,sal,deptno FROM empl WHERE " + " " + op + " " + crit + ";"; ResultSet rs = stmt.executeQuery(query); int count = 0; while(rs.next()) { count++;
  • 41. model.addRow (new object[] { rs.getInt(1),rs.getString(2),rs.getString(3),rs.getDate(4),rs.getFloat(5),rs.getInt(6)}); } msg = msg+"Criteria'"+sfld+""+op+""+crit+"' fetched" + count + "rows.n"; rs.close(); stmt.close(); con.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null,"Error in Connectivity"); } } private void exitBtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: JOptionPane.showMessageDialog(null,msg); System.exit(0); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Search_From_Database().setVisible(true); } }); OUTPUT
  • 42. Q18 Create a GUIapplicationthat computes calories in meal. Screenshot CODING: txtCarbo.setText(""); txtFat.setText(""); txtPro.setText(""); txtCal.setText(""); } floatCarbo,Fat, Prot; floatTcal = 0; Carbo=Integer.parseInt(txtCarbo.getText()); Fat=Integer.parseInt(txtFat.getText()); Prot=Integer.parseInt(txtPro.getText()); Tcal=(Carbo/4)+(Fat/9)+(Prot/4); txtCal.setText(Float.toString(Tcal)); } OUTPUT
  • 43. Q19 Write JAVA application that input number & find -number of days in that month -Table of input number -First ten evennumbers CODING: private voidjButton1ActionPerformed(java.awt.event.ActionEventevt) { intn=Integer.parseInt(t1.getText()); for(inti=1;i<=10;i++) ta.append(""+n+"*"+i+"="+n*i+"n"); : } private voidjButton2ActionPerformed(java.awt.event.ActionEventevt) { intmno=Integer.parseInt(t1.getText()); switch(mno) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: JOptionPane.showMessageDialog(null,"31days"); break; case 2: JOptionPane.showMessageDialog(null,"28or29 days"); break; case 4: case 6: case 9: case 11: JOptionPane.showMessageDialog(null,"30days"); default: System.out.print("notmonthnumber"); } } private voidjButton3ActionPerformed(java.awt.event.ActionEventevt) {
  • 45. Q20 Write JAVA application that input number and show the week day private voidjButton1ActionPerformed(java.awt.event.ActionEventevt) { intno=Integer.parseInt(t1.getText()); switch(no) { case 1: l2.setText("sunday"); break; case 2: l2.setText("Monday"); break; case 3: l2.setText("Tuesday"); break; case 4: l2.setText("Wednesday"); break; case 5: l2.setText("Thursday"); break; case 6: l2.setText("Friday"); break; case 7: l2.setText("Friday"); break; default: l2.setText("invaliddayno"); } OUTPUT
  • 46.
  • 47. MY-SQL STATEMENTS Q1. Write MySQL query to create a database named “school”. Solution: create database school; Q2: Write MySQL Query to use the database named “school”. Solution: use school; Q3: Using SQL statements in mysql,create the tables identified below in the following order (underlined columns depict primary keys). (i) Campus(CampusID,CampusName,Street,City,State,Pin,Phone,CampusDiscout) Solution: create table Campus(CampusID varchar(20),CampusName varchar(50),Street varchar(50),City varchar(20),State varchar(20),Pin varchar(10),Phone varchar(10),CampusDicount decimal(2,2); (ii) Members(MemberID,LastName ,FirstName,CampusAddress ,CampusPhone ,CampusID ,PositionID,ContractDuration). Solution: create table Members(MemberID varchar(10),LastName varchar(20),FirstName varchar(20),CampusAddress varchar(50),CampusPhone varchar(20),CampusID varchar(10),PositionID varchar(10),ContractDuration varchar(20)); (iii) Position(PositionID ,Position ,YearlyMembershipFee). Solution: Position(PositionID varchar(10),Position varchar(20),YearlyMembershipFee varchar(20));
  • 48. Q4: Write SQL Statements to show data of table named “Position1”. Solution: select * from Position1; Q5: Write a MySQL query to display current date and time. Solution: select now(); Q6: Write SQL commands to show the output of 3.14*8. Solution: select 3.14*8; Q7: Write SQL command to show the output of round(235.327,2). Solution: select round(235.327,2);
  • 49. Q8: Write MySQL command to predict the output of mid(‘Banasthali’,4,5). Solution: select MID(‘Banasthali’,4,5); Q9: Write MySQL query to predict the output of MOD(16,3). Solution: select MOD(16,3); Q10: Tell the output of the MySQL query: select UPPER(‘Banasthali Public School’ AS “School Name”; Solution: select UPPER (‘Banasthali Public School’ ) AS “School Name”; Q11: Write a mysql query to predict the output of POWER(4,2). Solution: select POWER(4,2);
  • 50. Q12: Write SQL commands for creating a table “student” with the following details: FIELD NAME DATA TYPE SIZE CONSTRAINT StudentID integer 5 Unique LastName Varchar 30 FirstName Varchar 30 Score integer 5 Solution: create table student(StudentID int(5) UNIQUE,LastName varchar(30),FirstName varchar(30),Score int(5)); Q13: Write SQL command to create a table “customer” with following constraints [SID-Primary Key] Customer SID(integer),LastName varchar(30),FirstName varchar(30). Solution: create table customer(CustomerID int(5) PRIMARY KEY,LastName varchar(30),FirstName varchar(30)); Q14: Write MySQL command to remove the tuples from employee table that have gross salary less than 2200. Solution: DELETE from employee where GrossSalary<2200;
  • 51. Q15: Write MySQL query to add a new column tel_number at type integer in table employee. Solution:ALTER table employee ADD (tel_number int(10)); Q16: Write MySQL command that counts the number of rows of score column in Q12 in table student. Solution:select COUNT(Score) from student; Q17: Write SQL query to display the details of all the students whose Last_Name starts with the letter “S”. Solution:select * from student where LastName like’S%’; Q18: Write a query to display name of all students that have distinct (Last_Name) from the table student. Solution: select DISTINCT LastName from student;
  • 52. Q19: Write MySQL query to show the structure of the table “student”. Solution: desc student; Q20: Write MySQl query to add foreign key through alter table command on the table “orders” which has the following structure: COLUMN NAME CHARACTERISTIC SID Primary Key Last_Name First_Name TABLE : orders TABLE : customer COLUMN NAME CHARACTERISTIC OrderID Primary Key Amount OrderDate CustomerSID Foreign Key Solution: ALTER table orders ADD FOREIGN KEY(Customer_SID) references customer(SID);