• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

help with IF Statements on a program 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'm having now is when I'm quering my data how do I prevent the fields Make,model,Type not to appear when Retail price, safety rating, and miles per gallon don't fit my criteria ect...? is their another way of doing this that's I'm not seeing?
the criteria for the program is as follows users are to input their preferences, then search a data file to match the fit of the users input.
by >=80% . output should be Make, Model,Type,Retail price, Safety rating,miles per gallon, fit and to calculate the fit use this given
weights:
Suggested Retail Price=.40
Safety Rating = .45
Miles Per gallon=.15
then their are 3 levels of fit.
With in 10% of preference: fit would be 100%
with in 20% of preference : fit would be 50%
above 20% of preference : fit would be 0%

My code up to Quering the Data file:
CarDataList carDataList=new CarDataList();
int listSize=carDataList.getListSize();
System.out.println("Cars that match your requirements with at least 80% fit:");
for (int i=0; i<listSize;i++)
{
CarData carData=carDataList.getCar(i);
make=carData.getMake();
model=carData.getModel();
type=carData.getType();
System.out.println("Make:"+ make);
safetyRating=carData.getSafetyRating();
if (inputSafetyRating<= 1.1 * safetyRating)
{
System.out.println("Safety Rating:"+ safetyRating);
}
else if (inputSafetyRating<= 1.2 * safetyRating)
{
System.out.println("Safety Rating:"+ safetyRating);

}

}//End of Loop
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you asking how to display some fields only when certain criteria apply?
If so why not put the System.out.println's inside the if statement... Here's some pseudocode:

I hope this answers your question. It's possible that a single if statement with a compound condition will work if the output is the same each time.
Regards, David
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic