Detail manufacturing

Report a typo

John decided to create a manufacturing firm. It produces various, mainly mechanical details. John wants to automate details producing requests, but sadly he cannot write code. He asks you to write a simple manufacturing controller.

You are given two methods, requestProduct and getNumberOfProducts:

  1. getNumberOfProducts should return the total number of requested products;
  2. requestProduct should keep track of requested products, and format the product argument in the format: No. Requested Detail.


For example:

ManufacturingController.requestProduct("detail 1");

should return:

1. Requested detail 1

and

ManufacturingController.requestProduct("Wrench");

should return:

2. Requested Wrench

After execution of these two commands,

ManufacturingController.getNumberOfProducts();

should return:

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

class ManufacturingController {
// here you may declare a field

public static String requestProduct(String product) {
// write your code here
}

public static int getNumberOfProducts() {
// write your code here
}
}

class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

while (scanner.hasNextLine()) {
String product = scanner.nextLine();
System.out.println(ManufacturingController.requestProduct(product));
System.out.println(ManufacturingController.getNumberOfProducts());
}
}
}
___

Create a free account to access the full topic