![CBSE Important Questions](../../../../../images/headings/important_question.gif)
CBSE Guess > Papers > Important Questions > Class XI > 2012 > Informatics Practices By Ms. Lakshmi Pulikollu
CBSE CLASS XI
![Next](../../../../../images/next.gif)
Chapter 6
(a) Develop an application to take input from user in a radio button out of the two referring to Area or Perimeter of a circle. Print the Area or Perimeter in a TextField for the value of Radius entered in another TextField.
Code :
private void rb1ItemStateChanged(java.awt.event.ItemEvent evt) {
if(rb1.isSelected()==true)
{
double r=Double.parseDouble(tf1.getText());
tf2.setText(""+(3.14*r*r));
} // TODO add your handling code here:
}
private void rb2ItemStateChanged(java.awt.event.ItemEvent evt) {
if(rb2.isSelected()==true)
{
double r=Double.parseDouble(tf1.getText());
tf2.setText(""+(2*3.14*r));
} // TODO add your handling code here:
}
Output :
![](images/13.gif)
(b) Develop an application to take an input in TextField for a number. If the number is even then Display its square otherwise its cube in a MessageBox.
Code :
import javax.swing.JOptionPane;
private void MessageActionPerformed(java.awt.event.ActionEvent evt) {
int n= Integer.parseInt(tf1.getText());
if(n%2==0)
JOptionPane.showMessageDialog(null,"Square is "+(n*n));
else
JOptionPane.showMessageDialog(null,"Cube is "+(n*n*n));
}
Output :
![](images/14.gif)
(c) Develop an application to calculate area of a circle, a rectangle or a triangle depending upon the user's choice (from a set of Radio Buttons). Accept the desired input Radius OR Length-Breadth OR Side as per the option selected by the user.
Code :
import javax.swing.JOptionPane;
private void formWindowActivated(java.awt.event.WindowEvent evt) {
Circle.setVisible(false); // Circle, Rectangle & Triangle are Panels
Rectangle.setVisible(false);
Triangle.setVisible(false);
}
private void rb1ItemStateChanged(java.awt.event.ItemEvent evt) {
if(rb1.isSelected()==true)
{
Circle.setVisible(true);
Rectangle.setVisible(false);
Triangle.setVisible(false);
}
}
private void ok1ActionPerformed(java.awt.event.ActionEvent evt) {
double r=Double.parseDouble(tf1.getText());
JOptionPane.showMessageDialog(null,"Area of Circle is "+(3.14*r*r));
}
private void rb2ItemStateChanged(java.awt.event.ItemEvent evt) {
if(rb2.isSelected()==true)
{
Rectangle.setVisible(true);
Circle.setVisible(false);
Triangle.setVisible(false);
}
}
private void ok2ActionPerformed(java.awt.event.ActionEvent evt) {
double l=Double.parseDouble(tf2.getText());
double b=Double.parseDouble(tf3.getText());
JOptionPane.showMessageDialog(null,"Area of Rectangle is "+(l*b));
}
private void rb3ItemStateChanged(java.awt.event.ItemEvent evt) {
if(rb3.isSelected()==true)
{
Triangle.setVisible(true);
Circle.setVisible(false);
Rectangle.setVisible(false);
}
}
private void ok3ActionPerformed(java.awt.event.ActionEvent evt) {
double b=Double.parseDouble(tf4.getText());
double h=Double.parseDouble(tf5.getText());
JOptionPane.showMessageDialog(null,"Area of Triangle is "+(0.5*b*h));
}
Output :
![](images/15.gif)
(d) An electronic shop has announced the following seasonal discounts on the purchase of certain items
![](images/16.gif)
Develop an application based on the above criteria, to input amount of purchase and the type of purchase ( TV or Music System using JRadioButton) by a customer. Compute and print the net amount to be paid by a customer along with his name accepted in a text field.
[Hint: Discount = ( Discount rate / 100) * Amount of purchase Net amount = amount of purchase - discount).]
Code :
import javax.swing.JOptionPane;
private void ComputeActionPerformed(java.awt.event.ActionEvent evt) {
String name=tf1.getText();
double amt=Double.parseDouble(tf2.getText());
double disc=0.0;
if(rb1.isSelected()==true)
{
if(amt>0 && amt<=25000)
disc=amt*0.05;
else if(amt>=25001 && amt<=50000)
disc=amt*0.10;
if(amt>50000)
disc=amt*0.15;
}
else if(rb2.isSelected()==true)
{
if(amt>0 && amt<=25000)
disc=amt*0.10;
else if(amt>=25001 && amt<=50000)
disc=amt*0.20;
if(amt>50000)
disc=amt*0.30;
}
double net=amt-disc;
JOptionPane.showMessageDialog(null,"Mr./Ms. "+name+" Pay Rs. "+net);
}
Output :
![](images/17.gif)
(e) Define a GUI application to create a list box ClassName with the following values.
![](images/18.gif)
Write a program to print the names of the class teacher according to the class selected based on the following information
Code :
private void list1ValueChanged(javax.swing.event.ListSelectionEvent evt) {
String name="";
if(list1.getSelectedIndex()==0)
name="Purnima Singh";
else if(list1.getSelectedIndex()==1)
name="Suruchi Oberoi";
else if(list1.getSelectedIndex()==2)
name="Manjula";
else if(list1.getSelectedIndex()==3)
name="Anita Mishra";
tf1.setText(name);
}
Output :
![](images/19.gif)
(f) Design a GUI application as shown below: On selecting the radio button and clicking the Set Alignment button the alignment of the text on the button gets changed to Left, Right or Centre
[Hint use the setHorizontalAlignment method. To set the alignment to right we can use setHorizontalAlignment (SwingConstants.RIGHT).]
![](images/20.gif)
Code :
import javax.swing.SwingConstants;
private void alignActionPerformed(java.awt.event.ActionEvent evt) {
if(rb1.isSelected()==true)
align.setHorizontalAlignment(SwingConstants.LEFT);
else if(rb2.isSelected()==true)
align.setHorizontalAlignment(SwingConstants.RIGHT);
else if(rb3.isSelected()==true)
align.setHorizontalAlignment(SwingConstants.CENTER);
}
Output :
![](images/21.gif)
Submitted By Ms. Lakshmi Pulikollu
Email Id : [email protected] |