Write a program for validating the fields java program
Answers
import java.util.*;
class Term_deposit
{
public static void main (String args[])
{
Scanner in = new Scanner(System.in);
{
System.out.println("enter the sum in term deposit scheme");
int p=in.nextInt();
System.out.println("enter the age of the customer");
int age=in.nextInt();
System.out.println("enter the term");
int t =in.nextInt();
double i = in.nextDouble ;
double amtp = int.nextDouble();
{
if ( age < 60)
{
if
{
if(t<=1)
i = p*7.5*t/100;
if (t <=2)
i = p*8.5*t/100;
if (t <=3)
i=p*9.5*t/100;
if(t < 3)
i=p*10.0*t/100;
}
else
{
if ( t <=1)
i = p*8.0*t/100;
if (t <=2)
i = p*9.0*t/100;
If( t <=3)
i=p*10.0*t/100;
If(t< 3)
i=p*11.0*t/100;
}
amtp= p- i;
System.out.println(/t"Amount deposited"/t"Term"/t"Age"/t"Interest"/t"Amount paid"/t);
System.out.println(/t+p+/t+ t +/t+i+/t+amtp/t");
}}}
Answer:
public class Main extends JFrame {
private JTextField textField1 = new JTextField();
private JTextField textField2 = new JTextField();
public Main() {
setSize(200,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(textField1, BorderLayout.NORTH);
add(textField2, BorderLayout.SOUTH);
textField1.setInputVerifier(fieldVerifier);
}
InputVerifier fieldVerifier = new InputVerifier() {
@Override
public boolean verify(JComponent input) {
JTextField temp = (JTextField)input;
try {
int number = Integer.parseInt(temp.getText());
return true;
}
catch(NumberFormatException e) {
JOptionPane.showMessageDialog(null, "You MUST input only numbers!");
}
return false;
}
};
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new Main().setVisible(true);
}
};
}
}