Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about Exceptions learning newbie

 
Eric Johns
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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
 
James Swan
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could do something like this:
 
Eric Johns
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic