Assignment title: Java


Java Programming Q Task 1 Based on the above requirements, the partial UML diagram for the Container class is as follows: Container

- String id - String contents

+ Container( String id, String contents ) + Container( Container c )

+ String getId( ) + String getContents( )

+ String toString( ) Implement the Container class so that we can create and use a Container object. The UML

diagram is described as partial because you are free to add methods to this class if you think they are required. Note that you do NOT have to add methods, you can if you think it necessary. Task 2 Based on the above requirements, the partial UML diagram for the Plane class is as

follows: Plane - String id

- int capacity - int current

- Container [ ] cargo + Plane( String id, int cap )

+ String getId( )

+ int getCap( )

+ add( Container c ) + String toString( ) + Container [ ] getContainers( ) Implement the Plane class so that we can create and use a Plane object. The UML diagram is

described as partial because you are free to add methods to this class if you think they are required. Note that you do NOT have to add methods, you can if you think it necessary.

The add method of this Plane class adds another Container to its array only if there is space in the array of course. The array size is always equal to the capacity and newly created Planes have not loaded any Containers.

You might find it useful to add a method to this class that takes a PrintWriter object as a parameter so that you can call this method from the Airport class when you need to write the array to a text file. Equally you might want to consider a method that just returns the details of the Plane without

the Containers loaded on the plane. Neither of these methods are absolutely required, there are other, correct, ways of writing this program without these 2 methods. It is just that you might find it easier to implement the overall

program if you have these 2 methods. Lastly, you might consider a method that returns the spare capacity of the Plane. That is the number of Containers that can still be loaded (free spaces in the array).

The PrintWriter class is described at the end of this document. Task 3

The driver program, Airport.java has as an object attribute, an array of Planes. This is of size 20 which is thus the maximum number of Planes that can be at the airport at any one time.

This object attribute and a number of final (constant) attributes are already declared in the class. Some (like the Plane array attribute) are commented out as they depend on the classes that you have implemented in Tasks 1 and 2. When you have implemented the Container and

Plane classes, then uncomment the attributes in the Airport class. The program starts by asking the user for the name of text file. This text file, described below contains all the information to create Plane and Container objects that are stored in the

array. The name of the text file must not be hard coded. You may assume that the name of the text file the user enters will always exist. However the text file maybe empty. Information on each Plane consists of at least 3 lines as follows (and is known as a record)

and as many lines as are needed for the Containers already loaded into this Plane (so the number of extra lines may be 0 to any number): The table below shows an example of a Plane that has one Container loaded aboard)