It File
It File
a=Integer.parseInt(n1.getText());
b=Integer.parseInt(n2.getText());
c=a+b;
txtRes.setText(""+c);
}
//Code to perform Subtraction
private void rbSUBActionPerformed(java.awt.event.ActionEvent evt)
{
int a,b,c;
if (rbSUB.isSelected()) // Now state of subtract radio button will be true
{
rbADD.setSelected(false); /*
rbMUL.setSelected(false);
rbDIV.setSelected(false); set state of others radio buttons to false
rbREM.setSelected(false); */
a=Integer.parseInt(n1.getText());
b=Integer.parseInt(n2.getText());
c=a-b;
txtRes.setText(""+c);
}
}
a=Integer.parseInt(n1.getText());
b=Integer.parseInt(n2.getText());
c=a*b;
txtRes.setText(""+c);
}
}
//Code to perform division
private void rbDIVActionPerformed(java.awt.event.ActionEvent evt)
{
int a,b;
float c;
if (rbDIV.isSelected()) //Now state of division radio button is set to true
{
rbADD.setSelected(false); /*
rbSUB.setSelected(false); Same code
rbMUL.setSelected(false);
rbREM.setSelected(false); */
a=Integer.parseInt(n1.getText());
b=Integer.parseInt(n2.getText());
c=(float)a/b;
txtRes.setText(""+c);
}
}
//Code to find out remainder
private void rbREMActionPerformed(java.awt.event.ActionEvent evt)
{
int a,b,c;
if (rbREM.isSelected()) //Now state of remainder radio button is set to true
{
rbADD.setSelected(false); /*
rbSUB.setSelected(false); Same code
rbMUL.setSelected(false);
rbDIV.setSelected(false); */
a=Integer.parseInt(n1.getText());
b=Integer.parseInt(n2.getText());
c=a%b;
txtRes.setText(""+c);
}
#9: Design a GUI application to accept marks of 5 subjects and find out the total,
percentage and also display grade depending on the percentage.
//Code to calculate the total of five subjects
private void btnTotalActionPerformed(java.awt.event.ActionEvent evt)
{ int s1,s2,s3,s4,s5,total;
s1=Integer.parseInt(txtEnglish.getText());
s2=Integer.parseInt(txtMath.getText());
s3=Integer.parseInt(txtScience.getText());
s4=Integer.parseInt(txtSST.getText());
s5=Integer.parseInt(txtIT.getText());
total=s1+s2+s3+s4+s5;
txtTotal.setText(total+"");
}
//Code to find out the Percentage and analyze the grade on the basis of percentage via
if-else-if statement
private void btnPerActionPerformed(java.awt.event.ActionEvent evt)
{ float per;
per=Float.parseFloat(txtTotal.getText())/5;
txtPer.setText(per+"");
if(per>=90)
lbl2.setText("A+");
else if (per>=85 && per<90)
lbl2.setText("A");
else if(per>=80 && per<85)
lbl2.setText("B+");
else if(per>=75 && per<80)
lbl2.setText("B");
else
lbl2.setText("C");
}
#10: Design a GUI application to check whether the entered character is Vowel or
Consonant
private void btnChkActionPerformed(java.awt.event.ActionEvent evt)
{
char ch;
ch=txtChar.getText().charAt(0);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
txtChar.setText("It is a Vowel");
else
txtChar.setText("It is a consonant");
}
//Code to clear the textbox.
private void txtClearActionPerformed(java.awt.event.ActionEvent evt)
{
txtChar.setText("");
}
Q: What will happen if you will input vowel in capital letter?
Ans: You have to write conditions for both small and capital letters like:
if( (ch=='a'|| ch==’A’) || (ch=='e'|| ch==’E’) || (ch=='i' || ch==’I’) || (ch=='o'||ch==’O’) ||
(ch=='u' || ch==’U’) )
txtChar.setText("It is a Vowel");
else
txtChar.setText("It is a consonant");
#11: Design a GUI application to find out greatest among three numbers by using
Logical and relational Operators
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int a,b,c;
a=Integer.parseInt(txtNum1.getText()); //code to convert string to integer
b=Integer.parseInt(txtNum2.getText());
c=Integer.parseInt(txtNum3.getText());
if(a>b&&a>c)
lbl.setText(a+" is greatest");
else if(b>a&&b>c)
lbl.setText(b+" is greatest");
else
lbl.setText(c+" is greatest");
}
#12 Design a GUI application to check whether the year is leap year or not.
private void btn1ActionPerformed(java.awt.event.ActionEvent evt)
{
int year;
year=Integer.parseInt(txt1.getText());
if(year%400==0||(year%4==0&&year%100!=0))
txt2.setText("leap year");
else
txt2.setText("not a leap year");
}
Write a SQL query to create database