Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Assignment #2 (Arrays) I. The Assignment This assignment is to take your Garage class from the previous assignment and modify it so that it

Programming Assignment #2

(Arrays)

I. The Assignment

This assignment is to take your Garage class from the previous assignment and modify it so that it uses an array of Car objects as the principal data structure instead of an ArrayList-of-Car.

This is an example of the OOP principle of information hiding as your Car and test classes will not have to be modified at all. Unless you broke encapsulationon the previous assignment, that is

II. Specifications

Specifications for all 3 classes are the same as for the previous version, except as noted here:

  1. To get credit, your Garage class must use an array (not an ArrayList) of Car objects to implement the garage

  1. Use a defined constant to set the size of the array (i.e. number of spaces in the garage). The literal 10 should not appear anywhere else in your program
  1. No credit will be given if any data structures other than the array of Car objects are used
  2. No credit will be given if you use Arrays.copyOfor System.arraycopy, or resize the garage array in any other way.

Hint: Uas a counterto keep track of the number of Cars in the garage.

Dude, why the restrictions?

Answer: To earn a meaningful merit badge in arrays, we must use only those techniques that will work for arrays in everylanguage in this quadrant of the galaxy. Loops.

Make sure your classes adhere to the style and documentation standards discussed in class and online notes

III. Due Date: Tuesday, February 5th

IV. Grading

As per the previous assignment, this one will generate two (2) separate grades one for the program itself and the other for the html files generated by Javadoc.

If you aced the Javadoc grade on the previous one, no need to do anything else. If you did not, heres another chance.

V. What to Upload to Canvas

Upload 2 files via the Programming Assignment 2link

  1. a zip file containing your NetBeans project folder with the output file included
  2. an empty Word document to receive your feedback

Upload another empty Word doc via the Javadoclink

Make sure you zip the project folder itself, and not the individual java files.

  1. See Submitting Your Assignments online to make sure you dont lose credit!

  1. For reference, see PartiallyFilled.javaand OrderedList.javaonline in this unit

_______________________________________________________________________________________

THIS IS ASSIGNMENT 1 GARAGE CLASS:

package garage.project;

import java.util.ArrayList;

/**

* Class that contains an array list full of car objects. Contains methods to

* handle departure and arrival operations of the cars.

* @param justLeft saves the value of a car that just left.

*/

public class Garage {

private Car justLeft;

private ArrayList Garage;

/**

* Constructor to intialize empty array list.

*/

public Garage()

{

Garage = new ArrayList<>() ;

}

/**

* Adds car to the array if there is room and turns car away if not.

* @param number the plate numbers for the car

* @return true if car object is added to array and false if list is full.

*/

public boolean arrive(Car number) // Add a car to list if list < 10

{

if (Garage.size() < 10)

{

Garage.add(number);

return true;

}

return false;

}

/** Check for car in garage and remove it. Pass true if car was removed.

* Removed car object is assigned to the variable justLeft.

* @param name the plate number of the car.

* @return true if car is found in list but false if not.

*/

public boolean depart(String name)

{

int position = -1;

// Traverse array to check for car position.

for (int i = 0; i < Garage.size(); i++)

{

String matchName = Garage.get(i).getName(); //get plate number

if ( name.equals(matchName) ) //compare plate numbers

{

position = i; // Get index if car is found

}

}

// if car is in garage then increment moves for cars ahead of it.

// Remove car and add its values to justLeft variable.

if (position != -1)

{

for (int i=position - 1; i >= 0; i--)

{

Garage.get(i).addMove();

}

justLeft = Garage.remove(position);

return true;

}

return false;

}

/**

* Gets the value of the variable justLeft.

* @return justLeft the variable that contains the last car to leave.

*/

public Car getLeft()

{

return justLeft;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

What ethical issues arise in using the self-concept in marketing?

Answered: 1 week ago

Question

What does the start( ) method defined by Thread do?

Answered: 1 week ago

Question

=+1 What would you do if you were the IHR manager?

Answered: 1 week ago