Eric Johns

Greenhorn
+ Follow
since Sep 13, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Eric Johns

my problem was I forgot to bring the values in for those var. thanks alot don't know how I missed that one.. thanks Eric
18 years ago
I need some help with overridding methods. I have car class and then some children class of the car class.. here is my car class

Now what I am trying to due is in the client class I'm trying to overide the car class's getCarsuggestedRetailPrice with this new getCarSuggestedRetatilPrice in PassengerCar Class, but no matter how I do or I should say where I put the code,I am always getting the same suggested Retail price value no change which leads me to think that it's not overriding the Car class's methods or somethings not right, would anybody have any suggestions? thanks.
18 years ago
I was thinking about that too, but it might get to complex because the next step is I have to sort my array by retail price.

Originally posted by Elouise Kivineva:
You could create an int array then, inside your "if fitWeight" loop, store in this array the index numbers from the car array where you found an appropriate car. Then you could read through this array and fetch each index in turn.
A much better idea would be to print as you go; when you find a match, print the information immediately, then go on with your search.
[ November 14, 2003: Message edited by: Elouise Kivineva ]

18 years ago
ok, your guys suggestion work but now I have a new problem. my orginal design was to have the "if ((fitWeight >=80)ect." to add and count matches then drop out of the "for" loop and run a new "for" loop to print my counting results and display the car details. the problem I'm running into is that not every run of the first "for" loop is going to give me a hit so in a sense I am having gap in the array, so when I then try to print my results with the last "for" loop and it run into an array index that has nothing the program crashes. I was wondering if anybody has any suggestions?
[ November 14, 2003: Message edited by: Eric Johns ]
18 years ago
Could you explain what you mean by Add Elements? What I'm am trying to do is all car objects that match the Fit requirments will be put into an array, then I need to count all the object that are in my array and then print the results.

Originally posted by Wayne L Johnson:
Your "carMatches" array is defined inside of the "for()" loop, but you are trying to reference it after the loop exits. You need to declare it before the "for()" loop, add elements inside the loop, and then you can reference it after the loop ends.
Also, you might want to think about checking for array bounds before you add the next match to the array.


[ November 13, 2003: Message edited by: Eric Johns ]
18 years ago
I'm writting this program that searches a data file for cars that match the users preferences. I'm having a problem with the line I marked with **, I keep getting a java error that says " cannot resolve symbol" and I don't understand why? anybody have any suggestions, Thanks
18 years ago
Yeah, that works thanks alot guys
18 years ago
My basic question is I have to return make,model,type,price,safetyrating,mpg if that car is with in my users preference but how do you return values with different types, their are strings,int,doubles.
18 years ago
I have car class
and a method in that methods I need to return those values,in program that will be calling on that method and it's findingmatchingcar class with it's with 80% or greater of the users required inputs my question is I'm having program with the return types and how would I return those values and have them get printed? thanks Eric
18 years ago
yeah I think that would work, but the counter has to been in the statment "Cars that match your requirements with at least 80% fit", so it should say something like Example, "2 Cars that match your requirements with at least 80% fit:" and the problem I'm having is that statement can only be displayed once per starting run of the loop and since the guts of the calculations are in a for loop how can I get a total number of cars that are going to get printed when the loop running on car at a time.
I can't seem to think of anything
18 years ago
I have this program that takes user input and searches a data file for cars that meet the users preferences, now if their are cars that match. The output, "Cars that match your requirements with at least 80% fit:, needs to display how many cars that would be and I can't seem to figure out how I could go about doing this. below I have what I have come up with I have added another if statement and another var called totalcars. is their a way to take the cars that work for the boolean statement and register them into a number?
thanks Eric



(Marilyn added code tags)
[ September 27, 2003: Message edited by: Marilyn de Queiroz ]
18 years ago
I have this program that takes user input and searches a data file for cars that meet the users preferences. my program has a general "for" loop that goes throught the whole data file and goes throught every car on the list till it ends, now in addtion to that I have to make another loop ( I think a while loop) that keeps running the program till the user decides to exit. My problem is I can't seem to get it working right. right now I have a string called prompt where the user can input either yes or no if they want to continue with the program. then I have a boolean statement endloop that can be a test for the while loop and a set of if statement to change the endloop to false, but the problem is no matter where it is it doesn't work right if I put it above the while loop statement it will never run the if statement but if I put it below the while loop you have to go thought it again even if you say no before it drops out , is their an easier way I'm not seeing?
sample of what I did.
if(prompt.compareTo("no")==0)
{
endLoop=false;
}
while (endLoop==true)
18 years ago
Thanks alot with your suggestion I jumped into my learning java book and found that part, I didn't know about the boolean type.. thanks it works

Originally posted by James Swan:
You could do something like this:

18 years ago
I have this program that takes user input and searches a data file for cars that meet the users preferences. here are the final print statements in my loop, my question is lets say no cars meet the user preferences how would I get a statement that would say "no cars match your preference" without it comming out just evertime one car doesn't match the preferences?
/Output for for the loop

if ((fitWeight >=80) && (carType.compareTo(type)==0))

{
System.out.println();
System.out.println("Make: "+ make);
System.out.println("Model: "+ model);
System.out.println("Type: "+ type);
System.out.println("Retail Price: "+ retailPrice);
System.out.println("Safety Rating: "+ safetyRating);
System.out.println("Miles Per Gallon: "+ milesPerGallon);
System.out.println("Fit: "+ fitWeight);
System.out.println();

}


}//End of Loop
18 years ago

Originally posted by Bear Bibeault:
To expand:
When comparing objects, the == operator is a test for identity not equality. It will check if the two objects are the exact same object instance, not whether their values are the same. For that, you would use the String.equals() or String.equalsIgnoreCase() methods as previously pointed out.
This makes complete sense if you understand that object variables don't contain the objects, but rather contain a reference to an object. So it makes complete sense that == would compare the two object references and only evaluate to true if the references are equal; which will only happen when the references are to the same object.
hth,
bear


ok that makes sense ,but how do you use the String.equals()?
18 years ago