Informatics Practices Class 12 Record File Cbse
Informatics Practices Class 12 Record File Cbse
RECORD FILE
INFORMATICS PRACTICES
School seal :
Program 1 : To print odd numbers between 2 numbers accepted from the user
CODING : Program 1
int n1,n2; n1=Integer.parseInt(t1.getText()); n2=Integer.parseInt(t2.getText()); If(n1>n2) {for(int i=n2;i<=n1;i++) if(i%2!=0) ta1.append(i+"\n");} else {for(int j=n1;j<=n2;j++) if(j%2!=0) ta1.append(j+"\n");
Program 2:Print the sum and average of all the numbers entered by the user using do-while loop.
CODING :
{float avg=0; int a,sum=0,count=0; do {String n=JOptionPane.showInputDialog("enter the number"); a=Integer.parseInt(n); sum=sum+a; count++;} while(a!=0); avg=sum/(count-1); t1.setText(""+sum); t2.setText(""+avg);}
Program 3 : To print the sum of ( 1 + 1/1! + 1/2! + 1/3! + . + 1/n! ) where n is the value taken from the user.
CODING:
import javax.swing.JOptionPane; double fact=1,n,sum=1; n=Double.parseDouble(t1.getText()); for(int x=1;x<=n;x++){ fact=fact*x; sum=sum+(1/fact); continue;} t2.setText(""+sum);
CODING: int k=1; for(int i=1;i<=4;i++){ for(int j=1;j<=i;j++) {ta1.append(k+" "); k++;} ta1.append("\n");}
10
11
Progaram 8:
Consumption level Domestic power Non-domestic upto 10KW Non-domestic above 10KW Agriculture upto 10KW Agriculture above 10KW Industrial upto 10KW Industrial above 10KW
When user select radio button(domestic power button) disable both the check boxes. 2 When user clicks on the radio buttons both the check box will be enabled. 3 Exit button - Terminate the program. 4 Clear button-Clear text box, radio button, check box.
12
Coding: import java.awt.Color; import javax.swing.JOptionPane; setTitle("BILL AMOUNT"); initComponents()this.getContentPane().setBackground(Color.yellow); b1.setToolTipText("Calculate"); b2.setToolTipText("Clear"); b3.setToolTipText("Exit");
13
BUTTON CODING:
double units,amt=0; units=Double.parseDouble(t1.getText()); if(r1.isSelected()==true) { if(units<=200) amt=(2.45)*units; else if(units<=400) amt=(2.45)*200+(200-units)*3.95; else if(units>400) amt=(2.45)*200+(3.95)*200+(units-200)*4.65; ta1.append("The bill for Domestic power is Rs"+amt); } else if(r2.isSelected()==true) {if(c1.isSelected()==true) amt=units*(5.40); if(c2.isSelected()==true) amt=units*(4.92); ta1.append("The bill for Non-domestic power is Rs"+amt);} else if(r3.isSelected()==true) {if(c1.isSelected()==true) amt=units*(1.55);
14
if(c2.isSelected()==true) amt=units*(9.84); ta1.append("The bill for Non-domestic power is Rs"+amt);} else if(r4.isSelected()==true) {if(c1.isSelected()==true) amt=units*(4.40); if(c2.isSelected()==true) amt=units*(5.05); ta1.append("The bill for Industrial power is Rs"+amt);}
15
Disable command:
For domestic: c1.setEnabled(false); c2.setEnabled(false); For Non-domestic: c1.setEnabled(true); c2.setEnabled(true); For Agricultural: c1.setEnabled(true); c2.setEnabled(true); For Industrial: c1.setEnabled(true); c2.setEnabled(true);
16
Program 9 :To accept the mode of payment from the user by using combo box and print the net amount.
CODING:
double i=c1.getSelectedIndex(); double amt,dis=0; amt=Double.parseDouble(t2.getText()); if(i==0) dis=0.10; if(i==1) dis=0.20; if(i==2) dis=0.05;
17
t3.setText(""+(amt*dis)); t4.setText(""+(amt-(amt*dis)));
Disable command:
t3.setEnabled(false); t4.setEnabled(false);
18
Program 10: Make a student class .Give access specifier as private to Firstname,Lastname,stream,doj and make a constructors to initialize their values.
Coding: class student{ private String fname,lname; student(String fn,String ln){ fname=fn;
19
} } class graduate extends student{ private String stream,doj; graduate(String fn,String ln,String s,String d){ super(fn,ln); stream=s; doj=d; } void printgrade(){ ta1.append("\nStream:"+stream+"\nDate of joining:"+doj);}}
Calling Code: String fname=t1.getText(); String lname=t2.getText(); String stream=t3.getText(); String doj=t4.getText();
20
Program 11:Create a class student with data members (Name,Date of birth,Roll number).Make a method to accept its values and print the data of the student.Subclass of this class is Marks having data members (Total,Percentage,Grade).
21
22