You are on page 1of 5

Calcutor

With OBJECT-ORIENTED approach


- Sir JOHN
Main Class
public class Calculator {

public static void main(String[] args) {

acceptInput askInput = new acceptInput();


askInput.Input();
}
}
AcceptInput Class
class acceptInput
{
int n1, n2;
int s;
float q;
public void Input()
{
n1=Integer.parseInt(JOptionPane.showInputDialog("Enter 1st number: "));
n2=Integer.parseInt(JOptionPane.showInputDialog("Enter 2nd number: "));

addition sum = new addition();

s=sum.add(n1,n2);

output out = new output();


out.labas(s);
}
}
Add Class
class addition
{
int add(int a, int b)
{
int s;
s=a+b;
return s;
}
}
Output CLass
class output
{
void labas(int a)
{
System.out.println("The sum is " + a);
}
}

You might also like