代写C代码 代做C程序 C辅导 C家教

远程写代码 Debug 讲解答疑 不是中介,本人直接写

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

1. Give a brief description of each of the following terms in the context of Java. Give illustrative
examples.
(a) primitive type;
(b) reference type;
(c) instance variable;
(d) local variable;
(e) access modifier;
(f) formal and actual parameters;
(g) constructor;
(h) static variables;
(i) static methods;
(j) interface.
[20 marks]
2 Lab Work (80%)
1. A car hire company needs to store information about its fleet of cars. You are required to write a
Java application which contains a class called
HireCar together with a main method class called
HireCarDemo.The information about each hire car consists of:
manufacturer (e.g. Toyota);
registration number (e.g. DK10RTP);
mileage (e.g. 12507 (miles));
service interval (e.g 5000 (miles) );
last service (e.g 5345 (miles));
current status (viz. on hire, available for hire, or being serviced).
A hire car is sent for service when it returns from hire if the number of miles it has been driven since
its last service has reached (or exceeded) its service interval.

Page 3 of ??
You should implement the status of a hirecar using an enum type. [5 marks]
In addition to appropriate fields,
HireCar should include the following two private methods
a boolean method serviceDue to determine whether this HireCar is due a service
a method sendForService
[10 marks]
and each of the following
public constructors and methods:
a constructor with arguments for the manufacturer and the registration number for a new
HireCar and which sets all other fields to zero or null as appropriate; [2 marks]
a constructor with arguments for the manufacturer, the registration number, the mileage, the
service interval and the last service for a new
HireCar; [2 marks]
methods for “setting” the mileage, the service interval and the last service value for a HireCar;
a method for “getting” the registration number of a HireCar; [3 marks]
a method makeAvailable to set a HireCar as available for hire; [2 marks]
three boolean methods isAvailable, isOnHire and isBeingServiced to determine information about a HireCar’s status; [6 marks]
methods hireOut, returnFromHire and returnFromService; [6 marks]
a toString method that returns a description of a HireCar. [4 marks]
In addition to your
main method, HireCarDemo should contain a static method with the following
header:
/**
* @param fleet the fleet of hire cars
* @param numberOFevents the size of the events table to be
* generated
* @param minMileage the assumed minimum mileage driven by
* a hire car during any hire period
* @param maxMileage the assumed maximum mileage driven by
* a hire car during any hire period
* @return table of events generated during the
* simulation
*/
public static String [] runSimulation(HireCar [] fleet,
int numberOFevents, int minMileage, int maxMileage)
This static method is to implement an algorithm for simulating a car hire company. The algorithm
generates a sequence of random events. There are four types of event:
a car is hired out;
a car is returned from hire (but is not sent for service);
Page 4 of ??
a car is returned from hire and is sent for service;
a car is returned from service.
The output from the algorithm is a list, each item of which has the form:
registration number: <type of event>
A pseudo-code description of the algorithm to be implemented is given below:
let n = number of cars in fleet;
initialise events list;
for event number from 1 to the required number of events do
select a car at random from the fleet;
select case from the following:
case status of selected car is available for hire:
hire out selected car;
add a "car hired out" event to the events list;
case status of selected car is on hire:
generate a random integer in the assumed range for
miles driven;
return from hire the selected car;
if selected car is being sent for service then
add a "return from hire and sent for service event" to
events list;
else
add a "return from hire" event to events list;
endif
case
status of selected car is being serviced:
return from service the selected car;
add a "car return from service" event to events list
end select case
endfor
The print-out of the events list from a typical run of your program might look like:
run:
AV12TRP: HIRE OUT.
DK10RTP: HIRE OUT.
DK10RTP: RETURN FROM HIRE. SEND FOR SERVICE.
AV12TRP: RETURN FROM HIRE.
OV12JVF: HIRE OUT.
AU11PKL: HIRE OUT.
OV12JVF: RETURN FROM HIRE. SEND FOR SERVICE.
AU11PKL: RETURN FROM HIRE. SEND FOR SERVICE.
OV12JVF: RETURN FROM SERVICE.
OV12JVF: HIRE OUT.
AV12TRP: HIRE OUT.

Page 5 of ?? Submission instructions overleaf.
AU11PKL: RETURN FROM SERVICE.
OV12JVF: RETURN FROM HIRE.
OV12JVF: HIRE OUT.
AU11PKL: HIRE OUT.
AU11PKL: RETURN FROM HIRE.
DK10RTP: RETURN FROM SERVICE.
OV12JVF: RETURN FROM HIRE.
AU11PKL: HIRE OUT.
AV12TRP: RETURN FROM HIRE. SEND FOR SERVICE.
 

相关推荐