• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help creating an array?  RSS feed

 
nicole poirier
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the assignment:
Using Eclipse, create a class Product which has a String field called company that refers to the constant string "Tech Industries". It also has a String field name that refers to the product name, as well as an int field serNo containing the serial number of the product. The constructor takes one parameter, being the name of the product, and initializes that field. It also initializes the serNo field in the following way: The serial numbers start with 1001, and each next product generated gets a serial number that is one larger than the previous product. The constructor will therefore need to remember what the next serial number has to be. The class also contains a method toString with no parameter that returns a String that contains the company name, the product name, and the product serial number, along with appropriate labels.

Then create a Tester method with the regular main method that starts up the program. It should create an array Product[ ] that is initialized with three Product objects. Then print out the objects in the array using a loop.

my code for the product class is as follows:


I'm stuck on the tester class, I'm not sure how to write the array initialized to three objects?
so far this is what I have(which isn't much):
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are explanations and examples here: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nicole poirier wrote:
so far this is what I have(which isn't much):

I would not recommend calling the constructor with the null argument. That will only lead to problems and bad implementation.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!