Thursday, 21 January 2016

IP Assignment for class XI (2015-16)

Dear students,
the following assignment is for looping and switch case statements.

Assignment for Informatics Practices
Class – XI (2015-16)
1.       What will be the output of the following programs :
a.       for (int k=1; k<=10; k=k+3)          
        jTextArea1.append("\n"+k);

b.      for(int k=1;k<=10;k+=3)         
        jTextArea1.setText(jTextArea1.getText()+"\n"+k);

c.       int a=5 , sum=0;
while (a>3)
 {
sum+=a; 
 a-=2; 
                              }
d.      int w=6, sum=0;
do
{
                sum+=w;
                w-=2;
} while(w>3);

e.       for (int i=10; i<=30; i+=4)
        jTextArea1.setText(jTextArea1.getText() + ” “ + Integer.toString(i));

f.        int x=2, y=20;
while(x<=y)
{
                JOptionPane.showMessageDialog(null, “ “+x);
                x=x+3;
}

g.        int x, y;
x= Integer.parseInt(jTextField1.getText());
y= Integer.parseInt(jTextField2.getText());
if (x=y)
                jTextField3.setText(“x  and y are equal”);
else
                jTextField3.setText(“x  and y are equal”);

h.       int a=1;
do
{
                jTextArea1.setText(Integer.toString(a+2));
                a=a+2;
} while(a<=6);

i.         String name=”Akash Jaiswal”, Name;
Name=jTextField1.getText();
jTextArea1.setText(“Welcome Mr.”+name);
jTextArea2.setText(“Hello  “+Name+”\t You are a Member of Microsoft.\n\tBill Gates”);

2.       Rewrite the following code using switch case statement without affecting the output of the following codes :
a.        char a;
if (a==’b’)
                jTextField1.setText(“Blue Ray ordered”);
else if (a==’d’)
                jTextField1.setText(“DVD ordered”);
else if (a==’c’)
                jTextField1.setText(“Compact Disk ordered”);
else if (a==’p’)
                jTextField1.setText(“Printer ordered”);
else if (a==’s’)
                jTextField1.setText(“Scanner ordered”);
else
                jTextField1.setText(“Wrong Choice”);

b.      int ch=0;
ch=Integer.parseInt(jTextField1.getText()) ;
if (ch==1)
                JOptionPane.showMessageDialog(null,“It is Monday”);
else if (ch==2)
                JOptionPane.showMessageDialog(null,“It is Tuesday”);
else if (ch==3)
                JOptionPane.showMessageDialog(null,“It is Wednesday”);
else if (ch==4)
                JOptionPane.showMessageDialog(null,“It is Thursday”);
else if (ch==5)
                JOptionPane.showMessageDialog(null,“It is Friday”);
else if (ch==6)
                JOptionPane.showMessageDialog(null,“It is Saturday”);
else if (ch==7)
                JOptionPane.showMessageDialog(null,“It is Sunday”);
else
                JOptionPane.showMessageDialog(null,“Please enter number between 1 to 7”);

c.       int code=0;
code=Integer.parseInt(jTextField1.getText()) ;
if (code==1)
                JOptionPane.showMessageDialog(null,“Nokia Mobile”);
else if (code==2)
                JOptionPane.showMessageDialog(null,“Samsung  Mobile”);
else if (code==3)
                JOptionPane.showMessageDialog(null,“Sony  Mobile”);
else if (code==4)
                JOptionPane.showMessageDialog(null,“Microtech  Mobile”);
else if (code==5)
                JOptionPane.showMessageDialog(null,“Apple Mobile”);
else
                JOptionPane.showMessageDialog(null,“Ordered mobile not supported. Use code 1 to 5”);

d.      if (jComboBox1.getSelectedIndex()==0)
                JOptionPane.showMessageDialog(null,“You belong to India”);
else if (jComboBox1.getSelectedIndex()==1)
                JOptionPane.showMessageDialog(null,“You belong to Canada”);
else if (jComboBox1.getSelectedIndex()==2)
                JOptionPane.showMessageDialog(null,“You belong to Kenya”);
else if (jComboBox1.getSelectedIndex()==3)
                JOptionPane.showMessageDialog(null,“You belong to Australia”);

e.      if (jComboBox1.getSelectedIndex()==0)
                jTextField1.setText(“Science  stream”);
else if (jComboBox1.getSelectedIndex()==1)
                JOptionPane.showMessageDialog(null,“You belong to Canada”);
else if (jComboBox1.getSelectedIndex()==2)
                JOptionPane.showMessageDialog(null,“You belong to Kenya”);
else if (jComboBox1.getSelectedIndex()==3)

                JOptionPane.showMessageDialog(null,“You belong to Australia”);

No comments:

Post a Comment