Beruflich Dokumente
Kultur Dokumente
1 BAJAJ NAGAR
JAIPUR ,RAJASTHAN
REPORT FILE
INFORMATICS PRACTICES
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:
2 When user clicks on the radio buttons both the check box will be
enabled.
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;
else if(r2.isSelected()==true)
{if(c1.isSelected()==true)
amt=units*(5.40);
if(c2.isSelected()==true)
amt=units*(4.92);
else if(r3.isSelected()==true)
{if(c1.isSelected()==true)
amt=units*(1.55);
14
if(c2.isSelected()==true)
amt=units*(9.84);
else if(r4.isSelected()==true)
{if(c1.isSelected()==true)
amt=units*(4.40);
if(c2.isSelected()==true)
amt=units*(5.05);
bg1.clearSelection();
c1.setSelected(false);
c2.setSelected(false);
ta1.setText("");
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{
fname=fn;
19
lname=ln;}
void printdata(){
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();
21
22