Java Reference
In-Depth Information
id, lastName, firstName,
street, city);
}
}
Recall that you can use the “Generate Getters and Setters. . .” function under “Source” when right‐
clicking in Eclipse's code window to generate getter and setter methods. Note also that here the
String.format method is used to format the string representation in the toString method. This is
a more readable alternative than having to work with long, concatenated strings.
Next up, create a class to represent a product:
package com.thomasbayer.sqlrest;
public class Product {
private int id;
private String name;
private double price;
public Product(int id) {
this.id = id;
}
public Product(int id, String name, double price) {
this(id);
this.name = name;
this.price = price;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String toString() {
return String.format(
"Product #%s: %s: priced at %s",
id, name, price);
}
Search WWH ::




Custom Search