Vous êtes sur la page 1sur 46

2010-2011

Informati
cs
Practices
Practical File

[ANUPAM VERMA]
XII-H
42

INDEX
1. Create a Java application to find the discount of an
item on the basis of category of item
2. Create a Java application to find the incentive ( %)
of sales for a sales person
3. Create a java applications to convert a given
temperature Fahrenheit to celcius and vice versa
using switch case statement
4. Create a java desktop application to store
nationality of peoples in a jcombobox control
5. Write a Java Desktop application to swap two
number without using third variable
6. Write a Java Desktop application that take a
number of seconds as input and converts this
value to the corresponding number of hours,
minutes, and seconds.
7. Write a program that reads an integer value and
print the sum of all even integers between 2 and
the input value inclusive. Print an error message if
the input value is less than 2
8. Write a program to check weather the number is
prime or not.
9. Write a program to check weather the number is
perfect or not.
42

10. write a program to find the sum and average


of n natural numbers, odd numbers and even
numbers.

11. Write a program reads in two integers and


determines and prints if the first is a multiple of the
second.
12. Write a program to adds several employees
names and removes a selected name from the jlist
control
13. Write a program to adds several employees
names and removes a selected name from the
jcombobox control
14. Write a program to find the sum of the
following Fibonacci series 0 1 1 2 3 5 8 13.
15. Write a program to find the power first number
to the second.
16. What happens in the following example?
<TD> Rosan Singh<BR> sandeep Joshi<br>Ritu
Ahuja</TD>
17. What type of link is <A HREF=”#intro”>
Intro</A>? What document will be accessed to
form the tag?
18. Create a page to tell about your hobbies and
interest. On the page include links to interesting
sites that coincide with your description. For
instance, if you like sports, you might create a link
to http://www.cnn.com/Sports/ for the benefit of
your users.
42

19. Create a form that offers the following choices


in a pop-up menu, a series of radio buttons and a
list of check boxes. Make a different value the
default in each. The choices are: North, South,
East, West.
20. Write HTML code to create a static page in the
format given below:

HTML FORM EXAMPLE

NAME :

EMAIL :

SIGN ME UP !

21. Write HTML code to create a static web page


in the format given below;
Big bazaar
All your shopping needs met under one
roof
Availability of all possible leading brands. Guarantee of
quality and price. Free home delivery . we provide the
following category of products.

1. clothing and accessories


• Men
• Women
• Kids
2. Household appliances
3. Grocery

Special
Shop Notes:
timing : 10.00 a.m to 8.00 p.m

a) Title of the web page is APKA BAZAR.


42

b)Background color of the page is grey and font


style is COMIC SANSMS.
c) The font style for the sub title “All yours……roof”
is TAHOMA in maroon color.
d)Link color should be BLUE and visited link color
should be GREEN.
e) The page are linked as follows :
Clothing & Accessories as clothes.htm
Household Appliances as house.htm
Grocery as grocery.htm
f) Use ordered and unordered list wherever
required.
g)The horizontal rule at the two places is a shaded
line of size 5
h) The bottom message is a smallest heading level
42

CERTIFICATE

This is to certify that I, Krishan Chaturvedi of


class XII-H of K.D.B. Public School Ghaziabad,
have prepared the practical file of the subject
INFORMATICS PRACTICES under the guidance of
my subject teacher Mrs. Anubha Seth. Has been
granted certificate of successful completion and
outstanding performance by this teacher.

Sign……………….
Date………………
42

1.Create a Java application to find the


discount of an item on the basis of
category of item [electrical appliance /
electronic gadget/ stationary]. The
categories will be implemented in
jradioButton controls. The discount will be
calculated as follows:
Cost Discount (%)
<=1000 5
Otherwise 10
The extra discount will be calculated as follows:
Category Discount
( %)
Electrical 3
appliance
Electrical gadget 2
Stationary 1
Calculate the total discount as : discount on cost
+discount on category
Calculate the discount amount as cost * discount
Using a button’s (compute discount ) click event
handler, display the discount in a jtextfield
control. Also implenment the following IDE
42

Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
String s1=tf1.getText():;
Int num= Integer.parseInt(s1);
float doc;
float dot=0;
if (num1<=1000)
{doc=(5/100)*num1;}
else
{doc=(10/100)*num1;}
If(rb1.isSelected())
{dot=(3/100)*num1;}
If(rb2.isSelected())
{dot=(2/100)*num1;}
If(rb3.isSelected())
{dot=(1/100)*num1;}
}
Float td=(doc+dot);
Tf2.setText(“discount is”+td);
}
42

OUTPUT:-
42

2.Create a Java application to find the


incentive ( %) of sales for a sales person on
the basis of following feedbacks:
Feedback Incentive ( %)
Maximum sales 10
Excellence 8
customer feedback
Maximum count of 5
customer

Note that the sales entry should not be


space.Calculate the total incentive as discount *
incentive
The feedback will be implemented in jcheckbox
controls. Using jbutton (compute incentive) click
event handler, display the total incentives in a
jtextfield control. Also implement the following
setting for IDE
42

Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
String s1=TF1.getText();
Float num=Float.parseFloat(s1);
Float ms=0, ecf=0, mcc=0;
if(CB1.isSelected())
{ms=(10/100)*num;
}
if(CB2.isSelected())
{ecf=(8/100)*num;
}
if(CB3.isSelected())
{mcc=(5/100)*num;
}
float tic=ms+ecf+mcc;
TF2.setText("" + tic);
}
42

OUTPUT:-
42

3.Create a java applications to convert a


given temperature Fahrenheit to celcius
and vice versa using switch case
statement. For an incorrect choice or input,
an appropriate error message should be
displayed.
( hints : c=5/9 X ( f-32) and f=1.8 X (c + 32)
Using a jbutton (convert click handler, display the
corresponding temperature value in a jtextfield
control. Also implement the following setting for
IDE:

temprature
Fahrenheit to Celsius convert
Celsius to Fahrenheit

Exit
Converted value

Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
float t=Float.parseFloat(Temp.getText());
doubleval;
intch;
if(FC.isSelected())
ch=1;
42

else
ch=2;
switch(ch) {
case 1:val=(t-32)*5/9;
value.setText("value is"+val);break;
case 2:val=(1.8*t)+32;
value.setText("value is"+val);break;
}

OUTPUT:-
42

4.Create a java desktop application to store


nationality of peoples in a jcombobox
control and display an appropriate
message when you click on a display
button

Nationality
Sri Lanka

dispaly Exit

Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
String nat=(String)Nation.getSelectedItem();
String str="Your nationality is "+nat;
JOptionPane.showMessageDialog(null,str);
}
OUTPUT:-
42
42

5.Write a Java Desktop application to swap


two number without using third variable.
Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
int num1=Integer.parseInt(a.getText());
int num2=Integer.parseInt(b.getText());
num1=num1*num2;
num2=num1/num2;
num1=num1/num2;
sa.setText(""+num1);
sb.setText(""+num2);
}

OUTPUT:-
42

6.Write a Java Desktop application that take


a number of seconds as input. The program
converts this value to the corresponding
number of hours, minutes, and seconds
and display theses values.
Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
int value=Integer.parseInt(val.getText());
int hours=value/3600;
value=value%3600;
int minutes=value/60;
value=value%60;
int seconds=value;
hr.setText(""+hours);
min.setText(""+minutes);
sec.setText(""+seconds);
}
OUTPUT:-
42
42

7.Write a program that reads an integer


value and print the sum of all even integers
between 2 and the input value inclusive.
Print an error message if the input value is
less than 2.

Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
int sum=0;
int a=Integer.parseInt(num.getText());
if(a>2)
{for(int i=3;i<=a;i++)
{if(i%2==0)
sum=sum+i;
}res.setText(""+sum);}
else
{JOptionPane.showMessageDialog(null,"Wrong
Input");}
}
OUTPUT:-
42
42

8.Write a program to check weather the


number is prime or not.
Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
int a=Integer.parseInt(t1.getText());
int k=0;
for(int i=2;i<a;i++)
{if(a%i==0)
k++;
}
if(k>0)
t2.setText("not a prime no.");
else
t2.setText("prime no.");
}
OUTPUT:-
42
42

9.Write a program to check weather the


number is perfect or not.
Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
int a=Integer.parseInt(t1.getText());
int sum=0;
for(int i=1;i<a;i++)
{if(a%i==0)
sum=sum+i;
}
if(sum==a)
t2.setText("prefect no.");
else
t2.setText("not a prefect no.");
}
OUTPUT:-
42

10. Write a program to find the sum and


average of n natural numbers, odd
numbers and even numbers.
Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
int a=Integer.parseInt(t1.getText());
int sumt=0;
for(int i=1;i<=a;i++)
{sumt=sumt+i;
}
t2.setText(""+sumt);
double avg=sumt/a;
t3.setText(""+avg);
int sum1=0;
int count=0;
for(int j=1;j<=a;j=j+2)
{ sum1=sum1+j;
count++;
}
double avg1=sum1/count;
int sum2=sumt-sum1;
double avg2=sum2/(a-count);
t4.setText(""+avg1);
t5.setText(""+avg2);
}
42

OUTPUT:-
42

11. Write a program reads in two integers


and determines and prints if the first is a
multiple of the second.
Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a%b;
if(c==0)
{int d=a/b;
t3.setText("first is the multiple of second by order"+d);
}
else
t3.setText("not a multiple");
}
OUTPUT:-
42

12. Write a program to adds several


employees names and removes a selected
name from the jlist control
Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
String a=t1.getText();
DefaultListModeldlm=(DefaultListModel)lst.getMod
el();
dlm.addElement(a);
lst.setModel(dlm);
}

private void
jButton2ActionPerformed(java.awt.event.ActionEve
ntevt) {
String a=t1.getText();
DefaultListModeldlm=(DefaultListModel)lst.getMod
el();
int b=lst.getSelectedIndex();
dlm.removeElementAt(b);
lst.setModel(dlm);
}
42

OUTPUT:-
42

13. Write a program to adds several


employees names and removes a selected
name from the jcombobox control.
Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
String a=t1.getText();
employ.addItem(a);
}
private void
jButton2ActionPerformed(java.awt.event.ActionEventev
t) {
String a=t1.getText();
employ.removeItem(a);
}

OUTPUT:-
42

14. Write a program to find the sum of the


following Fibonacci series 0 1 1 2 3 5 8 13.
Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
int a=1;
int b=0;
int sum=0;
for(int i=0;i<7;i++)
{int c=a+b;
a=b;
b=c;
sum=sum+c;
}
t1.setText(""+sum);
}
42

OUTPUT:-

15. Write a program to find the power first


number to the second.
Answer:
private void
jButton1ActionPerformed(java.awt.event.ActionEventev
t) {
int s=1;
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
for(int i=1;i<=b;i++)
{s=s*a;}
t3.setText(""+s);
}
OUTPUT:-
42
42

16. What happens in the following example?


<TD>Rosansingh<br>Sandeepjoshi<br>Rituahi
ya</TD>

Answer:
The names will get into a form of a list.
OUTPUT:-
42

17. What type of link is this


<a href=”#intro”>intro</a>?
What document is to be accessed to form
the tag?

Answer:
The above link is named intro and this hyperlink is
linked to a heading within the document the name of
the heading is also intro.
42

18. Create a page to tell about your hobbies


and interest on the page include link to
interesting sites that conclude with your
description for instance if you like sports,
you might create a link for the benefit of he
user
Answer:
<HTML>
<HEAD>
<TITLE>Hobbies and interests</TITLE>
</HEAD>
<BODY>
<H1>Click your hobby from the list given below</H1>
<A
HREF="http://www.cnn.com/Sports/">Sports</A><BR>
<A HREF="http://www.mtv.com/">Music</A><BR>
<A
HREF="http://www.amazon.com/Books">Reading</A>
<BR>
<A
HREF="http://www.wikipedia.com/Dance/">Dance</A>
<BR>
<BR>
<MARQUEE>Thanks for visiting!</MARQUEE>
</BODY>
</HTML>
42

OUTPUT:-
42

19. Create a form that offer the following


choice in a pop up menu, a series of radio
button and a list of checkboxes, the
choices are: north, south, east, west.
Answer:
<HTML>
<BODY>
<FORM action="mailto:abc.xyz@gmail.com"
method="post">
Select an option:-<BR>
<INPUT type="checkbox" name="s1" value="North"
CHECKED>North<BR>
<INPUT type="checkbox" name="s2" value="South"
>South<BR>
<INPUT type="checkbox" name="s3" value="East"
>East<BR>
<INPUT type="checkbox" name="s4" value="West"
>West<BR>
<BR>
<SELECT name="Direction">
<OPTION value="North">North</OPTION><BR>
<OPTION value="South"
SELECTED>South</OPTION><BR>
<OPTION value="East">East</OPTION><BR>
<OPTION value="West">West</OPTION><BR>
</SELECT><BR><BR>
<INPUT type="radio" name="North"
value="North">North<BR>
<INPUT type="radio" name="South"
value="South">South<BR>
42

<INPUT type="radio" name="East" value="East"


CHECKED>East<BR>
<INPUT type="radio" name="West"
value="West">West<BR>
<INPUT type="submit" value="SUBMIT"/>
</FORM>
</BODY>
</HTML>
42

OUTPUT:-
42

20. Write a HTML code to create a static page


in the format given below.

HTML FORM EXAMPLE


NAME:
EMAIL:
SIGN ME UP

Answer:
<HTML>
<BODY>
<H1 align="center">HTML FORM EXAMPLE</H1>
<BR>
<FORM action="mailto:abc.xyz@gmail.com"
method="post">
NAME: <INPUT type="text" name="name"/><BR>
<BR>
EMAIL: <INPUT type="text" name="email"/>
<BR><BR><BR>
<INPUT type="submit" value="Sign Me Up!"/>
</FORM>
</BODY>
</HTML>
42

OUTPUT:-
42

21. Write a HTML code to create a static web


page in the format given below

Special Notes:
a) Title of the page is APKA BAZAR.
b) Backgound color of the page is grey and
font style is COMIC SANSMS.
c)The font of the subtitle “All yours……roof”
is TAHOMA in maroon colour.
d) Link color should be BLUE and the visiting
link color be GREEN.
e) The page are linked as followes:
Clothing & Accessories as
clothes.htm
Household Appliances as
house.htm
Grocery as grocery.htm
f) Use ordered land unordered list wherever
required.
42

g) The horizontal rule at the two places is a


shade line of size 5.
h) The bottom message is a smallest
heading level.
Answer:
<HTML>
<HEAD>
<TITLE>Apka Bazar</TITLE>
</HEAD>
<BODY BGCOLOR="grey" link="blue" vlink="green">
<FONT face="COMIC SANSMS">
<H1 align="center">Big Bazaar</H1>
</FONT><BR><BR>
<FONT color="maroon" face="Tahoma">
<CENTER>All your shopping needs met under one
roof</CENTER>
</FONT><BR>
<FONT face="COMIC SANSMS">
<P>Availability of all possible leading
brands.Guarantee of quality and price.Free home
delivery.We provide the following category of
products.</P>
<BR><BR>
<OL>
<LI><A HREF="clothes.html">Clothing and
accessories</A><BR>
<UL>
<LI>Men
<LI>women
<LI>Kids
</UL>
42

<LI><A HREF="house.htm">Household
Appliances</A>
<LI><A HREF="grocery.htm">Grocery</A>
</OL><BR>
<HR size=5>
<H6>Shop timings:10 am to 8 pm
</H6>
<HR size=5>
</FONT>
</BODY>
</HTML>

OUTPUT:-
42

Vous aimerez peut-être aussi