This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* array_map() | |
* | |
* Round up array values | |
* Use array_map() with built-in ceil functions | |
* The result array $mapped will be [2, 3, 4] | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Given the users $role and access $rights ... | |
* Check if Mike has admin rights and downgrade him | |
* Wrong approach: | |
* if ($is_admin && $can_edit_articles ... | |
*/ | |
$rights = (object) ["read"=>1, "write"=>2, "readwrite"=>16, "admin"=> 32]; | |
$role = (object) ["jim"=>96, "mike"=>32]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Define Dog class using supertype Animal | |
* Use safeguard annotation. | |
*/ | |
class App { | |
public static void main(String[] args) { | |
Dog d = new Dog(); | |
d.test(); // Dog | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Define MyMath.floor() method using java.lang.math method | |
class App { | |
public static void main(String[] args) { | |
double n = MyMath.floor(12.3); | |
System.out.print(n); // 12.0 | |
} | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Define abstact class Animal | |
* Class Animal contains two methods, eat() and showName() | |
* One of the method is abstract | |
*/ | |
class App { | |
public static void main(String[] args) { | |
Dog d = new Dog(); | |
d.setName("MyDog"); | |
System.out.println(d.name); // MyDog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Define Dog class which | |
* Dog class must implement the correct class | |
*/ | |
class App { | |
public static void main(String[] args) { | |
Dog d = new Dog(); | |
d.bark(); // The dog is barking | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Write constructor and method for Output class. | |
* The output() prints the <name> instance variable | |
*/ | |
class App { | |
public static void main(String[] args) { | |
Output o = new Output("John"); | |
o.output(); // John | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Define class constructor and ... | |
* Display the constructor method name | |
*/ | |
$obj = new A(); | |
class A | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Import libraries required by the following code | |
*/ | |
/** | |
* SOLUTION | |
*/ | |
import java.util.List; | |
import java.util.ArrayList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This code will throw an Exception Error | |
* Correct the error line | |
*/ | |
class App { | |
public static void main(String[] args) { | |
/** | |
* SOLUTION |