Professional Documents
Culture Documents
Acknowledgement
I express my deep gratitude and appreciation to those who agreed to
participate in this project, for their time and courage in sharing their insights
with a fledging student. It is to them I am most indebted, and I can only
hope the product of our collaboration benefits each one as much as I
benefited from the process.
I thank my God for providing me with everything that I required in
completing this project.
I am highly indebted to the Teacher in Charge Mrs. Priyanka Upmanyu for
her guidance and constant supervision as well as for providing necessary
information regarding the assignment & also for her support in completing
the project. Also, I thank Mr.H.P Singh, principal, K.V No.1 AFS for
supporting me in completion of this project.
I would like to express my gratitude towards my parents for their kind cooperation and encouragement which helped me in the completion of this
project.
My thanks and appreciations also go to my classmates in developing the
project and to the people who have willingly helped me out with their
abilities.
ISHTA TRIPATHI
Class XII D (Commerce)
Certificate
This is to certify that Miss Ishta Tripathi of Class XII - D
(Commerce) of Kendriya Vidyalaya had completed her assignment
file under my supervision. She has taken proper care and shown
utmost sincerity in the completion of the project. I certify that this
project is up to my expectations and as per the guidelines issued by
the CBSE.
Declaration
I hereby declare that the assignment file submitted to Department of
Computer Science and Informatics Practices, Kendriya Vidyalaya is
prepared by us. All the coding is a result of only my personal efforts.
ISHTA TRIPATHI
Class XII D (Commerce)
Contents
1.
2.
3.
4.
To display the no. of year, months and days as the input of no. of days
given by the user.
Coding:
privatevoidjButton1ActionPerformed(java.awt.event.ActionEvent
evt){
Stringdays=JOptionPane.showInputDialog("EnterNo.ofDays");
intds=Integer.parseInt(days);
intd=0,m=0,y=0;
y=ds/365;
m=(ds%365)/30;
d=(ds%365)%30;
Stringmsg=""+ds+"daysareequivalentto\n"+y+"years"+m+"
months"+d+"daysapprox.";
JOptionPane.showMessageDialog(null,msg);
Screen Shots:
2)
A simple text editor that offers typing, copy, cut and paste features.
Coding:
privatevoidb1ActionPerformed(java.awt.event.ActionEventevt){
ta.cut();
}
privatevoidb2ActionPerformed(java.awt.event.ActionEventevt){
ta.copy();
}
privatevoidb3ActionPerformed(java.awt.event.ActionEventevt){
ta.paste();
}
Screen Shots:
Figure1Text
Figure2AfterCut
Figure3AfterClickingPaste
3)
Coding:
booleantestPalin(intn){
intn1=n,rev=0;
intdig=0;
while(n1>0){
dig=n1%10;
rev=rev*10+dig;
n1=n1/10;}
if(n==rev)
returntrue;
else
returnfalse;
}
privatevoidb1ActionPerformed(java.awt.event.ActionEventevt){
intnum=Integer.parseInt(tf1.getText());
booleanresult=testPalin(num);
if(result)
l2.setText(num+"isaPalindrome.");
else
l2.setText(num+"isNOTsaPalindrome.");
}
Screen Shots:
4)
Coding:
intpv=20,ps=35,pc=45;
intq;
Stringerror="PleaseenteraValidQuantity.";
privatevoidformWindowGainedFocus(java.awt.event.WindowEventevt){
tf1.setText(pv+"");
tf2.setText(ps+"");
tf3.setText(pc+"");
if(cb1.isSelected()==true)
tf11.setEditable(true);
if(cb2.isSelected()==true)
tf22.setEditable(true);
if(cb3.isSelected()==true)
tf33.setEditable(true);
}
privatevoidb1ActionPerformed(java.awt.event.ActionEventevt){
intq=Integer.parseInt(tf111.getText());
intw=Integer.parseInt(tf222.getText());
inte=Integer.parseInt(tf333.getText());
tf.setText(q+w+e+"");
}
privatevoidb2ActionPerformed(java.awt.event.ActionEventevt){
cb1.setSelected(false);
cb2.setSelected(false);
cb3.setSelected(false);
tf11.setText(0+"");
tf11.setEditable(false);
tf111.setText(0+"");
tf22.setText(0+"");
tf22.setEditable(false);
tf222.setText(0+"");
tf33.setText(0+"");
tf33.setEditable(false);
tf333.setText(0+"");
tf.setText(0+"");
}
privatevoidb3ActionPerformed(java.awt.event.ActionEventevt){
System.exit(0);
}
Screen Shots:
Figure4BasicApplication
Figure5Result
5)
Coding:
privatevoidb1ActionPerformed(java.awt.event.ActionEventevt){
intn,amt,tamt,temp;
n=Integer.parseInt(tf2.getText());
if(rb1.isSelected()==true){
amt=n*200;
tf3.setText(""+amt);}
elseif(rb2.isSelected()==true){
amt=n*150;
tf3.setText(""+amt);}
else{
amt=n*100;
tf3.setText(""+amt);}
temp=Integer.parseInt(tf3.getText());
if(cb.isSelected()==true){
tamt=temp(n*25);
tf3.setText(""+tamt);}
}
privatevoidb2ActionPerformed(java.awt.event.ActionEventevt){
tf1.setText("");
tf2.setText("");
tf3.setText("");
cb.setSelected(false);
type_of_ticket.clearSelection();
}
10
privatevoidb3ActionPerformed(java.awt.event.ActionEventevt){
b2.doClick();
System.exit(0);
}
Screen Shots:
11
6)
Coding:
floatt;
publicfloatCalcSum(floatx,floaty,floatz){
t=x+y+z;
returnt;
}
publicfloatCalcAvg(floatp,floatq,floatr){
t=(p+q+r)/3;
returnt;
}
publicfloatCalcMax(floati,floatj,floatk){
if(i>j)
if(i>k)
returni;
else
returnk;
else
if(j>k)
returnj;
else
returnk;
}
floatdis;
privatevoidbu1ActionPerformed(java.awt.event.ActionEventevt){
floata,b,c;
a=Float.parseFloat(tf1.getText());
b=Float.parseFloat(tf2.getText());
12
c=Float.parseFloat(tf3.getText());
dis=CalcSum(a,b,c);
//MethodCall
ta.append("Sum:"+dis+"\n");
}
privatevoidbu2ActionPerformed(java.awt.event.ActionEventevt){
floata,b,c;
a=Float.parseFloat(tf1.getText());
b=Float.parseFloat(tf2.getText());
c=Float.parseFloat(tf3.getText());
dis=CalcMax(a,b,c);
//MethodCall
ta.append("Average:"+dis+"\n");
}
privatevoidbu3ActionPerformed(java.awt.event.ActionEventevt){
floata,b,c;
a=Float.parseFloat(tf1.getText());
b=Float.parseFloat(tf2.getText());
c=Float.parseFloat(tf3.getText());
dis=CalcMax(a,b,c);
//MethodCall
ta.append("Maximum:"+dis+"\n\n");
}
Screen Shots:
13
7)
Write code for add button to add the text into the textarea ta
depending upon the selection made by the user.
Coding:
privatevoidb1ActionPerformed(java.awt.event.ActionEventevt){
if(rb1.isSelected()==true)
ta1.append("Male"+'\t');
elseif(rb2.isSelected()==true)
ta1.append("Female"+'\t');
elseif(rb3.isSelected()==true)
ta1.append("Other"+'\t');
else{
JOptionPane.showMessageDialog(null,"PleaseSelectYourGender!");
ta1.append("NotEntered"+'\t');}
Stringage=(String)cb1.getSelectedItem();
inti=0;
intlength=cb1.getItemCount();
booleanexists=false;
for(;i<length;++i){
Stringitem=(String)cb1.getItemAt(i);
if(item.equals(age)){
exists=true;
break;}
}
if(exists==false)
cb1.addItem(age);
ta1.append(""+age+'\t');
Stringc=(String)(jl1.getSelectedValue());
ta1.append(""+c+'\n');
}
privatevoidb2ActionPerformed(java.awt.event.ActionEventevt){
14
gender.clearSelection();
cb1.setSelectedIndex(1);
jl1.clearSelection();
ta1.setText("");
}
Screen Shots:
15
8)
Coding:
privatevoidpfActionPerformed(java.awt.event.ActionEventevt){
b1.doClick(0);
}
privatevoidb1ActionPerformed(java.awt.event.ActionEventevt){
Stringpd,name;
name=tf.getText();
pd=newString(pf.getPassword());
if(pd.equals("student")){
tp1.setText("WelcomeBack"+name+","+'\n'+"Youhaveloggedin
successfully.");
b2.setText("Proceed");
d1.setVisible(true);}
else{
JOptionPane.showMessageDialog(null,"WrongPassword"+'\n'+"Try
Again");
pf.setText("");}
}
privatevoidb2ActionPerformed(java.awt.event.ActionEventevt){
System.exit(0);
}
Screen Shots:
16
9)
Coding:
privatevoidb1ActionPerformed(java.awt.event.ActionEventevt){
Floata,b,c;
a=Float.parseFloat(tf1.getText());
b=Float.parseFloat(tf2.getText());
c=b;
b=a;
a=c;
tf1.setText(""+a);
tf2.setText(""+b);
}
privatevoidb2ActionPerformed(java.awt.event.ActionEventevt){
tf1.setText("");
tf2.setText("");
}
privatevoidb3ActionPerformed(java.awt.event.ActionEventevt){
System.exit(0);
}
Screen Shots:
17
10)
Coding:
privatevoidb1ActionPerformed(java.awt.event.ActionEventevt){
floatper;
per=Float.parseFloat(tf2.getText());
if(cb.isSelected()==false)
tf3.setText(""+per);
else
tf3.setText(""+(per+5));
}
privatevoidb2ActionPerformed(java.awt.event.ActionEventevt){
b1.doClick();
floatper=Float.parseFloat(tf3.getText());
if(rb1.isSelected()==true){
if(per>=70)
tf4.setText("Eligible!");
else
tf4.setText("NotEligible");}
elseif(rb2.isSelected()==true){
if(per>=60)
tf4.setText("Eligible!");
else
tf4.setText("NotEligible");}
elseif(rb3.isSelected()==true){
if(per>=40)
tf4.setText("Eligible!");
18
else
tf4.setText("NotEligible");}
else
JOptionPane.showMessageDialog(null,"PleaseSelectASubject.");
}
privatevoidb3ActionPerformed(java.awt.event.ActionEventevt){
group.clearSelection();
cb.setSelected(false);
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
}
privatevoidb4ActionPerformed(java.awt.event.ActionEventevt){
System.exit(0);
}
Screen Shots:
19
11)
Design an application that has some controls and a list displaying colors.
When a user selects a color from the list the background of the controls
selected should be changed.
Coding:
privatevoidlist1ValueChanged(javax.swing.event.ListSelectionEventevt){
inti;
Colorx=Color.white;
i=list1.getSelectedIndex();
switch(i){
case0:x=Color.RED;
break;
case1:x=Color.BLUE;
break;
case2:x=Color.GREEN;
break;
case3:x=Color.MAGENTA;
break;
case4:x=Color.CYAN;
break;
case5:x=Color.YELLOW;
break;
case6:x=Color.GRAY;
break;
default:x=Color.WHITE;
}
if(lblcb.isSelected()==true)
lbl.setBackground(x);
else
20
lbl.setBackground(Color.WHITE);
if(bcb.isSelected()==true)
b.setBackground(x);
else
b.setBackground(Color.WHITE);
if(tfcb.isSelected()==true)
tf.setBackground(x);
else
tf.setBackground(Color.WHITE);
}
Screen Shots:
21
12)
Design an application which shows all the odd numbers from 1 to the
number given as input.
Coding:
privatevoidjButton1ActionPerformed(java.awt.event.ActionEventevt){
ta.setText(null);
intn=Integer.parseInt(tf1.getText());
inti=1;
for(;i<=n;i=i+2){
Stringtxt=ta.getText();
ta.setText(txt+""+i);
}
}
Screen Shots:
22
MySQL queries
Table Student
1. Displaying whole table
2. Displaying name and sex of student who are more than 12 years and
are male.
23
4. Displaying the count of the students who scored more than 50%
5. Displaying names, marks and sex of students in the order where the
top scorer is first.
24
Table Pet
8. Displaying all information about pets whose species is either bird /
snake / hamster
11. Displaying name and sex of all the animals born before or on 0101-1995
25
Table Empl
12. Displaying names and job of employees who earn more
commission than salaries
14. Displaying names, job and salary of employees who dont have a
manager
15. Displaying all information about employees who dont earn any
commission
26
Table Dept
19. Add a column country which cannot be null and by default its
value should be India
27
28
Coding:
importjava.sql.*;
importjavax.swing.table.DefaultTableModel;
importjavax.swing.JOptionPane;
Connectionc;
Statements;
ResultSetrs;
privatevoidb1ActionPerformed(java.awt.event.ActionEventevt){
DefaultTableModelmodel=(DefaultTableModel)empl.getModel();
try{
Class.forName("java.sql.Driver");
c=DriverManager.getConnection("jdbc:mysql://localhost/con","root","");
s=c.createStatement();
rs=s.executeQuery("Select*fromempl;");
while(rs.next()){
inteno=rs.getInt("empno");
Stringena=rs.getString("ename");
Stringj=rs.getString("job");
intmgr=rs.getInt("mgr");
Stringhd=rs.getString("hiredate");
floatsal=rs.getFloat("sal");
floatcom=rs.getFloat("comm");
intdeptno=rs.getInt("deptno");
model.addRow(newObject[]{eno,ena,j,mgr,hd,sal,com,deptno});
}
rs.close();
29
s.close();
c.close();
}
catch(Exceptions){
JOptionPane.showMessageDialog(null,"ErrorInConnectivity");
}
}
privatevoidb2ActionPerformed(java.awt.event.ActionEventevt){
DefaultTableModelmodel=(DefaultTableModel)empl.getModel();
introw=model.getRowCount();
if(row>0){
for(inti=0;i<row;i++){
model.removeRow(0);
}
}
}
privatevoidb3ActionPerformed(java.awt.event.ActionEventevt){
System.exit(0);
}
30
Screen Shots:
31
Coding:
importjava.sql.*;
importjavax.swing.table.DefaultTableModel;
importjavax.swing.JOptionPane;
Connectionc;Statements;ResultSetr;
privatevoidb1ActionPerformed(java.awt.event.ActionEventevt){
DefaultTableModelmodel=(DefaultTableModel)empl.getModel();
introws=model.getRowCount();
if(rows>0){
for(inti=0;i<rows;i++){
model.removeRow(0);
}
}
}
privatevoidb2ActionPerformed(java.awt.event.ActionEventevt){
b1.doClick(0);
DefaultTableModeltbprp=(DefaultTableModel)empl.getModel(){
try{
Class.forName("java.sql.Driver");
c=
DriverManager.getConnection("jdbc:mysql://localhost/con","root","");
s=c.createStatement();
Stringfld=(String)cb1.getSelectedItem();
Stringop=(String)cb2.getSelectedItem();
Stringcrit=tf.getText();
Stringquery="selectempno,ename,job,hiredate,sal,deptnofromempl
where"+fld+""+op+"\""+crit+"\""+";";
r=s.executeQuery(query);
32
while(r.next()){
intl=r.getInt("empno");
Stringm=r.getString("ename");
Stringn=r.getString("job");
Stringo=r.getString("hiredate");
floatp=r.getFloat("sal");
intq=r.getInt("deptno");
tbprp.addRow(newObject[]{l,m,n,o,p,q});
}
r.close();
s.close();
c.close();
}
catch(Exceptionf){
JOptionPane.showMessageDialog(null,"ErrorinConnectivity!!");
}
}
privatevoidb3ActionPerformed(java.awt.event.ActionEventevt){
b1.doClick(0);
System.exit(0);
}
33
Screen Shots:
34
Html pages
1) Logical and Physical Text Styles
Source
<html>
<head><title>Chapter10Example10.16(PageNo289)</title></head>
<body>
<center><h1>LogicalAndPhysicalTextStyles</h1></center><br>
<p>LogicalStyles</p>
35
DFNtag<dfn>HTMLisafomattinglanguageforwebpages.</dfn><br>
CITEtag<cite>Newsweek</cite><br>
CODEtag<code>printf("Thevalueofnis%d/n",n)</code><br>
SAMPtag<samp>(Abort,Retry,Fail)?</samp><br>
VARtag<var>username</var><br>
EMtag<em>EspeciallytheRedhead.</em><br>
KBDtag<kbd>Username,host</kbd><br>
STRONGtag<strong>Youcannotbeserious!!</strong><br>
<p>PhysicalTags</p>
<b>Boldface(donewith'b'tag)lookslikethisonyourmachine.</b></br>
<i>Italics(donewith'i'tag)appearslikethis.</i><br>
<tt>Typewriter(donewith'tt'tag)textusesafixedwidthfont.</tt><br>
<b><i>Combinationof'i'&'b'tags.</i><b>
</body>
</html>
36
2) Hyperlinks
37
Source
<html>
<head><title></title></head>
<bodybgcolor="aqua">
<fontface="Jokerman"size=40>
<marqueebgcolor="orange"behaviour="alternate"
scrollamount="10">Hello!!</marquee><hr>
<center>WelcometoyourfirstHTMLpage.</center>
<pre>1
22
22
</pre></font>
<fontface="chiller"size="20"><ahref="E:\PROGRAMMING\HTMLFiles\Activity1
(God.html).html">Visitanotherhtmldocument</a></font>
</body>
</html>
@@Mg{x Xw M@@
38