Académique Documents
Professionnel Documents
Culture Documents
He asked
his software programmer to design an interest calculator which the compund interest and
amount due if he takes a loan for 5,10,15 years.
Calculate Interest:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int T=0;
double CI=0,Amount=0;
double P=Double.parseDouble(txtPrincipal.getText());
float R=Float.parseFloat(txtRate.getText());
if(Opt5.isSelected())
T=5;
else
if(Opt10.isSelected())
T=10;
else
if(Opt15.isSelected())
T=15;
//pow()function calculates power of a number
CI=P*Math.pow((1+(R/100)),T);
Amount=P+CI;
txtInterest.setText(String.valueOf(CI));
txtAmount.setText(String.valueOf(Amount);
}
Output:
Q.Write the code for Check Date Button to display where an input date is valid date or
not.Display:If the entered date is valid the message is: Valid date Otherwise the message
is:Invalid date.
Q.Design a GUI application(SumDiff)to input two numbers as in two text boxes(txtN1 and
txtN2)and find their sum and difference by choosing a checkBox from a panel using switch
statment.
Sum:
private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {
int N1,N2,sum=0;
N1=Integer.parseInt(txtN1.getText());
N2=Integer.parseInt(txtN2.getText());
sum=N1+N2;
jLabel3.setText("Sum is:"+sum);
}
Difference:
private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {
int N1,N2,diff=0;
N1=Integer.parseInt(txtN1.getText());
N2=Integer.parseInt(txtN2.getText());
if(N1>N2)
diff=N1-N2;
else
diff=N2-N1;
jLabel3.setText("The diffrence between"+N1+"and"+N2+"is="+diff);
}
Output:
Sum:
Difference:
Q.Write the code for calculate Total , Percentage & Grade button also to display the same in
respective text boxes.
if(per>=50&&per<60)
Gr="D";
else
if(per<50)
Gr="F";
txtTotal.setText(Integer.toString(tot));
txtPer.setText(Float.toString(per));
txtGr.setText(Gr);
}
Output:
Q.Design a GUI application in which the sum of digit of the number should be displayed in a
label control.
Sum of digit:
Q.Write the command for discount button to compute discount amount and net amount.
txtNet.setText(String.valueOf(netamount));
Calculate Table:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int i,j,k;
for(i=1;i<=5;i++){
for(j=1;j<=10;j++){
k=i*j;txtTable.append(""+i+"*"+j+"="+k+"\n");
}
txtTable.append("-------------------\n");
}
Output:
Q.Write a programme to input a string a screen through keyboard and dispaly in reverse
order.
Reverse:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String str;
int value,r_digit;
value=0;
while(value<=0){
value=Integer.parseInt(txtNum.getText());
if(value<=0){
break;
}
}
str="";
while(value!=0){
r_digit=value%10;
str=str+Integer.toString(r_digit);
value=value/10;
}
txtRev.setText(str);
}
Output:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String str;
int value,r_digit;
value=0;
while(value<=0){
value=Integer.parseInt(txtNum.getText());
if(value<=0){
break;
}
Output:
QWrite the code for Calculate Rate button and Calculate Amount Button.
Calclate Rate:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(RB1.isSelected())
txtRate.setText(Integer.toString(1500));
if(RB2.isSelected())
txtRate.setText(Integer.toString(2800));
if(RB3.isSelected())
txtRate.setText(Integer.toString(5000));
Calculate Amount:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
if(Chk1.isSelected())
txtFacility.setText(Integer.toString(7000));
if(Chk2.isSelected())
txtFacility.setText(Integer.toString(2000));
if(Chk3.isSelected())
txtFacility.setText(Integer.toString(1000));
Double.parseDouble(txtDays.getText());
Double.parseDouble(txtFacility.getText());
txtAmount.setText(Double.toString(TAmount));
Output:
Q.Write the code for Calculate button amount are computed and displayed.
Calculate:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
float subTot=0,charge=0,tax=0,Total=0;
int qty=Integer.parseInt(txtQty.getText());
float uPrice=Float.parseFloat(txtPrice.getText());
subTot=qty*uPrice;
tax=subTot*(float)6.5/100;
if(optA.isSelected())
charge=2000;
if(optB.isSelected())
charge=3000;
if(optC.isSelected())
charge=3500;
Total=subTot+tax+charge;
txtSub.setText(String.valueOf(subTot));
txtTax.setText(String.valueOf(tax));
txtCharge.setText(String.valueOf(charge));
txtTotal.setText(String.valueOf(Total));
Output:
Find Armstrong:
Find Factorial:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int num;
float fact=1;
String str=JOptionPane.showMessageDialog("Enter number to find Factorial");
txtNum.setText(str);
num=Integer.parseInt(str);
if(num<=1){
JOptionPane.showMessageDialog(this,"Factorial is 1");
}
do{
fact=fact*num;
num=num-1;
}
while(num>1);
txtFact.setText(Float.toString(fact));
} OUTPUT
Q.The bank provides three types of loan- car loan,house loan,education loan. Calculate
interest amount and discount amount.
Q.Design a GUI application (dtob)to convert decimal number into binary number.
Decimal to binary:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String str,str1="";
int n,r,n1,r_digit,ln,i;
int[]ar;
ar=new int[10];
str=JOptionPane.showInputDialog("ENTER THE DECIMAL NUMBER");
n=Integer.parseInt(str);
n1=n;
str="";
i=0;
while(n!=0){
r=n%2;
n=n/2;
ar[i]=r;
i++;
}
i--;
//Printing the decimal into a decimal number into a text field.
txtd.setText(Integer.toString(n1));
//storing the array in reverse order as binary number
for(int j=i;j>=0;j--)
str1=str1+ar[j];
//printing the binary number
txtb.setText(str1);// TODO add your handling code here:
}
Q. Write code for button to display the list price,discount price and net price.
list price:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String Product=cmbProduct.getSelectedItem().toString();
if (Product.equals("washing machine")){
txtlprice.setText("12000");
}
else if (Product.equals("colour television")){
txtlprice.setText("17000");
}
else if (Product.equals("refrigerator")){
txtlprice.setText("18000");
}
else if (Product.equals("otg")){
txtlprice.setText("8000");
}
else if (Product.equals("cd player")){
txtlprice.setText("14500");
}
}
discount price:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
Float ProductPrice,Discount;
ProductPrice=Float.parseFloat(txtlprice.getText());
if (optfest.isSelected()){
Discount = ProductPrice*7/100;
}
else {
Discount = ProductPrice*10/100;
}
txtdisc.setText(Float.toString(Discount));// TODO add your handling code here:
}
net price:
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
float NetPrice;
NetPrice=Float.parseFloat(txtlprice.getText())- Float.parseFloat(txtdisc.getText());
txtnprice.setText(Float.toString(NetPrice));// TODO add your handling code here:
}
output:
Q. Write code for to calculate rate button and calculate Amount and display it.
Calculate Rate:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(optregular.isSelected())
txtrate.setText(String.valueOf(220));
else if(optpan.isSelected())
txtrate.setText(String.valueOf(260));
Calculate Amount:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
int top=0;
float Amt=0;
if(chkcheese.isSelected()){
top=40;
}
if(chkcapsicum.isSelected()){
top=top+20;
}
if(chkPepperonion.isSelected()){
top=top+25;
}
txttop.setText(Integer.toString(top));
Amt=(Integer.parseInt(txtrate.getText())+top)*Integer.parseInt(txtqty.getText());
txtamt.setText(Float.toString(Amt));
}