Java Code Assessment
Tasks:
- Write class that implements below interface. Write a function (using Java syntax) that prints out the numbers 1 to 500 with the following constraints:
- For multiples of six print "Fizz" instead of the number.
- For multiples of ten print "Buzz".
- For numbers which are multiples of both six and ten print "FizzBuzz".
public interface IFizzBuzz {
public void doFizzBuzz();
}- Write an implementation of the Reverser interface which takes two strings and returns true if and only if the first string is the reverse of the second string. Multiple different implementations are encouraged.
- Example: isReverse("abc", "cba") returns true
- Example: isReverse("abc", "xyz") returns false
public interface Reverser
{
public boolean isReverse(String string1, String string2);
}- Write a "Square" class that implements the below Shape interface. Multiple different implementations are encouraged.
public interface Shape
{
public int perimeter();
public int area();
}- Write an implementation of the Fibonacci interface which computes the Nth Fibonacci number. Multiple different implementations are encouraged.
getFibonacci(n) = sum of last two Fibonacci numbers.
- getFibonacci(0) = 0
- getFibonacci(1) = 1
- getFibonacci(2) = 1
- getFibonacci(3) = 2
- getFibonacci(4) = 3
public interface Fibonacci
{
public int getFibonacci(int n);
}- Write a program to print all prime numbers from 1 to 100. A prime number is a number which is greater than 1 and only divisible by 1 or itself. Please use the interface below to determine if a number is prime for your program.
Examples:
- isPrime(5) returns true.
- isPrime(6) returns false.
Interface:
public abstract interface PrimeNumber
{
public boolean isPrime(int number);
}