Section 1
Create a [Link] file and implement the following function.
From a given array of natural numbers, return the distance between the two closest numbers.
import [Link].*;
public class Main {
// Returns the distance between the two closest numbers.
static int distanceClosestNumbers(int[] numbers) {
// Code here
}
public static void main(String[] args) {
int[] a= {2, 9, 40, 15, 84, 7,83, 35};
[Link](distanceClosestNumbers(a));
// Expected result is 1 (the 2 closest numbers are 84 and 83)
}
}
Section 2
Tech Stacks: Java Spring Boot + MySql/MongoDB (Choose one)
Go to Spring Initializr ([Link] for your starter template. Add Spring Web MVC
and any required dependency.
User
1. Create a User object class which has a name, phone number, age, gender and
nationality.
2. Create a controller with a few REST Api as listed below:
○ Create user
○ Get all users
○ Get user by name/id
○ Update user
○ Delete user
Order
1. Create an Order object class which has an id, buyer (user), total and paid at.
2. Create a controller with a few REST Api as listed below:
○ Get all orders
○ Get order by id
○ Create order
○ Update order
○ Delete order
Extra
1. Make a REST Api to get orders by user
2. Make a REST Api to get total orders by user
You may test the API by using any HTTP client (preferably Postman)
How to submit:
Compress a folder with the [Link] file (Section 1) and the Java Spring Boot project (Section
2)