Project Detail: Create calculator application which accepts two numbers from user and perform addition, subtraction, multiplication and division on given numbers.
-------------------------- * -----------------------------
-------------------------- * -----------------------------
Source: Calculation.java
package calculator;
public class Calculation {
int result;
//Method for
addition
public int add(int num1, int num2){
result = num1+num2;
return result;
}
//Method for
subtraction
public int substract(int num1, int num2){
result = num1-num2;
return result;
}
//Method for
multiplication
public int multiply(int num1, int num2){
result = num1*num2;
return result;
}
//Method for
division
public float divide(int num1, int num2){
result = num1/num2;
return result;
}
}
Source: CalculatorVO.java
package calculator;
public class CalculatorVO {
private int firstNumber;
private int secondNumber;
public int
getFirstNumber() {
return firstNumber;
}
public void setFirstNumber(int firstNumber) {
this.firstNumber = firstNumber;
}
public int
getSecondNumber() {
return secondNumber;
}
public void
setSecondNumber(int secondNumber) {
this.secondNumber = secondNumber;
}
}
Source: MainClass.java
package calculator;
public class MainClass {
public static void main(String[] args) {
CalculatorVO
calVO = new CalculatorVO();
//Input can be
taken from user
calVO.setFirstNumber(100);
calVO.setSecondNumber(11);
Calculation
cal = new Calculation();
int addResult = cal.add(calVO.getFirstNumber(),
calVO.getSecondNumber());
System.out.println("Addition
Result ="+addResult);
int subResult = cal.substract(calVO.getFirstNumber(),
calVO.getSecondNumber());
System.out.println("Subtraction
Result ="+subResult);
int mulResult = cal.multiply(calVO.getFirstNumber(),
calVO.getSecondNumber());
System.out.println("Multiplication
Result ="+mulResult);
float divResult = cal.divide(calVO.getFirstNumber(),
calVO.getSecondNumber());
System.out.println("Division
Result ="+divResult);
}
}
OUTPUT:
Addition Result =111
Subtraction Result =89
Multiplication Result =1100
Division Result =9.0
Hey Very nice Blog,Thanks For Sharing..
ReplyDeleteCore Java Online Training Hyderabad