0% found this document useful (0 votes)
65 views

Sl. No. Programs NOS Signature: Index

The document contains 10 programs with their source code. The programs include finding the largest of 3 numbers, generating a data form, performing arithmetic operations, finding the factorial of a number, using a while-do statement to print a series, displaying text, converting a digit to word, printing natural numbers and their sum, a registration form, and a password field.

Uploaded by

abhi shek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Sl. No. Programs NOS Signature: Index

The document contains 10 programs with their source code. The programs include finding the largest of 3 numbers, generating a data form, performing arithmetic operations, finding the factorial of a number, using a while-do statement to print a series, displaying text, converting a digit to word, printing natural numbers and their sum, a registration form, and a password field.

Uploaded by

abhi shek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 30

INDEX

Sl. PROGRAMS PAGE SIGNATURE


No. NOS

1
1.Program to find the largest of 3 numbers

private void largebtnActionPerformed(java.awt.event.ActionEvent evt) {


int a,b,c,large;
a=Integer.parseInt(atf.getText());
b=Integer.parseInt(btf.getText());
c=Integer.parseInt(ctf.getText());

if (a>b && a>c)


msglbl.setText("Largest of 3 numbers is "+a);
else if (b>c)
msglbl.setText("Largest of 3 numbers is "+b);
else
msglbl.setText("Largest of 3 numbers is "+c);
}

private void exitbtnActionPerformed(java.awt.event.ActionEvent evt) {


System.exit(0);
}

private void clrbtnActionPerformed(java.awt.event.ActionEvent evt) {


atf.setText("");
2
btf.setText("");
ctf.setText("");
msglbl.setText("");
}

3
4
2.Program to generate a DATA FORM

private void genbtnActionPerformed(java.awt.event.ActionEvent evt) {


String text1= titlemrmrs.getText();
//text of titleTextfield stored in text1
String text2= firstname.getText();
//text of firstname stored in text2
String text3= lastname.getText();
//text of lastname stored in text3v
String text4= ctf.getText();
//text of ctf stored in text4
String text5= section.getText();
//text of section stored in text5
repta.append("student details"+"\n");
repta.append("Name: "+text1+ " "+text2+ " "+text3+"\n");
repta.append("class: "+text4+" "+text5);//TODO add your handling code here:

5
6
3.Program to perform ARITHMETIC
OPERATIONS

private void diffbtnActionPerformed(java.awt.event.ActionEvent evt) {


int n1=Integer.parseInt(n1tf.getText());
int n2=Integer.parseInt(n2tf.getText());
oplbl.setText("-");
int res=n1-n2;
restf.setText(""+res);
}

private void quobtnActionPerformed(java.awt.event.ActionEvent evt) {


float n1=Integer.parseInt(n1tf.getText());
float n2=Integer.parseInt(n2tf.getText());
oplbl.setText("/");
float res=n1/n2;
restf.setText(""+res);
}

private void probtnActionPerformed(java.awt.event.ActionEvent evt) {


int n1=Integer.parseInt(n1tf.getText());
int n2=Integer.parseInt(n2tf.getText());
oplbl.setText("*");
int res=n1*n2;
restf.setText(""+res);
}

7
private void rembtnActionPerformed(java.awt.event.ActionEvent evt) {
int n1=Integer.parseInt(n1tf.getText());
int n2=Integer.parseInt(n2tf.getText());
oplbl.setText("%");
int res=n1%n2;
restf.setText(""+res);
}

private void addbtnActionPerformed(java.awt.event.ActionEvent evt) {


int n1=Integer.parseInt(n1tf.getText());
int n2=Integer.parseInt(n2tf.getText());
oplbl.setText("+");
int res=n1+n2;
restf.setText(""+res);
}

8
9
10
4. Program to find theFACTORIAL of a
number

private void factbtnActionPerformed(java.awt.event.ActionEvent evt) {


long fact=1,i=1;
int n=Integer.parseInt(ntf.getText());
if (n==0){
fact=1;
}
else
while (i<=n){
fact*=i;
i++;
}
reslbl.setText("Factorial of "+n+" is "+fact);
}

11
12
5. Program to print a series using while-do
statement.

private void dispbtnActionPerformed(java.awt.event.ActionEvent evt) {


float i=10;
int cnt=1;
do{
resta.append(" "+i+",");
cnt++;
i+=3.5;
}while(cnt<=10);

13
14
6. Program to display text

private void okbtnActionPerformed(java.awt.event.ActionEvent evt) {


String name = nametf.getText();
msglbl.setText("Hello "+ name+", ALL THE BEST!!!");// TODO add your handling code
here:
}

private void cancbtnActionPerformed(java.awt.event.ActionEvent evt) {


String name = nametf.getText();
msglbl.setText("Bye "+ name);

15
16
7.Program to convert DIGIT TO WORD

private void gbtnActionPerformed(java.awt.event.ActionEvent evt) {


int num = Integer.parseInt(dtf.getText());
switch (num){
case 0 : wlbl.setText("You have entered : zero.");
break;
case 1 : wlbl.setText("You have entered : ONE.");
break;
case 2 : wlbl.setText("You have entered : TWO.");
break;
case 3 : wlbl.setText("You have entered : THREE.");
break;
case 4 : wlbl.setText("You have entered : FOUR.");
17
break;
case 5 : wlbl.setText("You have entered : FIVE.");
break;
case 6 : wlbl.setText("You have entered : SIX.");
break;
case 7 : wlbl.setText("You have entered : SEVEN.");
break;
case 8 : wlbl.setText("You have entered : EIGHT.");
break;
case 9 : wlbl.setText("You have entered : NINE.");
break;
default: wlbl.setText("Invalid Entry");
}
}

18
8.Program to print natural numbers and its
sum

private void compbtnActionPerformed(java.awt.event.ActionEvent evt) {


19
int sum=0;
for(int i=1;i<=15;i++)
{
nosta.append(""+i+" ");
sum+=i;
}
sumtf.setText("SUM of 15 natural numbers is"+sum);
}

private void exitbtnActionPerformed(java.awt.event.ActionEvent evt) {


System.exit(0);
}

20
9. Program on REGISTRATION FORM

private void clrbtnActionPerformed(java.awt.event.ActionEvent evt) {


detta.setText(null);
gcb.setSelected(false);
pcb.setSelected(false);
icb.setSelected(false);
mrb.setSelected(true);

21
frb.setSelected(false);
nametf.setText(null);
}

private void subbtnActionPerformed(java.awt.event.ActionEvent evt) {


String n=nametf.getText();
String q;
if (pcb.isSelected())
{
gcb.setSelected(true);
icb.setSelected(true);
q="Post Graduate";
}
else if (gcb.isSelected())
{
icb.setSelected(true);
q="Graduate";
}
else
q="Intermediate";

if (mrb.isSelected()){
detta.append("Name : "+ n.toUpperCase()+"\n" );
detta.append("Gender : Male\n");
detta.append("Qualification : "+q+"\n" );
detta.append(" Hello!! "+n.toUpperCase()+ "\nYou are registered Successfully"
);
}

if (frb.isSelected())
detta.append("Name : "+ n.toUpperCase()+"\n" );
detta.append("Gender : Female\n");
detta.append("Qualification : "+q+"\n" );
detta.append(" Hello!! "+n.toUpperCase()+ "\nYou are registered Successfully"
);
}

22
23
10. Program on PASSWORD FIELD

private void okbtnActionPerformed(java.awt.event.ActionEvent evt) {


String pwd=new String(pwdpf.getPassword());
if (pwd.equals("program"))
okbtn.setText("PROCEED");
else
okbtn.setText("INVALID");
}

24
25
1.Program on Ice-Cream and its cost using
LISTbox

private void iclistValueChanged(javax.swing.event.ListSelectionEvent evt) {


int i=iclist.getSelectedIndex();
String ic=(String) iclist.getSelectedValue();
switch(i){
case 0 : billlbl.setText("Cost of "+ic+ "is Rs. 25" ); break;
case 1 : billlbl.setText("Cost of "+ic+ "is Rs. 35" ); break;
case 2 : billlbl.setText("Cost of "+ic+ "is Rs. 30" ); break;
case 3 : billlbl.setText("Cost of "+ic+ "is Rs. 22" ); break;
case 4 : billlbl.setText("Cost of "+ic+ "is Rs. 27" ); break;
case 5 : billlbl.setText("Cost of "+ic+ "is Rs. 24" ); break;
case 6: billlbl.setText("Cost of "+ic+ "is Rs. 45" ); break;
case 7 : billlbl.setText("Cost of "+ic+ "is Rs. 55" ); break;
case 8 : billlbl.setText("Cost of "+ic+ "is Rs. 50" ); break;
case 9 : billlbl.setText("Cost of "+ic+ "is Rs. 75" ); break;
}
}

26
27
2. Program on Selection of city and no. of
days using combobox

private void citycbActionPerformed(java.awt.event.ActionEvent evt) {


String t=(String)citycb.getSelectedItem();

int len=citycb.getItemCount();
boolean exists=false;
for(int i=0;i<len;i++){
String item=(String) citycb.getItemAt(i);
exists=true;
break;
}
if (exists=false)
citycb.addItem(t);
sellbl.setText("Selected City :"+t);
}

private void dayscbActionPerformed(java.awt.event.ActionEvent evt) {


String t=sellbl.getText();
String dur=(String)dayscb.getSelectedItem();
sellbl.setText(t +"\t"+" Selected Duration :"+dur);
}

28
29
30

You might also like