Member-only story
Java Interview Practice Problem (Beginner): Generate Sample Data
Java interview problem helps to learn how to generate sample data.
2 min readSep 11, 2023
🚀 🚀
Introducing the Everything Bundle — your one-stop solution to mastering Java, Spring Boot, SQL, acing interviews, and securing certifications!
>>
Problem Statement
We have been given an input number n and our task is to generate n orders that will be used for testing.
DTO for Order, Customer, and Product are given below.
@AllArgsConstructor
@Data
class Product{
long id;
String name;
String SKU;
}
@AllArgsConstructor
@Data
class Customer{
long id;
String name;
long age;
}
@AllArgsConstructor
@Data
class Order{
long id;
long productId;
long customerId;
}
Output should look like below
[
Order(id=1, productId=1, customerId=0),
Order(id=2, productId=0, customerId=1),
Order(id=3, productId=0, customerId=2),
......
]
Before jumping to solution consider giving an attempt.