Sei sulla pagina 1di 22

KENDRIYA VIDYALAYA NO.

1 BAJAJ NAGAR

JAIPUR ,RAJASTHAN

REPORT FILE

INFORMATICS PRACTICES

Name: Gaurav Chaturvedi


Class/section : XII C School seal :
Roll no :
2
Program 1 : To print odd numbers between 2 numbers accepted from
the user

3
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");

4
Program 2:Print the sum and average of all the numbers entered by
the user using do-while loop.

5
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);}

6
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.

7
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);

8
Program 4 :To print the following :

CODING :

for(int i=1;i<=6;i++){

for(int j=i;j>=1;j--)

ta1.append(j+" ");

ta1.append("\n");}

9
Program 5 :To print the following :

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
Program 6: To print the following :

CODING :
for(char i='a';i<='d';i++)
{for(char j='a';j<=i;j++)
ta1.append(i+" ");
ta1.append("\n");
}

11
Progaram 8:

Consumption level 1st(200) 2nd(200) Above(400)


Domestic power 2.45 3.95 4.65
Non-domestic upto 5.40 5.40 5.40
10KW
Non-domestic above 4.92 4.92 4.92
10KW
Agriculture upto 1.55 1.55 1.55
10KW
Agriculture above 9.84 9.84 9.84
10KW
Industrial upto 4.40 4.40 4.40
10KW
Industrial above 5.05 5.05 5.05
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);}

Clear button code:


t1.setText("");

bg1.clearSelection();

c1.setSelected(false);

c2.setSelected(false);

ta1.setText("");

Exit button code:


JOptionPane.showMessageDialog(null,"Going to exit","Exit command",2);

System.exit(0);

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
lname=ln;}

void printdata(){

ta1.append("First name:"+fname+"\nLast name:"+lname);

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
graduate g1=new graduate(t1.getText(),t2.getText(),t3.getText(),t4.getText());

g1.printdata();

g1.printgrade();

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

Potrebbero piacerti anche