hi,
I am having a hard time getting to grips with JAVA. I am on a course that is an introduction so i am only a novice at this. I have an assignment due in on Friday? but i am struggling to come up with the code. I am wondering if anyone would be able to help me with a few things.
I have to create 3 classes, the main one being MyGArage which should only contain a main method. This method should provide; a default constructor creating a garage for 5 vehicles and a constructor allowin any size of garage to be created.
The second class the Vehicle class i have:
[code]
class Vehicle
{
private static int count =0;
private String rNo;
private boolean petrol;
private int cc;
public static int HowMany()
{
return count;
}
public String regNo()
{
return rNo;
}
public boolean isPetrolEngine()
{
return petrol;
}
public int capacity()
{
return cc;
}
}
The third class is the Garage class. This class will contain an aggregation of Vehicle objects; with this possible UML definition:
theVehicles : an array of Vehicle objects references
noOfVehicles : no. of vehicles currently in the garage
park: add a supplied vehicle to the garage
remove : taks a reg. no. (string) and removes the corresponding Vehicle object from the garage; returns the removed object
occupancy: returns the max. size of the garage
contains: returns a string containing the reg. nos. of all vehicles in the garage(seperated by spaces)
Here is the code i have so far, its not much and is only setting the classes out:
[code]
public class MyGarage
{
public static void main(String[] argvs)
{
}
}
class Vehicle
{
private static int count =0;
private String rNo;
private boolean petrol;
private int cc;
public static int HowMany()
{
return count;
}
public String regNo()
{
return rNo;
}
public boolean isPetrolEngine()
{
return petrol;
}
public int capacity()
{
return cc;
}
}
class Garage
{
int[] theVehicles = new int[5];
private int noOfVehicles;
public int park()
{
return noOfVehicles;
}
public int remove()
{
return noOfVehicles;
}
public int occupancy()
{
return noOfVehicles;
}
public int capacity()
{
return noOfVehicles;
}
}
Ok now i am not looking for anyone to hand me all the code for this on a plate, i ain’t going to learn it like that so if someone could maybe spoon feed me this then that would be great.
My first question is when i am creating the array of vehicles do i create that out side the methods but still in the garage class?
I think i should be starting with the park method. So once i have my array in this method i would just be adding to the array does any one have an example of adding to an array?
Still in the park method, how do i find out how many references to objects that are already in the array, this is so i can tell it at which point i want to add the new vehicle?
How do i return the total number of vehicles in my array?
Any and i mean any help on this would be great, i am so stuck with this i feel like glue.