Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList in Java printing values  RSS feed

 
Aaron Boyse
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this Java program that I am trying to get running in NetBeans:



I would like to know as to whether or not, there is a need for multiple arrayLists and how to get it working?
 
Dave Tolls
Rancher
Posts: 2913
35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to detail what it is you are trying to achieve with this code.
It's not obvious, I'm afraid.

For example you create 2 Phone objects, but do nothing with them except call some methods.
I'm not sure what those method calls are supposed to do, as you seem to have setters (for example setName()) that take no parameters.
You also use getters (for example getCharge()) but do nothing with any returned value.

And then you have some Lists and and array, and nothing really happens with them.

So, if you could explain what you need then I think we can work towards a solution.
 
Aaron Boyse
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:I think you need to detail what it is you are trying to achieve with this code.
It's not obvious, I'm afraid.

For example you create 2 Phone objects, but do nothing with them except call some methods.
I'm not sure what those method calls are supposed to do, as you seem to have setters (for example setName()) that take no parameters.
You also use getters (for example getCharge()) but do nothing with any returned value.

And then you have some Lists and and array, and nothing really happens with them.

So, if you could explain what you need then I think we can work towards a solution.


I'm asking, is there a need for all the multiple arrays and also yes I do have setters and getters in another corresponding program.

I also need to know how you create System.out.println(); methods?
 
Stephan van Hulst
Saloon Keeper
Posts: 7804
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We can't tell from your program what it is your program is supposed to do.

Forget about the code, explain to us what it is you want the program to do.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aaron Boyse wrote:I have this Java program that I am trying to get running in NetBeans:...

I echo Stephan's sentiments entirely.

However, I do have a major tip for you: Be consistent.

Every variable in your program except one starts with a lowercase letter, which is correct.
The exception: 'Landline' - which should be 'landline' (or 'landLine').

It may seem like nitpicking, but it's really important.

Winston
 
Carey Brown
Bartender
Posts: 2992
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without understanding what the program is supposed to do, I have this observation. This code:

seems to be calling various getters and setters but they don't follow Java's convention for getters and setters.

A setter method name begins with 'set' followed by the class's field name in camelCase that the method is supposed to be setting. A setter also returns void. A setter also takes a single parameter of the same type as the field that the method is supposed to be setting.
So, a setHeight() method would look something like

In your code your setHeight() method takes no arguments and therefore does not follow the convention. While your code is legal Java code, it will confuse others trying to read it.

Similarly, a getter method name begins with 'get' followed by the class's field name in camelCase. A getter always returns a value that is the same type as the type of the field. A getter takes no parameters.
So, getPower() would look something like

In your case getPower() doesn't appear to be returning anything because if it is you are not making any use of it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!