Garage - { if (index >= maxCapacity || index...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
public class Garage { private final static int maxCapacity = 5; private int numCars = 0; private Car[] cars = new Car[maxCapacity]; public Garage () { } public Garage( Car[] carList) { for (int i =0; i<carList.length; i++) { if(i >=maxCapacity) { System.out.println( "Maxium car have been reached"+maxCapacity); break; } numCars++; cars[i] = carList[i]; } } public void addCar (Car car) { if ( numCars >=maxCapacity) { System.out.println("Reached max capicty of "+maxCapacity); } else { cars[numCars] = car; numCars++; System.out.println("Added car successfully."); } } public void removeCar(int index)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { if (index &gt;= maxCapacity || index &lt;0) System.out.println(&quot;Car does not exist at index &quot; + index + &quot;.&quot;); else if (cars[index] == null) System.out.println(&quot;Car does not exist at index &quot; + index + &quot;.&quot;); else { for (int i = index; i&lt;numCars; i++) { if (i == (maxCapacity - 1)) cars[i] = null; else cars[i] = cars[i+1]; } numCars--; System.out.println(&quot;Removed car at index &quot; + index + &quot; successfully.&quot;); } } public void printGarageInfo() { for (int i = 0; i &lt; numCars; i++) cars[i].printCarInfo(); } }...
View Full Document

This note was uploaded on 02/06/2010 for the course CSE CIS3023 taught by Professor Seema during the Spring '10 term at Florida College.

Page1 / 2

Garage - { if (index &amp;amp;gt;= maxCapacity || index...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online