Motor static factory

Report a typo

In the very heart of suburbia, there stood a motor factory; in the very heart of that factory worked a programmer. Implement the static method make of the MotorStaticFactory that produces motors of different types. The method takes three parameters: the type of a motor as a character, model as a string, and power as a long number. It should return a new motor according to the type with initialized fields.

Here is the correspondence between the passed type and the class of the motor: 'P' for pneumatic, 'H' for hydraulic, 'E' for electric and 'W' for warp. Ignore the upper/lower case when creating motors, i.e. 'p' must work as well as 'P'. If an invalid character is given, the method should return null.

Do not change the provided code of the motor classes.

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

class MotorStaticFactory {

/**
* It returns an initialized motor according to the specified type by the first character:
* 'P' or 'p' - pneumatic, 'H' or 'h' - hydraulic, 'E' or 'e' - electric, 'W' or 'w' - warp.
*/
public static Motor make(char type, String model, long power) {
// write your code here
}
}

/* Do not change code below */
class Motor {

String model;
long power;

public Motor(String model, long power) {
this.model = model;
this.power = power;
}
}

class PneumaticMotor extends Motor {

public PneumaticMotor(String model, long power) {
super(model, power);
}
}

class HydraulicMotor extends Motor {

public HydraulicMotor(String model, long power) {
super(model, power);
___

Create a free account to access the full topic