Вы находитесь на странице: 1из 44

 NAME- HARSH NAGESH

 CLASS- XII-F

 ROLL NO- 10
 SUBMITTED TO- SAKSHI MAM
 SCHOOL- ARMY PUBLIC SCHOOL
1
PROGRAM
ONE----------------------------------------------------------------
---------
Aim : To make a program which appends the information given.

Design :

Code : For Submit Button – String a = t1.getText(); String b = t9.getText(); String c =


t3.getText(); String d = t4.getText(); String e =
t5.getText(); String f = t6.getText();
ta.append("Name : "+a+"\n"+"House no :"+b+"\n"+"Building
:"+c+"\n"+"Street :"+d+"\n"
+"City :"+e+"\n"+"State :"+f+"\n");

Output :
2

PROGRAM
TWO---------------------------------------------------------------
---------
Aim : To make a calculator.

Design :

Code : For add button :


Double n1,n2,n3; n1 =
Double.parseDouble(t1.getText()); n2 =
Double.parseDouble(t2.getText());
n3 = n1+n2; l1.setText(""+n3);

For subtract button :


Double n1,n2,n3; n1 =
Double.parseDouble(t1.getText()); n2 =
Double.parseDouble(t2.getText());
n3 = n1-n2; l1.setText(""+n3);

For multiply button :


Double n1,n2,n3; n1 =
Double.parseDouble(t1.getText()); n2 =
Double.parseDouble(t2.getText());
n3 = n1*n2; l1.setText(""+n3);
3

For divide button :


Double n1,n2,n3; n1 =
Double.parseDouble(t1.getText()); n2 =
Double.parseDouble(t2.getText());
n3 = n1/n2; l1.setText(""+n3);
For clear button :
t1.setText("");
t2.setText("");
l1.setText("");
Output :
4
PROGRAM
THREE-------------------------------------------------------------
---------
Aim : To make a program that counts integers between two given integers.

Design :

Code : For Count button :


double i =Double.parseDouble(t1.getText()); double j
=Double.parseDouble(t2.getText());
if(j<i)
{for(;j<=i;j++){
ta.append(" "+j);}
}
else
Output : {for(;i<=j;i++){
ta.append(" "+i);
}}
5
PROGRAM
FOUR--------------------------------------------------------------
---------

Aim : To create a LCM and HCF calculator.

Design :

Code : For Calculate Button :


6
int a=Integer.parseInt(one.getText()); int
b=Integer.parseInt(two.getText());
int w, x=a, y=b, z;
while (y!=0)
{w=y; y=x%w; x=w;}
z=(a*b)/x;
disp.setText("The HCF is "+x+"\nThe LCM is "+z);}

Output :
7

PROGRAM
FIVE----------------------------------------------------------------
---------
Aim : To create percentagecalculator.

Design :

Code : For Calculate Button :


private void CalculateActionPerformed(java.awt.event.ActionEvent evt) {
int P= Integer.parseInt(p.getText()); int C= Integer.parseInt(c.getText()); int M=
Integer.parseInt(m.getText()); int E= Integer.parseInt(e.getText()); int I=
Integer.parseInt(i.getText());
double O;
8
O=(P+C+M+E+I)/5;
String G=null; if (O>=90) {
G="A+";}
else if(O>= 80 && O<90) {
G = "A-";}
else if(O>= 70 && O<80) {
G = "B+";}
else if(O>= 60 && O<70) {
G = "B-";}
else if(O>= 50 && O<60) {
G = "C+";}
else if(O>= 40 && O<50) {
G = "C-";}
For Clear Button :
else { G = "You got
s.setText(null);
F";}
For Exit Button : s.s
System.exit(0);

Output :
9

PROGRAM

SIX-----------------------------------------------------------------
----------
Aim : To create a registration for placements of job seekers.

Design :
10

Code : For Submit Button


if(pgtcb.isSelected()==true)
{
gradcb.setSelected(true); intercb.setSelected(true);
}
if(gradcb.isSelected()==true)
{
intercb.setSelected(true);
}
String str = null; if(malerb.isSelected())
{ str = "Hello Mr. "+ name.getText()+" you are registered";}

else if(femalerb.isSelected())
{ str = "Hello Ms. "+ name.getText()+" you are registered";}

JOptionPane.showMessageDialog(null,str);
For Clear Button :
gradcb.setSelected(false);
intercb.setSelected(false);
pgtcb.setSelected(false); name.setText(null);
malerb.setSelected(false);
femalerb.setSelected(false);
For Close Button :
System.exit(0);
Output :
11

PROGRAM
SEVEN-------------------------------------------------------------
---------
Aim : Design an application in which user enters his chat ID and City

Design :
12

Code : For Login Button:

String name=t1.getText(); String city=(String)c1.getSelectedItem();


l1.setText("<html>Hi "+ name +", Welcome to W3schools.net<br>How is The
Weather in "+city);

Output :
13

PROGRAM
EIGHT--------------------------------------------------------------
--------
Aim : Practical to illustrate the usage and functionality of String methods.
14
Design :

Code : For Submit


Button:

private void jButtonlActionPerformed(java.awtevent.ActionEvent evt){


String name1 = String(); name1 = .getText(); String name2 = String();
name2 = .getText(); String name3 = String();
name3 = .getText(); lengthOfString(name1);
characterAtIndex(namel); compareString(namel , name2);
concatinationl(namel , name2); concatination2(namel , name2); occurenceOfN(name3);
subString(name3);
replaceCharacter(name3); caseConversion(namel);
}
public void length0f5tring(String name) outTA.append( “LENGTH OF STRING”);
outTA.append( “\n----------\n”); outTA.append("Lenght Of String" + name + "
is " + name.length( ));
}
public void characterAtIndex(String name)
{
outTA.append(“\n\nCHARACTER AT INDEX N\n” );
outTA.append(“\n----------\n”) outTA.append(“At O the character is” +
name.charAt(0)); outTA.append(“\n At 3 the character is” + name.charAt(3));
}
public void comparestrings(String namel , String name2)
15
{
outTA.append(“\n\nCOMPARE STRINGS\n”);
outTA.append(“\n----------\n”); outTA.append(“Compare” +
name1 +”and” + name2 +”=”
namel.compareTo(name2)); outTA .append( “/nCompare”+
name2 + “and”+ name1 +
name2.compareTo(name1)); outTA .append( “/nCompare”+
name2 + “and”+ name1 +
Output :
name2.compareTo(name2));

PROGRAM
NINE---------------------------------------------------------------
---------
16
Aim : To design a simple purpose dialog through the application.

Design :

Code : For Show Button:


MsgDialog2.setVisible(true);

For OK Button:
System.exit(0);

Output :
17
18
PROGRAM
TEN----------------------------------------------------------------
----------
Aim : To design that decides the eligibility of the user as per his age.

Design :

Code : For Check Eligibility Button:

String a = JOptionPane.showInputDialog("Enter Age");


try{ int age= Integer.parseInt(a); if(age>=13
&& age<=20)
JOptionPane.showMessageDialog(null,"Is Eligible");
else
JOptionPane.showMessageDialog(null,"Is not Eligible");}

catch(NumberFormatException e){ JOptionPane.showMessageDialog(null,"Enter


age as Numeric Value");
}
19

Output :
20
PROGRAM
ELEVEN-----------------------------------------------------------
----------
Aim : To create a table that can receive input of the user and also display total count of records.

Design :

Code : For Add row Button:

Object []x = {t1.getText(),t2.getText(),t3.getText(),t4.getText(),}; DefaultTableModel Tbl =


(DefaultTableModel)tbl.getModel();
Tbl.addRow(x);

For Display Count Button:


JOptionPane.showMessageDialog(null, tbl.getRowCount());

For Classwise Count Button :


int a = tbl.getRowCount(); Object A = tbl.getValueAt(0,2); Object val =
new Object();
int cnt = 1; String msg = new String();
int i; for(i=1; i<a; ++i)
{val = tbl.getValueAt(i,2);
if(val.equals(A))
{cnt++;} else {msg = msg+"Class "+tbl.getValueAt(i-
21
cnt = 1; A= tbl.getValueAt(i,2);}}
msg = msg+" Class "+tbl.getValueAt(i-1,2)+" has "+cnt+" students.\n";
JOptionPane.showMessageDialog(null,msg);

For Exit Button:


System.exit(0);}

Output :
22
PROGRAM
TWELVE-----------------------------------------------------------
---------
Aim : To create a table that can receive input of the user and manage an address book.

Design :

Code : For Add Record Button:

Object []x = {t1.getText(),t2.getText(),t3.getText(),t4.getText()}; DefaultTableModel a =


(DefaultTableModel)tbl.getModel();
a.addRow(x); int sn = Integer.parseInt(t1.getText());
t1.setText(""+(++sn));
t2.setText("");
t3.setText("");
t4.setText("");

For Clear Record Button:


t2.setText("");
t3.setText("");
t4.setText("");
23

For Statistics Button :


int r = tbl.getRowCount(); JOptionPane.showMessageDialog(null,"Total
Records in the address in the
book:"+r);

For Exit Button:


System.exit(0);}

For Search Button:


int c = Integer.parseInt(t5.getText()); int r = Integer.parseInt(t6.getText());
Object A = t6.getText();
c = c-1;
int i; for(i=0;i<r; ++i)
{Object f = tbl.getValueAt(i,c);
if(f.equals(A))
{JOptionPane.showMessageDialog(rootPane,"Exists in Record");} else
{JOptionPane.showMessageDialog(rootPane, "Record with this value doesn't
exist");}}
Output :
24

PROGRAM
THIRTEEN--------------------------------------------------------
----------
Aim : To create a GUI component that updates and deletes records on a database.

Design :

Code :

public class Connectivity extends javax.swing.JFrame {

Connection con= null; Statement stmt = null; ResultSet rs = null;}

For Load Button:


private void loadBtnActionPerformed(java.awt.event.ActionEvent evt)
try{Class.forName(“java.sql.Driver”);
con=DriverManager.getConnection(“jdbc:mysql://localhost/test”,”root”,”friends”);
stmt = con.createStatement(); String query =”SELECT * FROM dept
WHERE deptno=”+deptnoTF.getText()+”;”;
rs = stmt.executeQuery(query);
if (rs.next()){ String dno = .getString(“deptno”};
String dname =rs.getString(“deptno”);
String lc = rs.getString(“loc” ); dnameTF.setText(dname);
locTF.setText(lc);

updBtn.setEnabled(true); delBtn.setEnabled(true); locTF.setEnabled(true);}

else{JOptionPane.showMessageDialog(null,”No such record Found”):}} Catch(Exception


e){JOptionPane.showMessageDialog(null,””Error in
Connectivity”);
25
For Update Button:
private void updBtnActionPerformed(java.awt.event.ActionEvent evt) int ans
= JOptionPane.showConfirmDialog(null,”Surely wanna update the records?);

if (ans == JOptionPane.YES_OPTION) {

try{stmt = con.createStatement();

String query =”UPDATE dept SET dname=” ”+ dnameTF.getText()+”;”

“loc=” “+locTF.getText()+” WHERE deptno =” ”+deptnoTF.getText()+”;”

stmt.executeUpdate(query);
JOptionPane.showMessageDialog(null,”Record successfully updated”); }

catch (Exception e ){

JOptionPane.showMessageDialog(null,”Error in table updation!”);} deptnoTF.setText(“”); dnameTF.setText(“”);

IocTF.setText(“”);

updBtn.setEnabled(false); delBtn.setEnabled(false);}}

For Delete Button:


private void delBtnActionPerformed(java.awt.event.ActionEvent evt) { int res =

JOptionPane.showConfirmDialog(null,”Surely wanna delete the


records?”);
if ( res == JOptionPane.YES_OPTION){
try(
26
stmt=con.createStatement();
String query =”DELETE FROM dept WHERE deptno=”+deptnoTF.getText0+”;”;
stmt.executeUpdate(query);
JOptionPane.showMessagebialog(null,”Record successfully deleted.”);}
catch (Exception e ){

JOptionPane.showMessageDialog(null,”Error in deletion!”);}
deptnoTF.setText(“”);

dnameTF.setText(“”); locTF.setText(“”);

updBtn.setEnabled(false); del Btn.setEnab led(false);}}

Output :
27

PROGRAM
FOURTEEN-------------------------------------------------------
---------
Aim : To create GUI application that obtains search criteria from user and retrieve data from database.

Design :

Code : For Empty Table Button:

private void emptyBtnActionPerformed(java.awt.event.ActionEvent evt) { DefaultTableModel model = (DefaultTableModel)

empTbl.getModel();

int rows = model.getRowCount();

if(rows>0)
for(int i =0 ; i<rows; i++) { model.removeRow(0);}}

For Search Button:

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

emptyBtn.doClick();
28
Class.forName(“java.sql.Driver”);

Connection con=
DriverManager.getConnection(jdbc:mysql://localhost/test”,”root”,”friends”);
Statement stmt = con.createStatement(); String sfId =
(String)srchFldCBX.getSelectedItem();
String op = (String)opCBX.getSelectedItem(); String crit = criteriaTF.getText();
String query =”SELECT empno,ename,job,hiredate,sal,deptno FROM empl WHERE”+
sfld +” ”+op+””+ crit +”;”; ResultSet rs = stmt.executeQuery(query);
while(rs.next()){ model.addRow(new Object[] {rs.getInt(1), rs.getString(2), rs.getString(3),
rs.getDate(4), rs.getFloat(5), rs.getInt(6)});}
rs.close();
stmt.close();
con.close();} catch(Exception e ){

JOptionPane.showMessagebialog(null ,”ERROR IN CONNECTIVITY”);}


Output :
29

PROGRAM
FIFTEEN----------------------------------------------------------
----------
Aim : Consider the table empl given below and run the following Queries.

Queries:
1. List the details of those employees whose annual salary is between
25000 and 40000.
SELECT * FROM empl where sal BETWEEN 2500 AND 4000;

2. Display the name of employees whose name contains ‘A’ as the 4th alphabet.

SELECT ename FROM empl WHERE ename like ‘ a%’;


30
3. Display Name, Job and Salary of employees who do not have a manager.

SELECT ename, job, sal FROM empl WHERE mgr IS NULL;

4. Display Name, Salary and salary added with commision.

SELECT ename, sal, sal+comm FROM empl;

5. Display details of employees who earn more commission than their salaries.

SELECT * FROM empl WHERE comm>sal;


31

PROGRAM
SIXTEEN----------------------------------------------------------
----------
Aim : Consider the table EMPLOYEE given below and run the following Queries.

Queries:
1. For record with ID=4 update record with last Name, User ID and Salary.

UPDATE employe SET Last_Name=’SAHUKAR’,User_ID=’skar’,Salary=9000 WHERE ID=4;

2. Modify the last name of employees to Gautam where salary<5000.

UPDATE employe SET Last_Name=’Gautam’ WHERE Salary<5000;

3. Add column Email of data type VARCHAR to the table.


ALTER TABLE employe ADD(Email VARCHAR(30));
32
4. Delete the employee record having first name as SIDDHARTH.

DELETE FROM employe WHERE First_Name=’SIDDHARTH’;

5. Modify the salary and increases it by 1000, for all who get salary less than 5000.

UPDATE employe SET Salary =Salary+1000 WHERE Salary<5000;


33

PROGRAM
SEVENTEEN------------------------------------------------------
---------
Aim : Consider the table STUDENT given below and run the following Queries.

Queries:
1. Display Name, Sex, Percentage of the Students.

SELECT name, sex, aggregate/5 AS Percentage FROM student;

2. Display in the following format:


<Student name> obtained <aggregate> marks and has <aggregate/5>
%

SELECT name,”obtained”,aggregate,”marks and has”,aggregate/5,”%” FROM student;


34

3. Display name, age and marks of students whose age is greater than or equal to 14 from student.

SELECT name,age,aggregate FROM student WHERE AGE>=14;

4. Display name, age, aggregate of student whose aggregate is between 300 and 400. Order the query in descending order
of name.

SELECT name, age, aggregate FROM student WHERE aggregate BETWEEN 300 AND 400 ORDER BY name DESC;

5. Alias any column name and use that name in another statement.

SELECT name, aggregate/5 “Percentage Marks” FROM student ORDER BY “Percentage NAME”;
35

PROGRAM
EIGHTEEN--------------------------------------------------------
----------
Aim : Join two Tables.

Queries:
1. Write a query to join two tables empl and dept on the basis of field
deptno.

SELECT * FROM empl,dept WHERE empl.deptno=dept.deptno GROUP BY empno;

2. Remove the duplicate deptno.

SELECT empl.*,dname,loc FROM empl,dept WHERE empl.deptno=dept.deptno;


36

3. Display details like department no, department name, employee number, employee name, job and salary. And order
the rows of by employee number with number.

SELECT empl.deptno, dname, empno, ename, job, sal FROM empl, dept WHERE empl.deptno=dept.deptno GROUP BY empno
ORDER BY empl.deptno, empno;

4. Calculate average salary of all employees listed in table empl.

SELECT AVG(sal) “Average” FROM empl;

5. Display the joining date of senior most employee.

SELECT MIN(hiredate) “Minimum Hire Date” FROM empl;


37

PROGRAM
NINETEEN--------------------------------------------------------
---------
Aim : Join two Tables.
Queries:
1. Write commands to create the above tables with constraints. Delete on
a primary key should be cascaded to its foreign key.

CREATE TABLE employe (empno INTEGER NOT NULL, salary FLOAT, PRIMARY KEY
(empno)) ENGINE=innodb;

CREATE TABLE employer (ID INTEGER NOT NULL, employee_no INTEGER, FOREIGN KEY(employee_no) REFERNCES
employer(empno) ON DELETE CASCADE) ENGINE=innodb;

2. Write a query to create two tables Tt1 and Tt2, such that a column of the table Tt1 is the foreign key referring to table Tt2
(constraint name fk1).

CREATE TABLE Tt1 (A INTEGER NOT NULL PRIMARY KEY, B INTEGER NOT NULL); CREATE TABLE Tt2 (C INTEGER NOT

NULL PRIMARY KEY, D INTEGER NOT NULL);

ALTER TABLE Tt1 ADD CONSTRAINT fk1 FOREIGN KEY (B) REFERENCES Tt2(C) ON DELETE CASCADE;
38
ALTER TABLE Tt1 DROP PRIMARY KEY;

3. Write a query to add primary key to column ename of table empl.

ALTER TABLE empl ADD PRIMARY KEY (ename);

4. In table empl, add a column named THRIFTPALN of datatype NUMBER with a maximum of 7 digits and two decimal places
anda column named LOANCODE of datatype CHAR with a size of one and integrity constraint that checks that loan code
should be one of these: E, C, H, P.
PROGRAM
TWENTY
<HTML>
<TITLE>TABLE</TITLE>
<BODY>
<TABLE BORDER=“2” WIDTH=“20%”>
<TR ALIGN=“CENTER”>
<TD ROWSPAN=‘4” WIDTH=“20%” ALIGN=“CENTER”>
A<BR> C <BR> G </TD>
<TD COLSPAN=“3” ALIGN=“CENTER”> B</TD>
</TR>
<TR>
<TD ALIGN=“CENTER”> D </TD>
<TD ALIGN=“CENTER”> E </TD>
<TD ALIGN=“CENTER” ROWSPAN=“2”> F </TD>
</TR>
<TR>
<TD ALIGN=“CENTER” COLSPAN=“2”> H </TD>
</TR>
</TABLE>
</BODY>
</HTML>

<HTML<
<BODY>
<TABLE BORDER>
</TR>
<TR>
<TD>A</TD> <TD>B<T/TD> <TD>C</TD>
</TR>
<TR>
<TD>D</TD> <TD>E</TD> <TD>F</TD>
</TR> <
</TABLE>
</BODY>
</HTML>
MADE BY- HARSH NAGESH

Вам также может понравиться