0% found this document useful (0 votes)
86 views21 pages

File of Ip

The document contains 10 code snippets in Java that demonstrate various programming concepts like data types, conditional statements, loops, functions etc. Each code snippet is followed by the name "ABHISHEK AGARWAL" and describes a short programming problem and its solution.

Uploaded by

mantuu123
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)
86 views21 pages

File of Ip

The document contains 10 code snippets in Java that demonstrate various programming concepts like data types, conditional statements, loops, functions etc. Each code snippet is followed by the name "ABHISHEK AGARWAL" and describes a short programming problem and its solution.

Uploaded by

mantuu123
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/ 21

1.

CODING :
int day=Integer.parseInt(jTextField1.getText());
switch(day)
{

case 1:jlabel2.setText("sunday");
break;
case 2: jlabel2.setText("monday");
break;
case 3: jlabel2.setText("tuesday");
break;
case 4:jlabel2.setText("wednesday");
break;
case 5:jlabel2.setText("thursday");
break;
case 6:jlabel2.setText("friday");
break;
case 7: jlabel2.setText("saturday");
break;
default:jlabel2.setText("wrong day number");
}

ABHISHEK AGARWAL

SOLUTION :

ABHISHEK AGARWAL

2. CODING :
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
double dis,amt,qty,rt;
qty=Double.parseDouble(jTextField1.getText());
rt=Double.parseDouble(jTextField2.getText());
amt=qty*rt;
dis=amt*10/100;
jTextField3.setText(Double.toString(amt));
jTextField4.setText(Double.toString(dis));
}

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


System.exit(0);
}

ABHISHEK AGARWAL

SOLUTION :

ABHISHEK AGARWAL

3. CODING :
int num;
num=Integer.parseInt(jTextField1.getText());
if(num%2==0)
jLabel2.setText("Number is Even");
else
jLabel2.setText("Number is Odd");
}

ABHISHEK AGARWAL

SOLUTION :

ABHISHEK AGARWAL

4. CODING :
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
double dis,amt,qty,rt;
qty=Double.parseDouble(jTextField1.getText());
rt=Double.parseDouble(jTextField2.getText());
amt=qty*rt;
dis=amt*10/100;
jTextField3.setText(Double.toString(amt));
jTextField4.setText(Double.toString(dis));
}

private void
jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
System.exit(0);
}

ABHISHEK AGARWAL

SOLUTION :

ABHISHEK
AGARWAL

5. CODING :
int v,ch;
v=hsc.getValue();
ch=Integer.parseInt(jTextField1.getText() );
lbl1.setText(v+"");
if(v==ch)
l2.setText("Congratulation You Won !!!");
else
l2.setText("Sorry Better Luck next Time");

ABHISHEK AGARWAL

SOLUTION :

ABHISHEK AGARWAL

6. CODING :
int num=0;
String txt;
txt=jTextField1.getText();
num =Integer.parseInt(txt);

if(num%5==0)
jLabel2.setText("This is divisile by five");
else
jLabel2.setText("This is not divisile by five");

ABHISHEK AGARWAL

SOLUTION :

ABHISHEK AGARWAL

7. CODING :
Object [ ] selected = ICList.getSelectedValues( ) ;
int i = 0 ;
int total = 0 ;
int length = selected.length ;
for (i = 0 ; i < length ; ++i ) {
String ic = (String) selected[i] ;
if ( ic.equals("TUTI FROOTI") || ic.equals("KESAR
PISTA")
|| ic.equals("HONEY")
|| ic.equals("CHOCLATE
SHAKE")
|| ic.equals("VANILLA SHAKE"))
{
total = total + 20 ;
}
else
total = total+15 ;
}

Billlbl.setText("YOUR ICE CREAM BILL IS RS.


"+total) ;

ABHISHEK AGARWAL

SOLUTION :

ABHISHEK AGARWAL

8. CODING :
int x=Integer.parseInt(num1JTextField.getText());
int y=Integer.parseInt(num2.getText());
int z=Integer.parseInt(num3.getText());
//determining largest number
int max=0;
max=x;
if (y > max)
max=y;
if (z > max)
max=z;
//setting output
largeLabel.setText(""+max);

ABHISHEK AGARWAL

SOLUTION :

ABHISHEK AGARWAL

9. CODING:
double hi,eng,acc,bst,ip,sst,total,per;
hi=Double.parseDouble(jTextField1.getText());
eng=Double.parseDouble(jTextField2.getText());
acc=Double.parseDouble(jTextField3.getText());
bst=Double.parseDouble(jTextField4.getText());
ip=Double.parseDouble(jTextField5.getText());
sst=Double.parseDouble(jTextField8.getText());
total=hi+eng+acc+bst+ip+sst;
per=total*100/600;
jTextField6.setText(Double.toString(total));
jTextField7.setText(Double.toString(per));

ABHISHEK AGARWAL

SOLUTION :

ABHISHEK AGARWAL

10. CODING :
String txtEntered = ageTF.getText();
int ag = Integer.parseInt(txtEntered);
boolean ans = validate(ag) ;
if (ans == true)
msglbl.setText("THE AGE IS VALID.");
else
msglbl.setText("THE AGE IS NOT VALID.");

ABHISHEK AGARWAL

SOLUTION :

ABHISHEK AGARWAL

You might also like