Question: PART 1: GETTING STARTED Create a new Java Project. Create a new Car class and enter this code. public class Car { // Data members

PART 1: GETTING STARTED

Create a new Java Project.

Create a new Car class and enter this code.

public class Car

{

// Data members

private String color;

private String license;

// Constructor

public Car(String l, String c)

{

license = l;

color = c;

}

// getters

public String getLicense()

{return license;}

public String getColor()

{return color;}

public String toString()

{

return license + "\t" + color;

}

}

Create a SEPARATE class in a SEPARATE file within the same project. Call it ParkingLot and enter this code. You do not have to type in the comments.

public class ParkingLot

{

private Car carlot[];

private int numCars;

public ParkingLot()

{

carlot = new Car[200];

numCars = 0;

}

public void add(String l, String c)

{

// ADD A CAR TO THE CARLOT

}

public String findCar(String c)

{

// FILL IN THE CODE TO FIND A CAR WITH

// THE SAME COLOR AND RETURN THE LICENSE

// RETURN NULL IF NOT FOUND

return null;

}

public String toString()

{

String results = "";

for (int i=0; i < numCars; i++)

results += carlot[i].toString() + " ";

return results;

}

}

Create a ANOTHER class in a THIRD file within the same project. Call it Lab7 and enter this code. You do not have to type in the comments.

public class Lab7

{

public static void main(String args[])

{

// Instantiate a ParkingLot object here.

// Name it metroRamp

metroRamp.add("METRO", "black");

metroRamp.add("ABC123", "red");

// Add at least three more cars

System.out.println(metroRamp);

System.out.println (metroRamp.findCar("red"));

// Write code to find a different car here

}

}

PART 2: ADDING CODE

In the Lab7 class, in the main() method,

Write code to declare a ParkingLot variable called metroRamp.

Instantiate the ParkingLot object.

Write code to add at least three more cars to the ParkingLot.

In the ParkingLot class,

Write the code for the add() method. The add() method will add the information for another Car to the end of the list stored in the array carlot.

You may wish to test the program by running main() at this point.

In the ParkingLot class,

Fill in the code for the findCar() method. findCar() has one parameter, a String representing the color of the Car. Look through the carlot array until you find a Car with a matching color, then return the license number for that Car.

Test the program by running main() at this point.

In the Lab7 class, in the main() method,

Add a line of code to find a Car with a different color and display the results.

PART 3: REFLECTION

Does findCar() change the contents of the array? ___________________

If there is more than one car with the desired color, which one is found?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!