This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!

rian bron

Ranch Hand
+ Follow
since Oct 14, 2018
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by rian bron

Hello guys,  have  a  problem.
i need to create a new City object which contains the variable" residents " in it.
i have a method in the country class which calls : int getNumOfResidents();
and i have a method in the City class which calls : long getNumOfResidnets();
now, i  want from my Country class, to call the getNumOfResidents() from my City class.
but i don't know how, because they have the same names.
how can i call it from the city class ( i can't change any of these method names)?
Thank you
1 week ago

Carey Brown wrote:

rian bron wrote:

First, I'd suggest replacing both your while() loops with for() loops, just like the one on line 8. This will solve your biggest issue. You will still be left with the problem that line 28 does not properly check to see if the name wasn't found. For that I would suggest adding a boolean variable just above your search loop, like:
And please clean up your indentation, it is contributing to your inability to follow your own code.

Yeah noticed to the loop issue by the help of Daniel , Thank you too i will notice to write the code cleaner next time
2 weeks ago

Daniel Demesmaecker wrote:cause i is already the length of the array by the first time it get's to the second while loop, so that loop is never executed.
Change your second while loop to:

What is Strings? A class you created yourself? What a terrible name...

Thank you man, didn't notice that. that's why i hate to use the while loop,
And about the name, i know i'm just doing it briefly not putting a lot of thinking with choosing names
2 weeks ago
Hello guys, i asked this question few times but it seems like people didn't understand what i was asking. so now i made it clear : i wrote this code :

But when i execute the code, i don't get any output. i also tried to create a String variable called ;before the last loop and put a command after the if statement " answer= "There was a match to the name : "+searchName;
and if not then , answer="There was no match for the name." and then after the loop to print the variable  " answer" , but  still nothing was happens. why?
2 weeks ago

Knute Snortum wrote:Look at this closely:
What are you comparing?  A City or a cityName?

i want to compare the cityName , thats why i need to wriite  
2 weeks ago

Knute Snortum wrote:

rian bron wrote:can you show me the way  i will get the output of the "cityName" and not the output saying "There was no match inside the citise array to the name "+cityName;"
i'm so lost

Well, I'm not sure why you would need the variable test at all.  Why not use cities?  

Still won't work
2 weeks ago
can you show me the way  i will get the output of the "cityName" and not the output saying "There was no match inside the citise array to the name "+cityName;"
i'm so lost
2 weeks ago

Daniel Demesmaecker wrote:No you don't, the class you thin you initialize is test and the class that returns the array is tester, even if you would Knute is still right...
You have to break out of the loop once you found the right value...

But test is an object of the Testerr class, so i initialize the test class because only there i can initialize the array values , and about the loop and the value, inside the loop i said :
if the array of the index "j" . get the name of the object is  equals to the given input from the user.
and you are right, i put a break after the "if " statement and its command below, but still. i get the output of "There was no match inside the citise array to the name "+cityName"
2 weeks ago

Knute Snortum wrote:Take a look at this:
Go through it step by step.  Keep in mind what tempName will be.  What happens if cityName isn't the last element in your array?

cityName isn't need to be a value inside the array, the cityName is a name that the user input and then by the for loop , it search for a match between the tempName and the user's input name.
2 weeks ago

Daniel Demesmaecker wrote:cause you're searching for the city in an empty array of cities.
You don't initialize the values of the array.
Note, this is the 4th or 5th question you ask about the same subject, but after getting some response you never let us know if you got it working, a little feedback or thanks on the responses you get would be nice...

I do initialize the values of the cities array in the loop in the main method

and about the feedback you are right, usually when i don't answer it means you helped me and i don't need to ask anything else but you are  right this is not kind and from now on i will answer on your answers
2 weeks ago
hello guys,
i have a problem.

i have a class which i created an City array which contains the City name,  number of residents, number of neighborhoods.
in the City class i have a method calls : getCityName();
now, i have a class called Country.
in the Country class i have private variables of City[] cities - which are an array of Cities.
I need to create a method that will  get a city name from the user, and will print to the user, whether the name he entered  has a match to one of the city names in the array or not.
i tried to do so but it doesn't work for me .
every output is saying ""There was no match inside the citise array to the name " +cityName.. even if i put the same city names
please help me

2 weeks ago

i didn't set anything to private . why does it prints me the object's address and not the array?
thank you
2 weeks ago
hello guys i build a long project so i will shortcut it for the problematic parts .
i have this method :

this writes me a problem with line 3

and in this ^ command it writes me a problem with line 4.

it writes : java.lang.NullPointerException

and i read about this problem and it says "when an application attempts to use an object reference that has the null value. These include: Calling an instance method on the object referred by a null reference."
but here, the object reference doesn't have null value because i initialized it in the beginning.
please help  
2 weeks ago

Liutauras Vilda wrote:

rian bron wrote:ignore the variable naming  thing, i did it because i didn't have much time

Your saved 13 keystrokes saving your own time caused Your Code Readers who want you to help to waste their time deciphering what those variables mean, so really to ignore the things are difficult, especially if readers are not informed upfront if they are relevant or not. If you want your readers to ignore the parts of the code, simply don't post them.

Please post the declaration of the Country class constructor, so the problem would be more apparent to discuss. But in general I think I've explained what I think the problem is, however, I could be mistaken due to insufficient visibility of the Country class, and in particular its constructor declaration.

this is the private variables of the country class and the constructor .
2 weeks ago

Liutauras Vilda wrote:This code is very very confusing and hard to read.

On line 37 to Country constructor you are trying to pass singular city ci[j], while I suspect constructor is expecting an array of cities.

Anyway, you have been taught some bad concepts initially probably (for example, naming variables, i.e.: c stands for countries and ci for cities. Why not countries and cities?) that you came up with such code.
I'd delete that and start over. To suggest something, we'd need to know what is the task about in general.

ignore the variable naming  thing, i did it because i didn't have much time , but my question is why it writes me can't  cant not be converted City to City[]?
2 weeks ago