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