This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Question about Exceptions learning newbie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question about Exceptions learning newbie" Watch "Question about Exceptions learning newbie" New topic
Author

Question about Exceptions learning newbie

Eric Johns
Greenhorn

Joined: Sep 13, 2003
Posts: 20
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
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
You could do something like this:
Eric Johns
Greenhorn

Joined: Sep 13, 2003
Posts: 20
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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about Exceptions learning newbie
 
Similar Threads
help with methods return types
comparing Stings help
Help with Arrays
Java help
help with IF Statements on a program Newbie