Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.

Learn More!


Download to Enter
| Contest Rules

Tutorials | Forums

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 28th, 2012, 10:18 PM
lucki_87 lucki_87 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 34 lucki_87 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 5 m 31 sec
Reputation Power: 1
Add method of an array

does anyone know how to write an add method of an array?

Reply With Quote
  #2  
Old January 29th, 2012, 07:17 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 1,758 NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 20 h 51 sec
Reputation Power: 288
You can not add methods to an array like you can with a class.

Please explain what you are trying to do.

Reply With Quote
  #3  
Old January 29th, 2012, 03:08 PM
lucki_87 lucki_87 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 34 lucki_87 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 5 m 31 sec
Reputation Power: 1
box class

item array
int numItem


i want to write a add method in the main argument which would add an item in the box and increase the numItem

box.add(item1);
box.add(item2);

etc

how do i make it so the item1 would be at location 0 in the array item2 would be at location 1

how do i initialize the item array in the box class?

Reply With Quote
  #4  
Old January 29th, 2012, 03:23 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 1,758 NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 20 h 51 sec
Reputation Power: 288
Your question leaves many things undefined and unanswerable.
What class is the box variable? Does it have an add() method? Where does the add method put the value that is passed to it?
Where are the variables: item1 and item2 defined?
Quote:
how do i initialize the item array in the box class?

You should initialize the variable: array before you put it into the box. If array has a null value that is what the box's add() method will receive.

Reply With Quote
  #5  
Old January 29th, 2012, 03:38 PM
lucki_87 lucki_87 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 34 lucki_87 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 5 m 31 sec
Reputation Power: 1
solved

Reply With Quote
  #6  
Old January 29th, 2012, 03:57 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 1,758 NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 20 h 51 sec
Reputation Power: 288
Have you got your answer and solved your problem?

Reply With Quote
  #7  
Old January 29th, 2012, 04:12 PM
lucki_87 lucki_87 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 34 lucki_87 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 5 m 31 sec
Reputation Power: 1
solved

Reply With Quote
  #8  
Old January 29th, 2012, 04:17 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 1,758 NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 20 h 51 sec
Reputation Power: 288
Describe what the method should do in small simple steps.
What does it need to do with the argument that is passed to it?

Reply With Quote
  #9  
Old January 29th, 2012, 04:23 PM
lucki_87 lucki_87 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 34 lucki_87 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 5 m 31 sec
Reputation Power: 1
the method should ad the item into the box array and increase the numItem

box array size is the actual numItem

so if no item is add the box array is size 0
item1 is added the box array size is 1
and so on so forth

Reply With Quote
  #10  
Old January 29th, 2012, 04:59 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 1,758 NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 20 h 51 sec
Reputation Power: 288
That looks like a start.
Also you need to define the array and give it some slots so you can add to it.
Your constructor sets the array to null instead of defining it with some size.
Why not define an array with some empty slots so you will be able to put items into it in the add method?

Reply With Quote
  #11  
Old January 29th, 2012, 08:10 PM
lucki_87 lucki_87 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 34 lucki_87 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 5 m 31 sec
Reputation Power: 1
solved

Reply With Quote
  #12  
Old January 29th, 2012, 09:02 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 1,758 NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level)NormR User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 20 h 51 sec
Reputation Power: 288
Code:
box = new Box[numItems+1];

This replaces the existing array with a new array. The contents of the old array is lost.

You can not change the size of an array. You must create a large enough one in the constructor. The add method should add items to the existing array.

If the array is full when add is called, then add must create a new larger array, copy the contents of the existing array to it and replace the existing array with the new array.

You must post the code that you are compiling. The code you have posted so far does not make sense. The variable names and the class names are changing from post to post.

Last edited by NormR : January 29th, 2012 at 09:07 PM.

Reply With Quote
  #13  
Old January 30th, 2012, 08:08 PM
lucki_87 lucki_87 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 34 lucki_87 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 5 m 31 sec
Reputation Power: 1
problems solved

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Add method of an array


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap