Jump to content

[REQUEST] This is a project for my Examps in the Univercity. CHECK IT!


Recommended Posts

Posted

This is an excerpt from a book and maybe is the answer can you help ? :)

 

Task 1 - the Time class                               15 marks

The Time class provided already has two methods  getElapsedTime and getTotalMinutes. There will be no need to make changes to getElapsedTime, but you will need to amend getTotalMinutes.

 

1.1 Amend Time class so that it has two private fields of type int to represent the elements of time: hour and minute.

 

1.2 Provide a constructor which has no parameters and initialises the time to midnight (0hr 0 min).

 

1.3 Write a private mutator setHour which sets the value of the hour field from a suitable parameter. If the value of the parameter is within an appropriate range (between 0 - 23), the mutator should set the value of the hour field to the parameter value.  If the parameter value is outside the appropriate range, the mutator sets the field value to 0.

 

1.4 Write a private mutator  setMinute whose behaviour is similar to setHour but which uses the range appropriate for minutes (between 0 - 59). It sets the minutes field either to the value of the parameter if it is in range, or to 0 if it is outside the range.

 

1.5 Write a public mutator setTime, which sets the time from suitable formal parameters. The values of the parameters should be in the appropriate range: 0-59 for the minutes and 0-23 for the hour. If the value of a parameter is not in the required range, the value of the corresponding field should be set to 0 by the method. To avoid duplicating code, you should consider using appropriate local method calls.

 

1.6 Provide a second constructor which sets the time from suitable formal parameters. The values of the parameters must be in the appropriate range: 0-59 for the minutes and 0-23 for the hour. If the value of a parameter is not in the required range, the value of the corresponding field should be set to 0 by the constructor. To avoid duplicating code, you should consider using appropriate local method calls.

 

1.7 Write an accessor  getAsString  which returns a String representation of the time using two digits each for hour and minute separated by a colon (: ) e.g.  14:35, 07:34, 02:03 and 00:00 for midnight.

(Hint: look at the Date class).

 

1.8 Amend the code in accessor getTotalMinutes to convert a time into a total number of minutes and returns this as an int. For example, if the current time object stores 3:15, then getTotalMinutes returns the value 195. This is a private method to be called locally in getElapsedTime

 

Task 2 - the Vehicle class                               20 marks

2.1 The Vehicle class must store the following information: the reference number as an int, the vehicle’s plate as a String, the responsible technician’s (person’s) name as a String, the manufacture date of the vehicle as a Date. In addition, the class also stores the arrival time and the time they started the service session, both of type Time.

 

2.2 Write a constructor which sets the reference number, plate, technician’s name and manufacture date from suitable formal parameters. The date of manufacture should be represented by three formal parameters of type int which are then passed on as actual parameters to a Date constructor. The time when the vehicle arrived and the time when they start servicing should be set to null.

2.3 Write accessors :

• getVehicleNo which returns the vehicle’s reference number

• getRPName which returns the name of the technician as a String

• getManufactureDate which returns the vehicle manufacture date as a Date

 

2.4 Write mutators setArrivalTime and setServiceStart to set the time the vehicle arrived and the time the service session started from suitable formal parameters of type int. These formal parameters should be used to create fields of type Time with suitable values. (Remember, arrival time and service start are both of type Time, which already has constructors/methods to handle time)

 

2.5 Provide a method getAsString which returns a String representation of all the information stored about a vehicle. The String should contain the vehicle’s plate, reference no, technician’s name, date of manufacture and any other text which you think will improve the presentation. 

 

To avoid runtime errors, arrival time and the service start time should only be added to the return String, if the fields which store them are NOT null.

 

2.6 Provide an accessor getWaitingTime which returns an integer representing the number of minutes that have elapsed between the vehicle arriving and the start of the service session. Again, this should only happen if the fields which store them are not null. If either field is null, the method should return -1.

 

 

Task 3 - Testing the Time class                               14 marks

3.1 Write a tester class TimeTest, with a method doTest, to test that your Time class behaves according to the above specification. You will need to make sure that:

• Time objects are initialised from the constructor's formal parameters according to the specification given above

• Time objects can have their values set from the formal parameters of mutators, according to the specification given above

• getAsString  returns a suitable String representation of a time

• getElapsedTime returns the correct results

Choose your data carefully to ensure that you have checked the different situations which can occur.

Provide output statements so that, when doTest is invoked, output is printed in the Terminal window to show the results of your tests, and include comments in the method saying what is being tested.

 

Note: you can only use this class to test the public methods in Time. However, if these methods do not work properly, the problem may be with private methods which they call.

 

 

Task 4 - Write the DayLog class                               16 marks

4.1 The DayLog class stores information about vehicles serviced on a particular date. It has the following fields:

• logDate - should be of type Date. You should use the class provided.

• noOfArrivals - stores the number of vehicles that arrived at the service point on that day 

    and is initialised to 0.

• waitingList - an Vector used to hold the collection of Vehicles waiting for

service.

• serviceList  - an Vector used to hold the collection of Vehicles who have

started the service session.

4.2 Provide a constructor which initialises the date from suitable formal parameters and the number of arrivals to zero. It should also create the two collection fields.

 

4.3 Provide the mutator addVehicle, which has a formal parameter of type Vehicle and two ints to

represent the hour and minute when the vehicle arrived. The method sets the vehicle’s arrival time from formal parameters, increments the number of arrivals and adds the vehicle to the end of the collection of vehicles waiting to be serviced.

 

4.4 Provide the following accessors:

• getArrived - returns the number of vehicles that arrived at the service point that day

• getNumberWaiting - returns the number of vehicles in the waiting list

• findWaitingPosition - has a formal parameter of type Vehicle and returns either the 

        position of  the vehicle on the waiting list or  -1

        if the vehicle is not on the waiting list.

 

 

4.5 Provide the method serviceVehicle. The parameters of this method will be a Vehicle and two ints which represent the hour and minute when the vehicle started the service session. The method should set the vehicle’s service start time, find the position of the vehicle in the collection of vehicles on the waiting list, and use this position to remove that vehicle from the waiting list, then add the vehicle to the collection of those being serviced. Only vehicles that are in the waiting list should be served. If a vehicle is not in the waiting list, it cannot be transferred from the waiting list to the service list.

 

Task 5 - Testing the DayLog class                               10 marks

Write a tester class DayLogTest with a doTest method. Your code should create a Daylog object and some Vehicle objects, then call methods on the DayLog object in a way which shows that these methods work according to specification. At this stage, you have not been asked to provide methods which display the details of vehicles on the waiting and the service lists, but you should ensure that the numbers of vehicles on those lists are consistent with the results expected from your method calls.

 

Provide output statements so that, when doTest is invoked, output is printed in the Terminal window to show the results of your test. Include comments in the method saying what is being tested.

 

Task 6 - Extensions to DayLog class                               10 marks

This task will provide a challenge for students who are confident in their abilities. It is possible to get a very good mark for the coursework without attempting this task.

 

6.1 Provide a method printReport which prints to the terminal window the date, the number of vehicles that have arrived at the service point on that day, the number of vehicles still waiting to start their service session, and the number of vehicles that have started the service session.

 

6.2 Add the following methods to the DayLog class:

• printWaitingList prints to the terminal window the date, and a list of vehicles that are

awaiting for service

• printServiceList prints to the terminal window the date,  and a list of vehicles

    for which the service session has been initiated

• getAverageWaitingTime returns a double representing the average(mean) waiting time

(in minutes)  for vehicles for which service has started. You will need to iterate through the 

          serviceList to get the waiting times for each vehicle.

 

Include the average waiting time in the report described in 6.1.

6.3 Ensure that these new methods are tested in DayLogTest.

 

Task 7 - Demonstration                               10 marks

 

In a scheduled practical, you will be asked to demonstrate that you have a good working knowledge of the code that you have submitted. The main purpose of the demonstration is to authenticate your code by showing that you know it well enough to make changes.

 

 

 

 

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...