Exercise PHP language [closed]

-5

Someone can help me:

In PHP: Create a class that has two methods; Method 1 calculates the number division module (any number) by an integer (you decide which integer to use); Method 2 will print on the screen the result obtained by the calculation performed in method 1.

    
asked by anonymous 21.01.2018 / 23:00

1 answer

1

It is not the purpose of the site to resolve the issue, but to ask questions. But apparently you're new, so I'll answer your question. We can define this class in many ways, but I chose to do it as easily as possible. Here is the code:

<?php
    class Modulo{

        private $resto;

        public function restoDivisao($matricula, $denominador) {
            $this->resto = $matricula%$denominador;
        }

        public function imprimeResto() {
            echo $this->resto;
        }
    }
?>

Here we define the class that has only one parameter, which is the rest of the division. It is a private parameter, that is, it can only be accessed by the class's own methods. To use this class you can do the following:

$resto = new Modulo;
$resto->restoDivisao(9,4);
$resto->imprimeResto();

First we instantiate the class, creating an object and saving it in the $ rema variable. Then we call métido restoDivisao() , passing as parameters the number of the enrollment (any number) and the divisor. This method does the remainder calculation and saves it to the private attribute. Then we call the imprimeResto() method that takes the attribute we set in the previous method and prints on the screen.

    
21.01.2018 / 23:52