Sei sulla pagina 1di 65

C OMP U T E R N E T W OR K I N G

Q1. Find the IP addresses of at least five computers in your school.

Ans:

 172.16.6.119

 172.16.6.109

 172.46.6.118

 172.60.6.019

 172.16.6.129

Q2. Find the IP address of your school's web site.


Ans: 212.1.210.225

Q3. Find the name of Internet Service Provider of your school.


Ans: Connect

Q4. Find the MAC addresses of at least 2 computers in your lab. Then verify their
manufacturer's name on the net.
Ans: 1) 00:ec:0a:3c:76:ab 2) 00:ec:0a:5c:76:ac

Q5. Find the layout of LAN in your school's labs. If you think some modifications can be
done in the layout, note these down in your notebook.

Ans:

Star Topology
OP E N S OU R C E C ON C E P T S
Q1. Find out which software in your school lab are open sorce.
Ans:
 Open Office
 Google Chrome
 MySQL
 NetBeans

Q2. Note down the category of software (system software or application software)
to which they belong to.
Ans:
System Software:
 Linux
 Ubuntu
 Windows
 Fedora
Application Software:
 OpenOffice
 MySQL
 Net Beans
 Google Chrome

Q3. If any of them is application software then specify its area of application.
Ans:
 NetBeans : It helps in creation of programs
 MySQL : It helps in creation and management of databases
 OpenOffice : It is a software that provides us a platform to write an format text
to make it look presentable
 Chrome : It is a web browser which gives us the ability to search information on
internet.
Q4. Search on internet about the features of mySQL and Netbeans.
Ans:
 Features Of MySql:
 Released under open source and available free of cost.
 Easy to learn and use.
 Provides portability.
 High Security.
 Provides many data types.
 Handles large database.
 Supports standards based SQL.
 Fast processing speed and easy in installation.
 Occupy very less space.

 Features Of Netbeans :
 NetBeans editor detects errors while you type and assists you with
documentation popups and smart code completion and it indents lines, matches
words and brackets, and highlights source code syntactically and semantically.
 NetBeans IDE is a free and open source.
 The NetBeans Profiler provides expert assistance for optimizing your
application's speed and memory usage, and makes it easier to build reliable
applications.
 Smoother startup and faster project scanning.
G U I P R O G R A M M IN G - A R E V IE W
Q1. Design a GUI application in which the user enters a number in the text field and
on clicking the button the sum of the digits of the number should be displayed in a
label. Hint: Suppose user enters 123 the output should be 6(1+2+3)
Ans: String a = jTextField1.getText();
int x =0; int y=0;
for(int i = 0; i <a.length(); i++)
{
x = Integer.parseInt(a.substring(i,i+1));
y= x+y;
}
jTextField2.setText(""+y);

Q2. Design a GUI application to accept a String from the user in a text field and print
using option pane whether it is a palindrome or not. Hint ABBA is a palindrome.
Ans:
String x = jTextField1.getText();
String reverse="";
for(int i=0; i<x.length(); i++)
{
reverse= x.substring(i,i+1)+reverse;
}
if (x.equals(reverse) )
{ JOptionPane.showMessageDialog(this,"palindrome"); }
else
{ JOptionPane.showMessageDialog(this,"Not a Palindrome"); }
Q3. Design a GUI application to accept the cost price and selling price form the user
in two text fields then calculate the profit or loss incurred.
Ans:
int a = Integer.parseInt(jTextField1.getText());
int b = Integer.parseInt(jTextField2.getText());
int c = b-a;
if(c>0)
{
jTextField3.setText("Profit :"+c);
}
else if (c==0)
{
jTextField3.setText("No Profit no loss");
}
else
{
jTextField3.setText("Loss :"+c*(-1));
}

Q4. Design a GUI application to accept a character in a text field and print in a label if
that character is a vowel: a, e, i, o, or u. The application should be case sensitive.
Ans:
private void formWindowOpened(java.awt.event.WindowEvent evt) {
jTextField2.setText("0");
jTextField3.setText("0");
jTextField4.setText("0");
jTextField5.setText("0");
jTextField6.setText("0");
}

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


String y= jTextField1.getText();
int a=0,e=0, i=0, o=0, u=0;
int x= y.length();
for(int t=0; t<x; t++)
{ String w= y.substring(t,t+1);
if (w.equals("a")|| w.equals("A"))
{a=a+1;
jRadioButton1.setSelected(true);
jTextField2.setText(Integer.toString(a));}
else if (w.equals("e")|| w.equals("E"))
{e=e+1;
jRadioButton2.setSelected(true);
jTextField3.setText(Integer.toString(e));}
else if (w.equals("i")|| w.equals("I"))
{i=i+1;
jRadioButton3.setSelected(true);
jTextField4.setText(Integer.toString(i));}
else if (w.equals("o")|| w.equals("O"))
{o=o+1;
jRadioButton4.setSelected(true);
jTextField5.setText(Integer.toString(o));}
else if (w.equals("u")|| w.equals("U"))
{u=u+1;
jRadioButton5.setSelected(true);
jTextField6.setText(Integer.toString(u));}
}
}
private void RESETActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jRadioButton1.setSelected(false);
jRadioButton2.setSelected(false);
jRadioButton3.setSelected(false);
jRadioButton4.setSelected(false);
jRadioButton5.setSelected(false);
}

Q5. Design a GUI application that repeatedly accepts numbers in an option pane and
once the typed number is 0 the maximum and minimum of all numbers typed are
displayed.
Ans:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
String no;
int b=0;
int s=0;
int n=0;
do
{
no= JOptionPane.showInputDialog("Enter your Numbers");
n= Integer.parseInt(no);
if(n>b)
{b=n;}
else if(n<s)
{s=n;}
}
while (n!=0);
j1.setText(b+"");
j2.setText(s+"");
}
Q6. Design a GUI application in java to convert temperature from Celsius to
Fahrenheit or vice versa using radio buttons and two text fields.
Ans:

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


jTextField1.setText(jTextField1.getText()+"9"); }
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"8"); }
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"7"); }
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"6"); }
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"5"); }
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"4"); }
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"3"); }
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"2");
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"1");
}
private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+".");
jButton13.setEnabled(false);
}
private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"0");
}
private void FActionPerformed(java.awt.event.ActionEvent evt) {
C.setSelected(false);
double num= Double.parseDouble(jTextField1.getText());
jTextField2.setText(""+(((num*9)/5)+32));
jLabel4.setText("°F");
jLabel5.setText("°C");
}
private void CActionPerformed(java.awt.event.ActionEvent evt) {
F.setSelected(false);
double num= Double.parseDouble(jTextField1.getText());
jTextField2.setText(""+((num-32)*5)/9);
jLabel4.setText("°C");
jLabel5.setText("°F");
}
private void BackspaceActionPerformed(java.awt.event.ActionEvent evt) {
int x= jTextField1.getText().length();
String m= jTextField1.getText().substring(0,x-1);
jTextField1.setText(m);
jTextField2.setText("");
C.setSelected(false);
F.setSelected(false);
jButton13.setEnabled(true);
}
private void ClearAllActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jTextField2.setText("");
jLabel4.setText("");
jLabel5.setText("");
C.setSelected(false);
F.setSelected(false);
jButton13.setEnabled(true);
}
Q7. Design a GUI application in java to convert kilograms into grams, litres into
millilitres, rupees into paisa using combo box and text fields.
Ans:
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"9"); }
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"8"); }
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"7"); }
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"6"); }
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"5"); }
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"4"); }
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"3"); }
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"2"); }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"1"); }
private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+".");
jButton13.setEnabled(false); }
private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(jTextField1.getText()+"0"); }
private void BackspaceActionPerformed(java.awt.event.ActionEvent evt) {
int x= jTextField1.getText().length();
String m= jTextField1.getText().substring(0,x-1);
jTextField1.setText(m);
jTextField2.setText("");
jButton13.setEnabled(true);
}
private void ClearAllActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jTextField2.setText("");
jLabel4.setText("");
jLabel5.setText("");
jButton13.setEnabled(true);
}
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
double a = Double.parseDouble(jTextField1.getText());
double b;
switch(jComboBox1.getSelectedIndex())
{ case 0:{ b = a*1000;
jLabel4.setText("G");
jLabel5.setText("Kg");
jTextField2.setText(""+b);
break; }
case 1:{ b = a*1000;
jLabel4.setText("ML");
jLabel5.setText("L");
jTextField2.setText(""+b);
break; }
case 2:{ b = a*100;
jLabel4.setText("p");
jLabel5.setText("Rs");
jTextField2.setText(""+b);
break; }
default:{JOptionPane.showMessageDialog(this,"Select any conversion!");
break; }
}
}
B as i c s o f OBJ E C T OR I E N T E D
PROGRAMMING
Q1. Create a GUI application to accept a string and display it in reverse order using
the substring() method.
Ans:
String x =jTextField1.getText();
String reverse="";
for(int i=0; i<x.length();i++)
{
reverse=x.substring(i,i+1)+reverse;
}
JOptionPane.showMessageDialog(this,reverse);

Q2. Create a GUI application to create random whole numbers between 2 float
numbers input by the user.
Ans:
float a =Integer.parseInt(jTextField1.getText());
float b =Integer.parseInt(jTextField2.getText());
float r=0;
if (a>b)
{r=(float)Math.random()+a-(float)Math.random()-b;
JOptionPane.showMessageDialog(this,r);}

else if (b>a)
{r=(float)Math.random()+b-(float)Math.random()-a;
JOptionPane.showMessageDialog(this,r);}
else if (a==b)
{ JOptionPane.showMessageDialog(this,"No Possible Value"); }

Q3. Create a GUI application to accept 3 numbers in separate text fields and display
their sum, average, maximum or minimum after rounding the results on the click of
appropriate buttons (There are four separate buttons - one for sum, one for average,
one for maximum and one for minimum). The result should be displayed in the
fourth text field.
Ans:
private void SUMActionPerformed(java.awt.event.ActionEvent evt) {
double a = Double.parseDouble(jTextField1.getText());
double b = Double.parseDouble(jTextField2.getText());
double c = Double.parseDouble(jTextField3.getText());
double sum,sum1;
sum = a + b + c;
sum1= Math.round(sum);
jTextField4.setText(Double.toString(sum1));
}
private void AVERAGEActionPerformed(java.awt.event.ActionEvent evt) {
double a = Double.parseDouble(jTextField1.getText());
double b = Double.parseDouble(jTextField2.getText());
double c = Double.parseDouble(jTextField3.getText());
double Average,Average1;
Average = (a+b+c)/3;
Average1= Math.round(Average);
jTextField4.setText(Double.toString(Average1));
}
private void MAXActionPerformed(java.awt.event.ActionEvent evt) {
double a = Math.round(Double.parseDouble(jTextField1.getText()));
double b = Math.round(Double.parseDouble(jTextField2.getText()));
double c = Math.round(Double.parseDouble(jTextField3.getText()));
double maximum;
if (a>=b && a>=c){
maximum= a;
jTextField4.setText(Double.toString(a));
}
else if (b>=c && b>=a){
maximum = b;
jTextField4.setText(Double.toString(b)); }
else { maximum = c;
jTextField4.setText(Double.toString(c)); }
}
private void MINIActionPerformed(java.awt.event.ActionEvent evt) {
double a = Math.round(Double.parseDouble(jTextField1.getText()));
double b = Math.round(Double.parseDouble(jTextField2.getText()));
double c = Math.round(Double.parseDouble(jTextField3.getText()));
double minimum;
if (a<=b && a<=c) { minimum = a;
jTextField4.setText(Double.toString(a)); }
else if (b<=c && b<=a) { minimum = b;
jTextField4.setText(Double.toString(b)); }
else { minimum = c;
jTextField4.setText(Double.toString(c)); }
}
private void RESETActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(""); jTextField2.setText("");
jTextField3.setText(""); jTextField4.setText(""); }
Q4. Create a GUI application to accept the date (as 1), month (as a number like 3 for
March) and year (as 2010) in separate text fields and display the date in the format:
dd/mm/yy. Take care of the following points while creating the application:
 Verify the date input before displaying it in the suggested format and display
error messages wherever applicable
 The date is accepted as 1 (for the first of any month) but should be displayed
as 01 in the final format.
 The year is accepted as 2010 but displayed as 10 in the final format.
Ans:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String date= DATE.getText();
String month= MONTH.getText();
String year= YEAR.getText();

int a= Integer.parseInt(date);
int b= Integer.parseInt(month);
int c= Integer.parseInt(year);

int d= date.length();
int m= month.length();
int y= year.length();

if( (a==1||a==2||a==3||a==4||a==5||a==6||a==7||a==8||a==9||a==10||
a==11||a==12||a==13||a==14||a==15||a==16||a==17||a==18||a==19||a==20||
a==21||a==22||a==23||a==24||a==25||a==26||a==27||a==28||a==29||a==30||
a==31) && (b==1||b==3||b==5||b==7||b==8||b==10||b==12) )
{ if(d==1)
{ String dd=0+date;
if(m==1)
{ String mm=0+month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f);
}
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m==2)
{ String mm=month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f);
}
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m<1||m>2)
{JOptionPane.showMessageDialog(null,"Invalid month!");}
}
else if(d==2)
{ String dd= date;
if(m==1)
{ String mm=0+month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f); }
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m==2)
{ String mm=month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f);
}
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m<1||m>2)
{JOptionPane.showMessageDialog(null,"Invalid month!");}
}
else
{JOptionPane.showMessageDialog(null,"Invalid date!");}
}
else if((a==1||a==2||a==3||a==4||a==5||a==6||a==7||a==8||a==9||a==10||
a==11||a==12||a==13||a==14||a==15||a==16||a==17||a==18||a==19||a==20||
a==21||a==22||a==23||a==24||a==25||a==26||a==27||a==28||a==29||a==30)&&
(b==4||b==6||b==9||b==11))
{ if(d==1)
{ String dd=0+date;
if(m==1)
{ String mm=0+month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f);
}
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m==2)
{ String mm=month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f);
}
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m<1||m>2)
{JOptionPane.showMessageDialog(null,"Invalid month!");}
}
else if(d==2)
{ String dd= date;
if(m==1)
{ String mm=0+month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f); }
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m==2)
{ String mm=month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f);
}
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m<1||m>2)
{JOptionPane.showMessageDialog(null,"Invalid month!");}
}
else
{JOptionPane.showMessageDialog(null,"Invalid date!");}
}
else if((b==2)&&(c%4==0))
{ if(a==1||a==2||a==3||a==4||a==5||a==6||a==7||a==8||a==9||a==10||
a==11||a==12||a==13||a==14||a==15||a==16||a==17||a==18||a==19||
a==20||a==21||a==22||a==23||a==24||a==25||a==26||a==27||a==28||a==29)
{ if(d==1)
{ String dd=0+date;
if(m==1)
{ String mm=0+month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f); }
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m==2)
{ String mm=month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f);
}
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m<1||m>2)
{JOptionPane.showMessageDialog(null,"Invalid month!");}
}
else if(d==2)
{ String dd= date;
if(m==1)
{ String mm=0+month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f); }
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m==2)
{ String mm=month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f);
}
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m<1||m>2)
{JOptionPane.showMessageDialog(null,"Invalid month!");}
}
else
{JOptionPane.showMessageDialog(null,"Invalid date!");}
}
else
{JOptionPane.showMessageDialog(null,"Error!");}
}
else if((b==2)&&(c%4!=0))
{
if(a==1||a==2||a==3||a==4||a==5||a==6||a==7||a==8||a==9||a==10||
a==11||a==12||a==13||a==14||a==15||a==16||a==17||a==18||a==19||
a==20||a==21||a==22||a==23||a==24||a==25||a==26||a==27||a==28)
{ if(d==1)
{ String dd=0+date;
if(m==1)
{ String mm=0+month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f);
}
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m==2)
{ String mm=month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f); }
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m<1||m>2)
{JOptionPane.showMessageDialog(null,"Invalid month!");}
}
else if(d==2)
{ String dd= date;
if(m==1)
{ String mm=0+month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f);
}
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m==2)
{ String mm=month;
if(y==4)
{ String yy=year.substring(2);
String f=dd+"-"+mm+"-"+yy;
FINAL.setText(f);
}
else if(y>4||y<4)
{JOptionPane.showMessageDialog(null,"Invalid year!");}
}
else if(m<1||m>2)
{JOptionPane.showMessageDialog(null,"Invalid month!");}
}
else
{JOptionPane.showMessageDialog(null,"Invalid date!");}
}
else
{JOptionPane.showMessageDialog(null,"Error!");}
}
else
{JOptionPane.showMessageDialog(null,"Error!");}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
DATE.setText("");
MONTH.setText("");
YEAR.setText("");
FINAL.setText("");
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}

OUTPUT:
A D V A N C E D PR O G R A M MI N G C O N C E PT S
Q1. Create an application to accept two strings – First Name and Last Name from the
user and display the message Welcome with the complete name of the user.
Ans:

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


String first = jTextField1.getText();
String last = jTextField2.getText();
String msg = first+" "+last;
JOptionPane.showMessageDialog(null,"Welcome"+" "+msg);
}

Q2. Create an application to accept the radius of a circle, calculate the area and
circumference and display the results in a message box after rounding off the area
and circumference to an Integer number.
Ans :
private void AActionPerformed(java.awt.event.ActionEvent evt) {
int r = Integer.parseInt(jTextField3.getText());
double A = Math.round(3.141592653589793)*r*r;
JOptionPane.showMessageDialog(this,"Area= "+A);
}
private void CActionPerformed(java.awt.event.ActionEvent evt) {
int r = Integer.parseInt(jTextField3.getText());
double C = 2*Math.round(3.141592653589793)*r;
JOptionPane.showMessageDialog(this,"Circumference= "+C);
}
Q3. Modify application to make sure that the user has not input the complete name
in the first name text field.
Ans:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String first = jTextField1.getText();
String last = jTextField2.getText();
String msg = first+" "+last;
if (first.equals("")||last.equals(""))
{JOptionPane.showMessageDialog(null,"Fill the details properly!");}
else
{JOptionPane.showMessageDialog(null,"Welcome"+" "+msg);}
}
Q4. Modify the Case changer application developed in lesson to display the input
text in title case using the substring (), toLowerCase() and toUpperCase() methods
Ans :
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String a= jTextField1.getText();
String l= a.toLowerCase();
String u= a.toUpperCase();
jTextField2.setText(u);
jTextField3.setText(l);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}
MySQL - REVISION TOUR
Consider a database LOANS with the following table:

Table: Loan_Accounts
AccNo Cust_Name Loan_Amount Instalments Int_Rate Start_Date Interest
1 R.K. Gupta 300000 36 12.00 19-07-2009
2 S.P. Sharma 500000 48 10.00 22-03-2008
3 K.P. Jain 300000 36 NULL 08-03-2007
4 M.P. Yadav 800000 60 10.00 06-12-2008
5 S.P. Sinha 200000 36 12.50 03-01-2010
6 P. Sharma 700000 60 12.50 05-06-2008
7 K.S. Dhall 500000 48 NULL 05-03-2008
ANS 1: Create database LOANS;

ANS 2: Use LOANS;

ANS 3: Create table Loan_Accounts(AccNo INT(2), Cust_Name VARCHAR(20),


Loan_Amount INT(7), Instalments INT(2), Int_Rate VARCHAR(5), Start_Date DATE,
Intrest VARCHAR(8));

mysql> Insert into Loan_Accounts values(1,"R.K.


Gupta",300000,36,"12.00","20090719",NULL);
Query OK, 1 row affected (0.30 sec)

mysql> Insert into Loan_Accounts values(2,"S.P.


Sharma",500000,48,"10.00","20080322",NULL);
Query OK, 1 row affected (0.36 sec)
mysql> Insert into Loan_Accounts values(3,"K.P.
Jain",300000,36,NULL,"20070308",NULL);
Query OK, 1 row affected (0.03 sec)

mysql> Insert into Loan_Accounts values(4,"M.P.


Yadav",800000,60,"10.00","20081206",NULL);
Query OK, 1 row affected (0.36 sec)

mysql> Insert into Loan_Accounts values(5,"S.P.


Sinha",200000,36,"12.50","20100103",NULL);
Query OK, 1 row affected (0.06 sec)

mysql> Insert into Loan_Accounts values(6,"P.


Sharma",700000,60,"12.50","20080605",NULL);
Query OK, 1 row affected (0.08 sec)

mysql> Insert into Loan_Accounts values(7,"K.S.


Dhall",500000,48,NULL,"20080305",NULL);
Query OK, 1 row affected (0.36 sec)
ANS 4: Select * from Loan_Accounts;

ANS 5: Select AccNo, Cust_Name, Loan_Amount from Loan_Accounts;

ANS 6: SELECT * FROM LOAN_ACCOUNTS WHERE INSTALMENTS<40;

ANS 7: Select AccNo, Loan_Amount from Loan_Accounts WHERE


Start_Date < "20090401";

ANS 8: Select Int_Rate from Loan_Accounts WHERE Start_Date>"20090401";


ANS 9: Select * from Loan_Accounts WHERE Int_Rate is NULL;

ANS 10: Select * from Loan_Accounts WHERE Int_Rate is not NULL;

ANS 11: select distinct Loan_Amount from Loan_Accounts;

ANS 12: select distinct Instalments from Loan_Accounts;

ANS 13: Select * from Loan_Accounts WHERE Start_Date>"20081231"


AND Instalments>36;

ANS 14: Select Cust_Name, Loan_Amount from Loan_Accounts WHERE Instalments!= 36;
ANS 15: Select Cust_Name, Loan_Amount from Loan_Accounts WHERE
Loan_Amount<500000 OR Int_Rate>12;

ANS 16: Select * from Loan_Accounts WHERE Year(Start_Date)=2009;

ANS 17: Select * from Loan_Accounts WHERE Loan_Amount>=400000 AND


Loan_Amount<=500000;

ANS 18: Select * from Loan_Accounts WHERE Int_Rate BETWEEN 11 AND 12;

ANS 19: Select Cust_Name, Loan_Amount from Loan_Accounts WHERE Instalments


IN(24,36,48);

ANS 20: Select * from Loan_Accounts WHERE Loan_Amount BETWEEN 400000 AND
500000;
ANS 21: SELECT * FROM LOAN_ACCOUNTS WHERE INT_RATE BETWEEN 11 AND 12;

ANS 22: SELECT AccNO, Cust_Name, Loan_Amont from Loan_Accounts WHERE


Cust_Name LIKE ‘%SHARMA’;

ANS 23: Select AccNO, Cust_Name, Loan_Amount from Loan_Accounts WHERE


Cust_Name LIKE "%A";

ANS 24: Select AccNO, Cust_Name, Loan_Amount from Loan_Accounts WHERE


Cust_Name NOT LIKE “%A%”;

ANS 25: Select AccNO, Cust_Name, Loan_Amount from Loan_Accounts WHERE


Cust_Name NOT LIKE “%P%”;

ANS 26: Select AccNO, Cust_Name, Loan_Amount from Loan_Accounts WHERE


Cust_Name LIKE “%A_”;
ANS 27: Select * from Loan_Accounts ORDER BY Loan_Amount;

ANS 28: Select * from Loan_Accounts ORDER BY Start_Date DESC;

ANS 29: Select * from Loan_Accounts ORDER BY Loan_Amount AND Start_Date DESC;

ANS 30: Update Loan_Accounts SET Int_Rate =11.50 WHERE Int_Rate is NULL;

ANS 31: Update Loan_Accounts SET Int_Rate= 0.5 * Int_Rate WHERE


Loan_Amount>400000;
ANS 32: Update Loan_Accounts SET Intrest=(Loan_Amount*Int_Rate*Instalments)*12*100;

ANS 33: Delete from Loan_Accounts WHERE Year(Start_Date)<"2007";

ANS 34: Delete from Loan_Accounts WHERE Cust_Name="K.P. Jain";


ANS 35: Alter table Loan_Accounts ADD Category CHAR(1);

Find the Output of the following queries


ANS 36:
SELECT cust_name, LENGTH(Cust_Name), LCASE(Cust_Name), UCASE(Cust_Name)
FROM Loan_Accounts WHERE Int_Rate < 11.00;

ANS 37:
SELECT LEFT(Cust_Name, 3), Right(Cust_Name, 3), SUBSTR(Cust_Name, 1, 3) FROM
Loan_Accounts WHERE Int_Rate > 10.00;
ANS 38:
SELECT RIGHT(Cust_Name, 3), SUBSTR(Cust_Name, 5) FROM Loan_Accounts;

ANS 39:
SELECT DAYNAME(Start_Date) FROM Loan_Accounts;

ANS 40:
SELECT ROUND(Int_Rate*110/100, 2) FROM Loan_Account WHERE Int_Rate > 10;

Write the output produced by the following SQL


commands:
ANS 41:
SELECT POW(4,3), POW(3,4);
ANS 42:
SELECT ROUND(543.5694,2), ROUND(543.5694), ROUND(543.5694,-1);

ANS 43:
SELECT TRUNCATE(543.5694,2), TRUNCATE(543.5694,-1);

ANS 44:
SELECT LENGTH("Prof. M. L. Sharma");

ANS 45:
SELECT CONCAT("SHEIKH", " HAROON") "FULL NAME";

ANS 46:
SELECT YEAR(CURDATE()), MONTH(CURDATE()), DAY(CURDATE());

ANS 47:
SELECT DAYOFYEAR(CURDATE()), DAYOFMONTH(CURDATE()), DAYNAME(CURDATE());
ANS 48:
SELECT LEFT("Unicode",3), RIGHT("Unicode",4);

ANS 49:
SELECT INSTR("UNICODE","CO"), INSTR("UNICODE","CD");

ANS 50:
SELECT MID("Informatics",3,4), SUBSTR("Practices",3);
W E B A P P L I C A T I ON S
Q1. Write HTML code to display the following web pages:
a.

<HTML>
<HEAD>
<TITEL></TITEL>
</HEAD>
<BODY>
<CENTER><IMG SRC="D:\New Assignment folder\download.jpg" HEIGHT="170" WIDTH=
"180"
BORDER=0 ALIGN="cc"
WIDTH=100 HEIGHT=100></CENTER><P></P>
<FONT FACE="Times New Roman">
<CENTER><FONT SIZE="6"<b>Welcome to the website of Manchester Football
Cub</FONT>
</b></CENTER>
<P>The Manchester Football Club is based in United States of America and has a long and
proud history.
We have several teams in various age groups from kids to grownups so there is a team to
suit any player. </P>
<P> <P>
<U>This year's motto:</U></P>
<P>We are the <I>BEST;</I></P>
<hr size=2 width=80% color="BLACK"><CENTER>
<P><font color="Red">If you have any questions about us, send us a mail at
manr@football.net.usa</P>
<P ALIGN="Right">ManchesterFootballClub. Last Updated 30th July 2010</P>
</FONT>
</BODY>
</HTML>

b.

<HTML>
<HEAD>
<TITEL></TITEL>
</HEAD>
<BODY>
<FONT FACE="Times New Roman" SIZE="10"> <CENTER>
<TABLE BORDER="1" CELLSPACING="0">
<TR>
<TH colspan="2"><ALIGN="cc"><font color="Red">Fresh Fruits</FONT></TH>
</TR>
<TR>
<TH>Fresh Fruits helps us stay healthy and fit. <P></P>
<P lang="hi">फफ फफफफ फफ फफफ फफफफफफफ फफ</P></TH>
<TH><IMG SRC="D:\walpaprs\fruit basket.jpg" HEIGHT="190" WIDTH="200"</TH>
</TR>
</FONT> </CENTER>
</BODY>
</HTML>
c.

<HTML>
<HEAD>
<TITEL></TITEL>
</HEAD>
<BODY>
<FONT FACE="Times New Roman" SIZE="6">
<OL start = 1>
<LI> INDIA </LI>
<OL START = 1 TYPE = a>
<LI> HARYANA </LI>
</FONT>
<UL TYPE=rectangle>
<FONT FACE="Times New Roman" SIZE="5">
<LI> Gurgaon </LI>
<LI>Faridabad</LI>
</FONT>
</UL>
<FONT FACE="Times New Roman" SIZE="6">
<LI> J&K </LI>
</FONT>
<UL TYPE=rectangle>
<FONT FACE="Times New Roman" SIZE="5">
<LI>Jammu</LI>
<LI>Srinagar</LI>
</FONT>
</UL>
</OL>
</BODY>
</HTML>
Q2. Write the HTML code to generate the following result:
a.

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
ONE 1 2 3
</BODY>
</HTML>

b.

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
TWO
<OL TYPE=i START =2
<LI><P><P></LI>
<LI>ONE</LI>
<LI>TWO</LI>
<LI>THREE</LI>
</OL>
</BODY>
</HTML>
c.

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<FONT Size=5>
<OL TYPE=1 START =1>
<LI>Seek expert advice about the area</LI>
<UL TYPE=DISC>
<LI> Get the best maps. On the map select</LI>
<UL TYPE=DISC>
<LI>landmarks</LI>
<LI>mountains</LI>
<LI>lakes</LI>
</UL>
<LI>Get a good compass and</LI>
<UL TYPE=DISC>
<LI>check slope of land</LI>
<LI>check direction of flowing streams</LI>
</UL>
</UL>
<LI>If there is snow on the ground, stay close to:</LI>
<UL TYPE=DISC>
<LI>roads</LI>
<LI>trails and</LI>
<LI>waterways</LI>
</UL>
</OL>
</BODY>
</HTML>
d.

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<FONT Size=5>
Things we learned in kindergarten:
<OL TYPE=1 START =1
<LI><P><P></LI>
<LI>share</LI>
<LI>play fair</LI>
<LI>don't hit people</LI>
<LI>put things back where we found them</LI>
<LI>say sorry when we hurt somebody</LI>
</OL>
</FONT>
</BODY>
</HTML>

Q3. Give the output for the following:


a.
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<H1>The following is a list of a few chemicals: </H1>
<UL TYPE=disc>
<LI>Sodium</LI>
<LI>Sulphur</LI>
<LI>Magnesium</LI>
</UL>
</BODY>
</HTML>

Output:

b.
<HTML>
<HEAD><TITLE>SCHEDULE</TITLE></HEAD>
<BODY>
<TABLE BORDER="3">
<CAPTION>VOLUNTEER SCHEDULE</CAPTION>
<TR BGCOLOR="#AAFFCC">
<TH>9 A.M.</TH> <TH>12 P.M.</TH> <TH>2 P.M.</TH>
</TR>
<TR>
<TD>Anmol </TD> <TD>Abhinav </TD> <TD>Anika </TD>
</TR>
<TR>
<TD>Riti </TD> <TD>Riya </TD> <TD>Sara </TD>
</TR>
<TR>
<TD>Gul </TD> <TD>Reyana </TD> <TD>Swayam </TD>
</TR>
</TABLE>
</BODY>
</HTML>

Output:
A D VA N C E D R D B M S CO N C E P TS
Q1. Perform the following tasks:

A) Start MySQL session .

Create a table named Student with columns RollNumber, Name and Marks.

Start a transaction and insert two rows to the Student table.

Verify the inserts by SELECT statement.

Commit the changes.

Start another transaction.


Delete a row that was recently inserted.

Verify that the row has been deleted.

Rollback the changes.

Verify that the delete has been cancelled.

B) A table named ITEM has the following contents:

Write the output that will be displayed by each SELECT statement as the SQL
statements given below are executed:
mysql> SELECT * FROM ITEM;
mysql> SET AUTOCOMMIT = 0;
mysql> INSERT INTO ITEM VALUES(103,'COFFEE TABLE',340);
mysql> SELECT * FROM ITEM;
mysql> ROLLBACK;
mysql> SELECT * FROM ITEM;
mysql> START TRANSACTION;
mysql> UPDATE ITEM SET IPRICE = IPRICE +200;
mysql> SAVEPOINT S1;
mysql> UPDATE ITEM SET IPRICE = IPRICE +400;
mysql> SELECT * FROM ITEM;
mysql> ROLLBACK TO S1;
mysql> SELECT * FROM ITEM;
Now verify the OUTPUT by creating the table using MySQL and executing the above
statements.
C) A table named Bill has the following rows:

Write the output that will be displayed due to last SQL SELECT statement:

mysql> START TRANSACTION;


mysql> INSERT INTO BILLS VALUES(7,'C101','2010-09-02',5000);
mysql> UPDATE BILLS SET Bill_Amt = Bill_Amt+500 WHERE
Order_Num = 3;
mysql> SAVEPOINT A;
mysql> INSERT INTO BILLS VALUES(8,'C97','2010-09-03',4500);
mysql> DELETE FROM BILL WHERE cust_code = 'C105';
mysql> ROLLBACK TO A;
mysql> SELECT * FROM bills;

OUTPUT:
Now verify the output by actually executing the statements.
M O R E O N DA T A BA S E S A N D M Y SQ L

Q1. In a database create the following tables with suitable constraints:

A) Based on these tables write SQL statements for the following


queries:

i. Display the lowest and the highest classes from the table STUDENTS.

SELECT MIN(Class) AS ‘Lowest’, MAX(Class) AS ‘Highest’ FROM STUDENTS;

ii. Display the number of students in each class from the table STUDENTS.

SELECT COUNT(Name) FROM STUDENTS;


iii. Display the number of students in class 10.

SELECT COUNT(Name) FROM STUDENTS WHERE Class=10;


iv. Display details of the students of Cricket team.

SELECT * FROM STUDENTS,SPORTS where STUDENTS.AdmNo=SPORTS.AdmNo AND


Game='Cricket';

v. Display the Admission number, name, class, section, and roll number of
the students whose grade in Sports table is 'A'.

SELECT STUDENTS,AdmNo,Name,Class,Sec,RNo FROM STUDENTS,SPORTS WHERE


STUDENTS.AdmNo=SPORTS.AdmNo AND Grade=’A’;

vi. Display the name and phone number of the students of class 12 who
are play some game.

SELECT Name,Phone FROM STUDENTS,SPORTS WHERE Class=12 AND


STUDENTS.AdmNo=SPORTS.AdmNo AND Game IS NOT NULL;

vii. Display the Number of students with each coach.

SELECT COUNT(*),CoachName FROM SPORTS GROUP BY CoachName;

viii. Display the names and phone numbers of the students whose grade is
'A' and whose coach is Narendra.

SELECT Name,Phone FROM STUDENTS,SPORTS WHERE


STUDENTS.AdmNo=SPORTS.AdmNo AND Grade=’A’ AND CoachName=’Narendra’;

B) Identify the Foreign Keys (if any) of these tables. Justify your
choices.
AdmNo is the foreign key for these tables. This is because, AdmNo is used to link the
two tables and it is a primary key for the table, Sports.
c) Predict the the output of each of the following SQL statements,
and then verify the output by actually entering these statements:
i. SELECT class, sec, count(*) FROM students GROUP BY class, sec;

ii. SELECT Game, COUNT(*) FROM Sports GROUP BY Game;

iii. SELECT game, name, address FROM students, Sports WHERE


students.admno = sports.admno AND grade = 'A';

iv. SELECT Game FROM students, Sports WHERE students.admno =


sports.admno AND Students.AdmNo = 1434;
Q2. In a database create the following tables with suitable constraints:

A) Based on these tables write SQL statements for the following


queries:

i. Display the average rate of a South Indian item.

SELECT AVG(Rate) FROM ITEMS WHERE Category=’South Indian’;

ii. Display the number of items in each category.

SELECT COUNT(Name) FROM ITEMS;

iii. Display the total quantity sold for each item.

SELECT SUM(qty) FROM BILLS;

iv. Display total quantity of each item sold but don't display this data for
the items whose total quantity sold is less than 3.

SELECT SUM(qty) FROM BILLS WHERE qty>3;

v. Display the details of bill records along with Name of each


corresponding item.

SELECT BillNo,Date,I_Code,qty,Name FROM BILLS, ITEMS WHERE


ITEMS.I_Code=BILLS.I_Code;
vi. Display the details of the bill records for which the item is 'Dosa'.

SELECT * FROM BILLS,ITEMS WHERE ITEMS.I_Code=BILLS.I_Code AND


Name LIKE ’%Dosa’;

vii. Display the bill records for each Italian item sold.

SELECT * FROM BILLS,ITEMS WHERE BILLS.I_Code=ITEMS.I_Code AND


Category=’Italian’;

viii. Display the total value of items sold for each bill.

SELECT BillNo,SUM(Rate) FROM ITEMS,BILLS WHERE ITEMS.I_Code=BILLS.I_Code


GROUP BY BillNo;

B) Identify the Foreign Keys (if any) of these tables. Justify your
answer.
I_Code is the foreign key among these tables. This is because, I_Code is used to link
the two tables and it is a primary key for Items table.

C) Answer with justification (Think independently. More than one


answer may be correct. It all depends on your logical thinking):

I. Is it easy to remember the Category of item with a given item code?


Do you find any kind of pattern in the items code? What could be
the item code of another South Indian item?

Yes, it is easy to remember the category of item with a given item code. There is a kind
of pattern in the item codes, South Indian dishes must be in the range from 1000 to
1999, Chinese dishes must be in the range of 2000 to 2999 and Italian food must be in
the range of 3000 to 3999.
The code of another South Indian item could be 1004.

II. What can be the possible uses of Bills table? Can it be used for some
analysis purpose?
The possible uses of BILLS table can be:
1. Maintenance of bill records.
2. Maintenance of sale records.
3. Legal proof.
Yes, it can be used for some analysis purpose also. We can find overtime sales of the
items or a particular item.

III. Do you find any columns in these tables which can be NULL? Is there
any column which must not be NULL?

No. None of the columns in the table can be NULL

Q3. In a database create the following tables with suitable


constraints:

a) Based on these tables write SQL statements for the following


queries:

i. Display the dates of first registration and last registration from the table
Vehicle.

SELECT MIN(RegDate) AS ‘First registration’, MAX(RegDate) AS ‘Last registration’


FROM VEHICLE;

ii. Display the number of challans issued on each date.

SELECT COUNT(*) AS ‘Number of challans’,Ch_Date FROM CHALLAN GROUP


BY Ch_Date;
iii. Display the total number of challans issued for each offence.

SELECT COUNT(*) AS ‘Number of challans’, Offence FROM CHALLAN GROUP BY


Offence;

iv. Display the total number of vehicles for which the 3rd and 4th
characters of RegNo are '6C'.

SELECT COUNT(RegNo) WHERE RegNo LIKE ‘__6C%’ AND RegNo LIKE ‘___6C%’;

v. Display the total value of challans issued for which the Off_Desc is
'Driving without License'.

SELECT COUNT(Challan_No) FROM CHALLAN WHERE Off_Desc=’Driving without


License’;

vi. Display details of the challans issued on '2010-04-03' along with


Off_Desc for each challan.

SELECT Challan_No, Ch_Date, RegNo, Offence, Off_desc FROM CHALLAN, OFFENCE


WHERE Ch_Date=’2010-04-03’;

vii. Display the RegNo of all vehicles which have been challaned more
than once.

SELECT RegNo FROM Vehicle WHERE Challan_No>1;

viii. Display details of each challan alongwith vehicle details, Off_desc, and
Challan_Amt.

SELECT Challan_No, Ch_Date, RegNo, Offence, RegDate.VEHICLE, Owner.VEHICLE,


Address.VEHICLE’,Off_desc.OFFENCE,Challan_Amt.OFFENCE’FROM CHALLAN,VEHICLE;

b) Identify the Foreign Keys (if any) of these tables. Justify your choices.

RegNo is the foreign key for the tables as it can be used to link each other.

c) Should any of these tables have some more column(s)? Think, discuss in
peer groups, and discuss with your teacher.
No, there is no need of more column(s) in any of the tables.
Q4. In a database create the following tables with suitable
constraints:

A) Based on these tables write SQL statements for the following


queries:

i. Display the details of all the employees who work in Sales department.

SELECT No, Name, Salary, Zone, Age, Grade, Dept FROM EMPLOYEE, DEPARTMENT
WHERE EMPLOYEE.Dept=DEPARTMENT.Dept AND DName=’Sales’;

ii. Display the Salary, Zone, and Grade of all the employees whose HOD is
Nupur.

SELECT Salary, Zone, Grade FROM EMPLOYEE, DEPARTMENT WHERE Name=’Nupur’;

iii. Display the Name and Department Name of all the employees.

SELECT Name, DName FROM EMPLOYEE, DEPARTMENT WHERE


EMPLOYEE.Dept=DEPARTMENT.Dept
iv. Display the names of all the employees whose salary is not within the
specified range for the corresponding department.

SELECT Name FROM EMPLOYEE, DEPARTMENT WHERE


EMPLOYEE.Dept=DEPARTMENT.Dept AND Salary NOT BETWEEN MinSal AND MaxSal;

v. Display the name of the department and the name of the


corresponding HOD for all the departments.

SELECT DName, Name FROM EMPLOYEE, DEPARTMENT WHERE


EMPLOYEE.Dept=DEPARTMENT.Dept GROUP BY HOD;

b) Identify the Foreign Keys (if any) of these tables. Justify your
choices.
Dept is the foreign key for these tables. This is because, Dept is used to link the two
tables and it is a primary key for one of the table.

Potrebbero piacerti anche