hey can i get ur help guys plz i really need u
i dunno how to use the hell java thing
so i can i get ur help i have to make a calculator
here u r my assignment
____________
1.Create a class Calculator in VisualAge with the following members:
Private Fields:
int number1;
int number2;
Public methods:
int add()
int sub()
int mul()
float div()
Constructor:
Calculator( ) //default constructor
Calculator(int x, int y)
2. Implement the above methods and constructors. In the default
constructor, set number1 and number2 to zero.
3. Handle the ArithmeticException in div ( ) method
4. Create a driver class to test the Calculator class.
_______________________
package Calculator;
public class Calculator{
private int num1, num2; //private field
public Calculator(int x, int y) { //constructor
this.num1=x; this.num2=y;
}
public int add(){
return num1+num2;
}
public int sub(){
return num1-num2;
}
public int mul(){
return num1*num2;
}
public float div(){
return num1/num2;
/* if (num2==0) {
System.out.println("Undefined");}*/ //if it is divied by 0 the result
is undefined
}
}
package Calculator;
import java.io.*;
import java.math.*;
public class driver {
public static void main(String[] args) {
System.out.println("Enter the 1st #");
String n1="";
int num1=0;
System.out.println("Enter the 2nd #");
String n2="";
int num2=0;
try{
BufferedReader br = new BufferedReader(new InputStreamReader
(System.in));
n1=br.readLine();
}catch(IOException e){
System.out.println("Input Error ");
try{
BufferedReader br = new BufferedReader(new InputStreamReader
(System.in));
n2=br.readLine();
}catch(IOException e){
System.out.println("Input Error ");
}
num1=Integer.parseInt(n1);
Calculator Calc =new Calculator(num1); // Create an object.
num2=Integer.parseInt(n2);
Calculator Calc =new Calculator(num2); // Create an object.
int a = Calc.add();
int s = Calc.sub();
int m = Calc.mul();
float d = Calc.div();
System.out.println("add \t" + a);
System.out.println("sub \t" + s);
System.out.println("mul \t" + m);
System.out.println("div \t" + d);
}
}