Saturday, 22 October 2011

INTEREST CALCULATOR PROGRAM USING JAVA

INTEREST CALCULATOR PROGRAM IN JAVA USING AWT

import java.awt.*;
import java.awt.event.*;

class InterestCalci extends Frame implements ItemListener
{
  Label l1,l2,l3,l4;
  TextField t1,t2,t3,t4;
  Checkbox c1,c2,c3;
  CheckboxGroup cbg; 
  public InterestCalci()
  {
    //Super(new Frame(),"RadioCalci");
    setLayout(new FlowLayout());
    setSize(300,300);
    setTitle("RadioCalculator");

    l1 = new Label("principle");
    l2 = new Label("rate");
    l3 = new Label("time");
    l4 = new Label("S.I.");     
    t1 = new TextField(10);
    t2 = new TextField(10);
    t3 = new TextField(10);
    t4 = new TextField(10);
    cbg = new CheckboxGroup();
    c1 = new Checkbox("calculaton",cbg,false);   
    c2 = new Checkbox("reset",cbg,false);
    c3 = new Checkbox("close",cbg,false);

    add(l1);   
    add(t1);
    add(l2);
    add(t2);
    add(l3);
    add(t3);
    add(l4);
    add(t4);
    add(c1);   
    add(c2);
    add(c3);

    c1.addItemListener(this);
    c2.addItemListener(this);
    c3.addItemListener(this);
  }

public void itemStateChanged(ItemEvent ie)
{
    double a=0,b=0,c=0,d=0;
    try
    {
      a = Double.parseDouble(t1.getText());
    }
    catch(Exception e)
    {
      t1.setText("Invalid Text");
    }
    try
    {
      b = Double.parseDouble(t2.getText());
    }
    catch(Exception e)
    {
      t2.setText("Invalid Text");
    }
    try
    {
      c = Double.parseDouble(t3.getText());
    }
    catch(Exception e)
    {
      t3.setText("Invalid Text");
    }
    if(ie.getSource()==c1)               
    {
       d = (a*b*c)/100;
       t4.setText((String.valueOf(d));
    }
    if(ie.getSource()==c2)               
    {
       t1.setText("0");
       t2.setText("0");
       t3.setText("0");
       t4.setText("0");
    }
    if(ie.getSource()==c3)               
    {
       System.exit(0);
    }
}
}
class InterestCalciDemo
{
public static void main(String args[])
{
     InterestCalci c = new InterestCalci();
     c.setVisible(true);
     c.setLocation(500,300);
}
}

0 comments:

Post a Comment

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel