Practical File
Practical File
CLASS - 12TH
SECTION - SCIENCE
4. Fibonacci series
5. Printing Patterns
17. Webpage-1
18. Webpage -2
NETWORK CONFIGURATION AND OPEN SOURCE SOFTWARE
NETWORK CONFIGURATION
Our school lab is well equipped and has 42 personal computers. The
configuration of each computer is as follows:
Intel Pentium processor @2.9GHz
RAM 4GB
Hard Disk 500GB
USB Keyboard Interface
USB Optical Mouse
Network Card
32-bit Windows Operating System
LAN Network is configured using twisted pair cables in the lab. For better
performance a simple installation of Point to Point(P_P) link between each
computers is in the network. Two switches are used to segment networks into
different sub-networks or LAN segments.
In the left half of the interface, two numbers are to be accepted. When
the user clicks on greater button, greater number with appropriate
message should be displayed.
In the right half of the above interface, a number grade is input. Valid
grades are 0-4. Upon clicking check validity button, a message depicting
validity of the grade should be displayed.
Source Code:
For (Greater) Button
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int a= Integer.parseInt(jTextField1.getText());
int b=Integer.parseInt(jTextField2.getText());
if (a>b){
jLabel4.setText(" Greater number is" + a); }
else if(b>a) jLabel4.setText(" Greater number is" + b);
For Check validity Button:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
int c=Integer.parseInt(jTextField3.getText());
if(c>=0&&c<=4){
jLabel5.setText("The grade is valid");
}
else
jLabel5.setText("The grade is invalid"); }
OUTPUT
Q.2. Mr Rehaan frequently need to calculate interest and amount due to his
clients. He asked his software programmer to design a calculator which will
calculate the simple interest and amount due if he takes loan for 5, 10, 15
years.
SOURCE CODE:
int pa=Integer.parseInt(jTextField1.getText());
double r= Double.parseDouble(jTextField2.getText());
double i,a;
int t=0;
if (jRadioButton1.isSelected()){
t=5; }
else if(jRadioButton2.isSelected()){
t=10; }
else if(jRadioButton3.isSelected()){
t=15; }
i=pa*r*t/100;
jTextField3.setText(""+i);
a=i+pa;
jTextField4.setText(""+a);}
For Clear Button:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jRadioButton1.setSelected(false);
jRadioButton2.setSelected(false);
jRadioButton3.setSelected(false); }
For exit button:
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
OUTPUT
Q.3. Write a program to print 20 terms of Fibonacci Series in output window.
1 1 2 3 5 8...............
SOURCE CODE:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int a=1; int b=1;
int sum;
System.out.print(" "+ a);
System.out.print(" "+b);
for(int i=1; i<=18; i++){
sum=a+b;
System.out.print(" "+sum);
a=b;
b=sum;}
OUTPUT WINDOW:
Q.4. Design an application using nested loop to print the given patterns. Use
button pattern 1 to display first patterns and pattern2 button to display
pattern in an output area.
4 a
43 ab
432 abc
4321 abcd
SOURCE CODE:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt{
int n1= Integer.parseInt(jTextField1.getText());
int n2 = Integer.parseInt(jTextField2.getText());
int t, x, y, lcm;
x=n1;
y=n2;
while(n2!=0){
t=n2;
n2=n1%t;
n1=t;}
lcm= x*y/n1;
jLabel4.setText(" "+lcm); }
OUTPUT:
Q6. Mr. Ram Kishore, owner of the Kiddi Land Enterprises has asked his
programmer Saumya to develop the following GUI in Netbeans.
Mr. Ram accepts payment through three types of credit cards. The offer is
given according to the following schemes:
TYPE OF CARDS OFFER
PLATINUM 20% OF DISCOUNT
GOLD 15% OF DISCOUNT
SILVER 10% OF DISCOUNT
If the Bill Amount is more than Rs. 25000 then the customer gets an additional
offer of 5%.
Write the java code for the following:
1) To assign Additional Offer as 0 and Net Amount as 0. Also set them as
uneditable.
2) When Calculate Button is clicked calculate discount as per the given
criteria and display the same in Textfield3.
3) When calculate Net Amount is clicked calculate Net Amount(total cost –
offer- Additional offer) and display it in jTextField5.
SOURCE CODE:
For calculate discount button:
double dis=0, dis1, dis2=0,amt;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
double amt = Double.parseDouble(jTextField2.getText());
if(jRadioButton1.isSelected()==true)
dis=20;
else if(jRadioButton2.isSelected()==true)
dis=15;
else if(jRadioButton3.isSelected()==true)
dis=10;
dis1= amt*dis/100;
if(amt>25000)
dis2= amt*5/100;
jTextField3.setText(" "+dis1);
jTextField4.setText(" "+dis2);}
jTextField4.setEditable(false);
jTextField5.setEditable(false);}
Output:
Q.7. Write a GUI application to calculate bill for mega mall.
(a) Write the code for the calculate button to display the discount and final
price in the Discount and Final Price Textfield respectively. Note that the
final price is calculated as (price-discount) and the discount is calculated
based on the category and price according to the following table. If Card
Holder is selected 5% discount to be given.
Category Price Discount
Men’s <10000 30%
>=10000 50%
Women’s <8000 40%
>=8000 50%
Kid’s <5000 20%
>=5000 30%
(b) Write the code for the TestData button to ensure that the user does not
enter a negative or a zero value in a price TextField. If a negative or a
zero value is entered then price textfield should be made blank and a
warning message should be displayed in a JOptionPane.
(c) Write the code for the clear button to clear all RadioButtons and final
price textfield and card holder checkbox.
(d) Write the code for Exit Button to exit the application but before closing
the application it should display message “Have a nice day”.
import javax.swing.JOptionPane;
GENERATED CODE
double disc, finalp, disc1, discount, disc2 =0;
SOURCE CODE:
For TestData Button:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
double n= Double.parseDouble(jTextField3.getText());
if(n<=0){
jTextField3.setText("");
OUTPUT:
Q.8. Create an application that receives a number through textfield and prints
the sum of its individual digits when submit button is pressed as shown below.
SOURCE CODE:
For submit button:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
int b=0, rev=0, sum=0;
int n1= Integer.parseInt(jTextField1.getText());
while(n1!=0){
b=n1%10;
sum=sum+b;
rev= rev*10+b;
n1=n1/10;
} jTextField2.setText(" "+sum);
OUTPUT
Q.9. Design an application to check whether the string is a Palindrome or not.
SOURCE CODE
For check button
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String str=jTextField1.getText();
StringBuffer str1= new StringBuffer(str);
str1= str1.reverse();
String str2=new String(str1);
if(str2.equals(str))
jLabel2.setText("It is a Palindrome ");
else
jLabel2.setText("It is not a Palindrome");
}
OUTPUT
Q.10. Design an application to convert input string to Sentence Case.
SOURCE CODE:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String s1= jTextField1.getText();
int len= s1.length();
char ch = Character.toUpperCase(s1.charAt(0));
s1= ch+ s1.substring(1);
for(int i=0; i<=s1.length()-1; i++){
if(s1.charAt(i)== ' '){
ch= Character.toUpperCase(s1.charAt(i+1));
s1= s1.substring(0, i+1) + ch+ s1.substring(i+2)
}
} jTextField1.setText(s1); }
OUTPUT
Q.11. Design an application to count total number of Vowels in the input
String.
SOURCE CODE:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int count=0;
String s= jTextField1.getText();
for(int i=0; i<s.length(); i++){
char ch= s.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'){
count=count+1; }
jLabel2.setText(" "+count);
}}
OUTPUT
Q.12.Design a Java application to print Even no. series from the range 1 to 100
as an item in List Box.
SOURCE CODE:
import javax.swing.DefaultListModel;
For Print Series Button:
nprivate void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
DefaultListModel m= new DefaultListModel();
for (int i=2; i<=100; i=i+2){
m.addElement(i);
jList1.setModel(m);} }
OUTPUT
Q.13. Create a table ‘Library’ having following structure :
Column name Data Type Size Constraint
Libno Int 4 Primary Key
Title Varchar 20 Not null
Author Varchar 25
Publisher Varchar 30
Price Int 7
Purchasedate Date
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
For Delete Buttton:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt){
try{
Class.forName("java.sql.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost/Nishant", "root",
"admin");
Statement stmt= con.createStatement();
String q= "Delete from Library where Libno='"+jTextField1.getText()+"';";
stmt.executeUpdate(q);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);}
}
For Clear Button:
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText(" ");
jTextField2.setText(" ");
jTextField3.setText(" ");
jTextField4.setText(" ");
jTextField5.setText(" ");
jTextField6.setText(" ");}
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);}}
OUTPUT FOR LOAD BUTTON:
Q.14. Design a Java application to retrieve the data from a “Course “ table for
the given coursed in a Table control by clicking on Retrieve button. By clicking
on clear button the Table should get clear.
RNo Name Class Course ID Coursename
1 Ankit X C001 IT
2 Shreya XI C002 Commerce
3 Palak XI C003 Math/Bio
4 Neel VIII C004 IT
5 Preksha IX C005 IT
SOURCE CODE:
import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
For Retrieve Button:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel model= (DefaultTableModel) jTable1.getModel();
try{
Class.forName("java.sql.Driver");
Connection con
=DriverManager.getConnection("jdbc:mysql://localhost/Nishant", "root",
"admin");
Statement stmt= con.createStatement();
String q= "select* from Course;";
ResultSet rs= stmt.executeQuery(q);
while(rs.next()){
int rno= rs.getInt("rno");
String na= rs.getString("Name");
String cla= rs.getString("Class");
String couid= rs.getString("CourseID");
String cou= rs.getString("Coursename");
model.addRow(new Object[]{ rno, na, cla, couid, cou});
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
OUTPUT:
15. Consider the following table SHOP and answer the following questions:
No. Shopname Sales Area Cust_percent Rating City
1 S.M. Sons 250000 West 68.6 C Delhi
2 Dhirajner 500000 South 81.8 A Mumbai
3 Kirtit 300000 North 79.8 B Kolkata
4 Scant Ripple 380000 North 88.0 NULL Mumbai
5 Biswas 456000 East 92.0 A Delhi
Store
6 Crystal 290000 South 66.7 A Kolkata
3. To display list of all shops with sales more than 300000 in ascending
order of shopname.
4. To display a report with Shopname, area, and rating for each shop in the
table for only those shops whose sales is between 350000 and 400000.
5. To display the city and the number of shops in each city.
12.To display report showing shopname, area, city, and sales/12 as ‘Monthy
sales’ from shop table.
Table Salary:
17.Identify a foreign key field and write command to apply foreign key
field.
18.To count name of all staff that are in sales having more than 10 years of
experience.
19.To display the highest commission(%) among all male staff.
21.To display name, count(dept), basic from salary and staff for their
corresponding ID.
22. Create a natural join between staff and salary table using join clause.
23. Create an Equijoin between Staff and Salary table.
17. 1) Write the HTML code to generate the following webpage with the given
below specifications:
(a) Title of the webpage is “ecommerce”.
(b) Heading of the page is in centre and in maroon colour.
(c) Caption of table is blue colour.
(d) Background of table is “cyan” colour and border of size 2.
(e) List heading is red in centre.
(f) Create a bulleted list and underline all list item.
<html>
<head>
<title>Ecommerce</title>
</head>
<body>
<h1 align='center'><font color='maroon'> eCommerce</font></h1>
<img src="C:\Intel\COMP.PNG" align='right'>
<p align='center'> Ecommerce or electronic commerce is a subset of ebusiness,
e-commerce
is the purchasing, and exchanging of goods<br>
and services over computer networks(such as internet) through which
transactions or terms
of sale are performed electronically.
</p>
<br>
<br>
<table bgcolor= 'cyan' align ='center' border=2>
<font color='blue'><caption><h3><font color='blue'>eCommerce
requirements</h3></font></caption>
<tr align='center'><td>Shopping cart</td><td>Merchant account</td></tr>
<tr align='center'><td>Processing gateway</td><td>Digital
Certificate</td></tr>
</table>
</br>
<h3 align='left'><font color='red'> Ecommerce can be broken into four
categories</font></h3>
<ul type='disc'>
<li><u>B2B(Business-to-Business)</u></li>
<li><u>B2C(Business-to-Consumer)</u></li>
<li><u>C2B(Consumer-to-Business)</u></li>
<li><u>C2C(Consumer-to-Consumer)</u></li>
</ul>
</body>
</html>
2) Write an XML document to represent the following recipe as shown:
recipe{display:block}
title {font-size:large; font-weight:bold; text-align:center; display:block;
color:#800000;}
ing {display:block; margin-top:20px; text-align:center; margin-left:10pt; font-
family:verdana;}
in {display:block; margin-left:60pt; text-align:left;}
amt{font style:itallic;}
procedure {display:block; margin-top18px; margin-left:60pt; text-align:left;}
step {display:block; font-color:blue; margin-top:10pt; font-family:Arial; margin-
left:60pt; text-align:left;}