Clocks

Report a typo

The given classes are the Clock interface of products, specified clocks, and the factory class ClockFactory to produce instances.

Your task is to implement the factory method produce. It should return a clock according to the specified type string:

  • "Sand" — SandClock;

  • "Digital" — DigitalClock;

  • "Mechanical" — MechanicalClock.

Please, do not change the provided code of the clock classes.

Sample Input 1:

Digital

Sample Output 1:

...pim...
Write a program in Java 17
import java.util.Scanner;

/* Product - Clock */
interface Clock {
void tick();
}

/* Concrete Product - Sand Clock */
class SandClock implements Clock {

@Override
public void tick() {
System.out.println("...sand noise...");
}
}

/* Concrete Product - Digital Clock */
class DigitalClock implements Clock {

@Override
public void tick() {
System.out.println("...pim...");
}
}

/* Concrete Product - Mechanical Clock */
class MechanicalClock implements Clock {

@Override
public void tick() {
System.out.println("...clang mechanism...");
}
}

abstract class ClockFactory {

___

Create a free account to access the full topic