public class Product { // our attributes: name, price, code, number, category private String name; private double price; private int code; private int number; private String category; // constructor (takes as arguments: name, price, code, category) // and initializes number to 0 (we mean to have initially no item in store) public Product(String n, double p, int c, String cat) { name = n; price = p; code = c; category = cat; number = 0; } // 5 get methods public String getName() { return name; } public double getPrice() { return price; } public int getCode() { return code; } public int getNumber() { return number; } public String getCategory() { return category; } // buy method (takes as argument the number of items the shop buys) // buy has no return value public void buy(int k) { number += k; } // sell method (takes as argument the number of items the shop sells = n) // it decreases number by n, if number >= n // or it sets number to 0, if number < n // the return value should be the number of items actually sold public int sell(int n) { // i have *number* items // the user wants to get *n* if (number >= n) { // ok, have enough -> I'm going to give away n number -= n; return n; } else { // oops, i'm going to give away number number = 0; return number; } } // sell() ends here! }