* @(#)AllinOne.java
*
*
* @author -> Anant Mahale
* @version 1.00 2013/5/11
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class AllinOne extends JFrame implements ActionListener
{
private Button btn_add,btn_subtract,btn_mul,btn_div,btn_arm_strong_number,btn_palindrom,btn_prime,btn_factorial,btn_sum_digit;
public AllinOne()
{
setLayout(null);
setTitle("Operation");
setSize(500,500);
setLocation(200,200);
btn_add=new Button("Addition");
btn_add.setBounds(50,50,150,30);
btn_add.addActionListener(this);
add(btn_add);
btn_subtract=new Button("Subtract");
btn_subtract.setBounds(50,100,150,30);
btn_subtract.addActionListener(this);
add(btn_subtract);
btn_mul=new Button("Multiplication");
btn_mul.setBounds(50,150,150,30);
btn_mul.addActionListener(this);
add(btn_mul);
btn_div=new Button("Division");
btn_div.setBounds(50,200,150,30);
btn_div.addActionListener(this);
add(btn_div);
btn_arm_strong_number=new Button("ArmStrong Number");
btn_arm_strong_number.setBounds(250,50,150,30);
btn_arm_strong_number.addActionListener(this);
add(btn_arm_strong_number);
btn_palindrom=new Button("Palindrom");
btn_palindrom.setBounds(250,100,150,30);
btn_palindrom.addActionListener(this);
add(btn_palindrom);
btn_prime=new Button("Prime");
btn_prime.setBounds(250,150,150,30);
btn_prime.addActionListener(this);
add(btn_prime);
btn_factorial=new Button("Factorial");
btn_factorial.setBounds(250,200,150,30);
btn_factorial.addActionListener(this);
add(btn_factorial);
btn_sum_digit=new Button("Sum Of Digit");
btn_sum_digit.setBounds(150,250,150,30);
btn_sum_digit.addActionListener(this);
add(btn_sum_digit);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btn_add)
{
String fn=JOptionPane.showInputDialog(this,"Enter the first number");
String sn=JOptionPane.showInputDialog(this,"Enter the Second number");
int fno=Integer.parseInt(fn);
int sno=Integer.parseInt(sn);
int sum=fno+sno;
JOptionPane.showMessageDialog(this,"Addition - "+sum);
}
if(ae.getSource()==btn_subtract)
{
String fn=JOptionPane.showInputDialog(this,"Enter the first number");
String sn=JOptionPane.showInputDialog(this,"Enter the Second number");
int fno=Integer.parseInt(fn);
int sno=Integer.parseInt(sn);
int sub=fno-sno;
JOptionPane.showMessageDialog(this,"Subtract - "+sub);
}
if(ae.getSource()==btn_mul)
{
String fn=JOptionPane.showInputDialog(this,"Enter the first number");
String sn=JOptionPane.showInputDialog(this,"Enter the Second number");
int fno=Integer.parseInt(fn);
int sno=Integer.parseInt(sn);
int mul=fno*sno;
JOptionPane.showMessageDialog(this,"Multiplication - "+mul);
}
if(ae.getSource()==btn_div)
{
String fn=JOptionPane.showInputDialog(this,"Enter the first number");
String sn=JOptionPane.showInputDialog(this,"Enter the Second number");
int fno=Integer.parseInt(fn);
int sno=Integer.parseInt(sn);
int div=fno/sno;
JOptionPane.showMessageDialog(this,"Division - "+div);
}
if(ae.getSource()==btn_arm_strong_number)
{
int rem,n,no,div,arm=0;
String str_num=JOptionPane.showInputDialog(this,"Enter the number to check it is Armstrong or not");
n=Integer.parseInt(str_num);
no=n;
while(n!=0)
{
rem=n%10;
div=n/10;
arm=arm+(rem*rem*rem);
n=div;
}
if(arm==no)
{
JOptionPane.showMessageDialog(this,no+" is armstromg");
}
else
{
JOptionPane.showMessageDialog(this,no+" is not armstromg");
}
}
if(ae.getSource()==btn_palindrom)
{
int n,no,rem,rev=0;
String str_num=JOptionPane.showInputDialog(this,"Enter the number to check it is Palindrom or not");
n=Integer.parseInt(str_num);
no=n;
while(no!=0)
{
rem=no%10;
rev=rev*10+rem;
no=no/10;
}
if(rev==n)
{
JOptionPane.showMessageDialog(this,n+" is palindrom ");
}
else
{
JOptionPane.showMessageDialog(this,n+" is not palindrom ");
}
}
if(ae.getSource()==btn_prime)
{
int i,no,a=1;
String str_num=JOptionPane.showInputDialog(this,"Enter the number to check it is Palindrom or not");
no=Integer.parseInt(str_num);
for(i=2;i<no;i++)
{
if(no%i==0)
{
a=0;
break;
}
else
{
a=1;
}
}
if(a==1)
{
JOptionPane.showMessageDialog(this,no+" is prime");
}
else
{
JOptionPane.showMessageDialog(this,no+" is not prime");
}
}
if(ae.getSource()==btn_factorial)
{
int n,no,f=1;
String str_num=JOptionPane.showInputDialog(this,"Enter the number to check it is Palindrom or not");
n=Integer.parseInt(str_num);
no=n;
while(n>0)
{
f=f*n;
n--;
}
JOptionPane.showMessageDialog(this,"factorial of "+no+" is = "+f);
}
if(ae.getSource()==btn_sum_digit)
{
int sum=0,n,no,rem;
String str_num=JOptionPane.showInputDialog(this,"Enter the number to check it is Palindrom or not");
n=Integer.parseInt(str_num);
no=n;
while(no!=0)
{
rem=no%10;
sum=sum+rem;
no=no/10;
}
JOptionPane.showMessageDialog(this,n+" of sum of digit is "+sum);
}
}
}
class AllinOnePro
{
public static void main(String args[])
{
new AllinOne().setVisible(true);
}
}
No comments:
Post a Comment