# Thread: Proper if Statements: Help

1. Member
Join Date
Oct 2010
Posts
81
Rep Power
0

## Proper if Statements: Help

Would i need to use else if statements for this
Java Code:
```public static String GarageHolds(ArrayList<Garage> myCars)
{
if (myCars.size() < 25);
return "below minimum";

else if(myCars.size() >= 25 && myCars.size() <100);

else if(myCars.size() >= 100);
return "full";
}```
When i try just to use regualr if statements the last 2 statements become "unreachable". Could this be solved by using if else?

2. Originally Posted by socboy6579
Java Code:
`		if (myCars.size() < 25);`
Remove the trailing semicolon(s) (also on the other lines with if-clauses).

kind regards,

Jos

3. Member
Join Date
Oct 2010
Posts
81
Rep Power
0
thank you i figured it out.
Java Code:
```public static String GarageHolds(ArrayList<Garage> myCars)
{
if (myCars.size() < 25){
return "below minimum";

} else if(myCars.size() >= 25 && myCars.size() <100){

} else if(myCars.size() >= 100);
return "full";
}```
Thank you. and one more question if you wuld be able to answer this
Java Code:
```import java.util.ArrayList;
public class Garage {

private static int milesDriven;
private static int GallonsGas;

public Garage(int MilesDrove, int AmtGallonsGas)
{
this.milesDriven=milesDriven;
this.GallonsGas=GallonsGas;
}

public int getMilesDrove()
{
int returnMilesDrove= milesDriven;
return returnMilesDrove;
}

public int getAmtGallonsGas()
{
int returnAmtGallonsGas= GallonsGas;
return returnAmtGallonsGas;
}

public static void main(String[] args)
{
Garage auto1 = new Garage(5000, 2679);
Garage auto2 = new Garage(4325, 1931);
Garage auto3 = new Garage(2452, 978);
Garage auto4 = new Garage(6742, 2979);
Garage auto5 = new Garage(10000, 4503);

ArrayList<Garage> myCars =  new ArrayList<Garage>();

System.out.println(myCars.size());
}

public static int averageMiles(ArrayList<Garage> myCars)
{
int sum= 0;
for(int i=0; i < myCars.size(); i++)
sum+= myCars.get(i).getMilesDrove();
return sum/myCars.size();
}

public static String GarageHolds(ArrayList<Garage> myCars)
{
if (myCars.size() < 25){
return "below minimum";

} else if(myCars.size() >= 25 && myCars.size() <100){

} else if(myCars.size() >= 100);
return "full";
}

public static int numGallons(ArrayList<Garage> myCars)
{
int sum=0;
for(int i=0; i < myCars.size(); i++)
sum+= myCars.get(i).getAmtGallonsGas();
return sum;
}
}```
How would i call the averageMiles, GarageHolds, and the numGallons methods in the main method..

4. Originally Posted by socboy6579
How would i call the averageMiles, GarageHolds, and the numGallons methods in the main method..
System.out.println(averageMiles(myCars))?

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•