0

How to call an array relation in the menu

i have two classes, one is related to the another one with an array ( departments []) and i have a menu class, so i need to call a method on each element of the array (deparments[1].giveName();) but it keeps returning errors about the privacy of the relation and stuff like that, any help?

23rd Sep 2017, 8:44 PM
Juan Felipe Jaramillo
Juan Felipe Jaramillo - avatar
11 Réponses
+ 1
You should be able to use a method to retrive the data and make the call. If not, a friend class relationship could fix it. If you still can't get it link the code or a small subset to show the relationships, data, and methods involved. I'm sure someone will be able to help you from there. The default protection of data is private to other classes so accessing another's data is something you should try to avoid.
23rd Sep 2017, 9:01 PM
John Wells
John Wells - avatar
+ 1
Thanks man. You really saved my life
23rd Sep 2017, 11:35 PM
Juan Felipe Jaramillo
Juan Felipe Jaramillo - avatar
0
Post your code
23rd Sep 2017, 8:55 PM
ChaoticDawg
ChaoticDawg - avatar
0
there are 4 .javas of code, is there an email where i can send them to you?
23rd Sep 2017, 8:57 PM
Juan Felipe Jaramillo
Juan Felipe Jaramillo - avatar
23rd Sep 2017, 9:08 PM
Juan Felipe Jaramillo
Juan Felipe Jaramillo - avatar
0
Sorry I don't know Spanish, but from what I can see: You're missing the following imports in Menu.java: import modelo.Municipio; import modelo.Departamento; and: CensoDepto in the main method isn't initialized before attempting to use it here: CensoDepto.MunicipiosPertenecientes[0] = new Municipio(elNombre, laPoblacion, cHombres, cMujeres, cAdultosM, Epromedio, Ipromedio); I initialized it like: Departamento CensoDepto = new Departamento("Department"); After altering the above the code runs. You can change several of your access modifiers to private and package private too: in Pias.java Departamento[] can be private, in Municipio.java all of the //ATRIBUTOS can be private, and your methods look like they can be package private (no modifier), in Departamento.java it looks like your methods can also be package private.
23rd Sep 2017, 10:13 PM
ChaoticDawg
ChaoticDawg - avatar
0
i initialized it and now i have this error on the last lane: cannot find symbol symbol: variable MunicipiosD location: variable censoDepto of type Departamento
23rd Sep 2017, 10:24 PM
Juan Felipe Jaramillo
Juan Felipe Jaramillo - avatar
0
Did you add the import to Menu.java? import modelo.Municpio;
23rd Sep 2017, 10:44 PM
ChaoticDawg
ChaoticDawg - avatar
0
yes
23rd Sep 2017, 10:44 PM
Juan Felipe Jaramillo
Juan Felipe Jaramillo - avatar
0
Ok, If it is literally spelled MunicipiosD in error and this is not a typo in the post then you most likely have accidentally added the D to the end of the name on the specified line. Also with censoDepto it should have a capital C like CensoDepto according to the rest of your code. Check through those lines and make sure that you didn't accidentally change their spelling and/or capitalization etc.
23rd Sep 2017, 11:00 PM
ChaoticDawg
ChaoticDawg - avatar
0
Here's the edited version if that helps: https://drive.google.com/open?id=0B0WvpWZkJHGcLWtFa3Zwc01tTWc
23rd Sep 2017, 11:19 PM
ChaoticDawg
ChaoticDawg - avatar