خرید بک لینک

Vote count: 0

I have created the following java program. Its basic functionality is to perform addition, subtraction, multiplication, division and modular division on two numbers.

I have implemented the concept of object oriented programming but it is missing encapsulation.

How to introduce encapsulation in it? My code is:

/*
 * To change this license header, choose License Headers in Project    Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author piyali
 */



public class Calculator {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
    int x, y;
    x = 13;
    y = 5;

    calculation add = new calculation();
    calculation sub = new calculation();
    calculation mul = new calculation();
    calculation div = new calculation();
    calculation mod = new calculation();

    int addResult = add.addition(x, y);
    int subResult = sub.subtraction(x, y);
    int mulResult = mul.multiplication(x, y);
    int divResult = mul.division(x, y);
    int modResult = mod.modularDivision(x, y);

    System.out.println("The addition of the numbers is " +addResult);
    System.out.println("The subtraction of the two numbers is " +subResult);
    System.out.println("The multiplication of the two numbers is " + mulResult);
    System.out.println("The division of the two numbers is " +divResult);
    System.out.println("The modular division of the two numbers is " + modResult);

}

}

class calculation {

int addition(int x, int y){
    int z;
    z = x + y;
    retu(z);
}

int subtraction(int x, int y){
    int z;
    z = x - y;
    retu(z);
}

int multiplication(int x, int y){
    int z;
    z = x * y;
    retu(z);
}

int division(int x, int y){
    int z;
    z = x / y;
    retu(z);
}

int modularDivision(int x, int y){
    int z;
    z = x % y;
    retu(z);
}
}

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 17 مرداد 1395 ساعت: 23:20

صفحه بندی