Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package E03_ShoppingSpree;
- public class Product {
- private String name;
- private double cost;
- public Product(String name, double cost) {
- this.setName(name);
- this.setCost(cost);
- }
- public String getName() {
- return name;
- }
- private void setName(String name) {
- if (name == null || name.trim().isEmpty()){
- throw new IllegalArgumentException("Name cannot be empty");
- }
- this.name = name.trim();
- }
- public double getCost() {
- return cost;
- }
- private void setCost(double cost) {
- if (this.cost < 0){
- throw new IllegalArgumentException("Money cannot be negative");
- }
- this.cost = cost;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement