0% found this document useful (0 votes)
5 views2 pages

Java Closest Numbers & Spring Boot API

The document contains instructions for two coding exercises. Section 1 describes a function that takes an array as input and returns the distance between the two closest numbers. Section 2 provides guidelines for building a basic Spring Boot application with REST APIs for performing CRUD operations on User and Order objects that have a one-to-many relationship. The completed work is to be compressed and submitted as a single folder containing the Main.java file from Section 1 and the Spring Boot project from Section 2.

Uploaded by

Mawar Lia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Java Closest Numbers & Spring Boot API

The document contains instructions for two coding exercises. Section 1 describes a function that takes an array as input and returns the distance between the two closest numbers. Section 2 provides guidelines for building a basic Spring Boot application with REST APIs for performing CRUD operations on User and Order objects that have a one-to-many relationship. The completed work is to be compressed and submitted as a single folder containing the Main.java file from Section 1 and the Spring Boot project from Section 2.

Uploaded by

Mawar Lia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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)

You might also like