IP fiile

24
DELHI PUBLIC SCHOOL NAVI MUMBAI RECORD FILE INFORMATICS PRACTICES Name: Sarthak singh Class/section : XII B School seal :

description

record file

Transcript of IP fiile

Page 1: IP fiile

DELHI PUBLIC SCHOOL navi mumbai

RECORD FILE

Name: Sarthak singh Class/section : XII B School seal :

Roll no :

Page 2: IP fiile

2

Page 3: IP fiile

Program 1 : To print odd numbers between 2 numbers accepted from the user

3

Page 4: IP fiile

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

Page 5: IP fiile

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

5

Page 6: IP fiile

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

Page 7: IP fiile

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

Page 8: IP fiile

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

Page 9: IP fiile

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

Page 10: IP fiile

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

Page 11: IP fiile

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

Page 12: IP fiile

Progaram 8:

Consumption level 1st(200) 2nd(200) Above(400)Domestic power 2.45 3.95 4.65

Non-domestic upto 10KW

5.40 5.40 5.40

Non-domestic above 10KW

4.92 4.92 4.92

Agriculture upto 10KW

1.55 1.55 1.55

Agriculture above 10KW

9.84 9.84 9.84

Industrial upto 10KW

4.40 4.40 4.40

Industrial above 10KW

5.05 5.05 5.05

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

Page 13: IP fiile

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

Page 14: IP fiile

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

Page 15: IP fiile

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

Page 16: IP fiile

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

Page 17: IP fiile

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

Page 18: IP fiile

t3.setText(""+(amt*dis));

t4.setText(""+(amt-(amt*dis)));

Disable command:

t3.setEnabled(false);

t4.setEnabled(false);

18

Page 19: IP fiile

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

Page 20: IP fiile

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

Page 21: IP fiile

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

Page 22: IP fiile

22