Converting a DTO to a Java class implementation

Report a typo

You have a class called Product in your project:

class Product {
    private long id;
    private String model;
    private int price;
    private LocalDate dateOfArrival;
    private String vendor;

    public Product(long id, String model, int price, LocalDate dateOfArrival, String vendor) {
        this.id = id;
        this.model = model;
        this.price = price;
        this.dateOfArrival = dateOfArrival;
        this.vendor = vendor;
    }

    public Product() {}

    //getters and setters
}

The DTO of the class looks like this:

class ProductDTO {
    private long id;
    private String model;
    private int price;
    
    //constructors, getters, and setters
}

Write a function that converts a ProductDTO to a Product object. Your company has only one vendor named "SuperVendor" so far. The date of arrival is the 15th of January, 2023.

Sample Input 1:

No input.

Sample Output 1:

Good job!
Write a program in Java 17
import java.time.LocalDate;

class Solution {
Product convertProductDTOToProduct(ProductDTO dto) {
// write your code here
}
}

// do not change the code given below
class Product {
private long id;
private String model;
private int price;
private LocalDate dateOfArrival;
private String vendor;

public Product(long id, String model, int price, LocalDate dateOfArrival, String vendor) {
this.id = id;
this.model = model;
this.price = price;
this.dateOfArrival = dateOfArrival;
this.vendor = vendor;
}

public Product() {}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getModel() {
return model;
___

Create a free account to access the full topic