Create the following Java classes that are used in Restful service.
Book.java
Book class represents a book. It contains id, title and price properties.
package rest;
import javax.xml.bind.annotation.XmlRootElement;
public class Book {
private int id;
private String title;
private double price;
public Book() {
}
public Book(int id, String title, double price) {
super();
this.id = id;
this.title = title;
this.price = price;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
Books.java
Books class creates a set of Book objects. To keep it simple, I am creating a few objects and putting them in an ArrayList.
package rest;
import java.util.ArrayList;
import java.util.List;
public class Books {
private static ArrayList<Book> books = new ArrayList<>();
static {
books.add(new Book(1, "The Outliers", 500));
books.add(new Book(2, "World Is Flat", 550));
}
public static List<Book> getBooks() {
return books;
}
}