• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about Exceptions learning newbie

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could do something like this:
 
Eric Johns
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

reply
    Bookmark Topic Watch Topic
  • New Topic