This program is a command-line based utility for creating shoppers and products (presumably for a store), handling shoppers purchasing products, and displaying information about shoppers and products. It is designed in order to give you an opportunity to:
The whole program will consist of four classes:
private static int nextShopperID = 100; private static int nextProductID = 100;These variables hold the ID numbers to be given to the next shopper created and the next product created, respectively. Because these variables have been declared outside of the methods, they will be available to code inside the methods. Because both shopper IDs and product IDs start at 100, each of the variables is initialized to that. Remember this for later, when it appears in one of the code requirements.
In order to do this part, you will need to know how to call an instance method, with respect to a particular object reference; in this context, that is simply the variable s, for all intents and purposes. In addition, you will need to study the Shopper class to see what methods you should be calling. Pay attention to such details as the method's name and the type of data it gives you. Also, some of the pieces of information you are seeking will not be directly provided by a method -- in which case, you will need to retrieve other information to calculate the result.
The Shopper class already has an instance method that will print the shopper's products for you, though it does not go inside a println like the others. Look for methods in Shopper.java that provide the pieces of information you need. Your job is to figure out the pattern.
In order to do this part, you will need to know how to call an instance method, with respect to a particular object reference; in this context, that is simply the variable p, for all intents and purposes. In addition, you will need to study the Product class to see what methods you should be calling. Pay attention to such details as the method's name and the type of data it gives you. Also, some of the pieces of information you are seeking will not be directly provided by a method -- in which case, you will need to retrieve other information to calculate the result.
The Product class already has an instance method that will print the shoppers for you, though it does not go inside a println like the others. The first piece of information, the title, is already done for you. Look for methods in Product.java that provide the pieces of information you need. Your job is to figure out the pattern.
Click here for a live demonstration of a very similar program in action. The substantive material is different but the overall pattern of interaction and behavior is very close to this one.