We want to realize a program for collecting data about medical visits. For each visit, the following information is stored:
null
.
-1
.
Part 1.
Write a class Visit
that implements the following methods:
Visit(String n, double p)
: constructor that creates an
object representing a visit whose name of person is n
, whose
price is p
, and which has not been made yet;
String getName()
: that returns the name of the person;
double getPrice()
: that returns the price of the visit;
String getResult()
: that returns the result of the visit,
if it has taken place, and null
otherwise;
int getDuration()
: that returns the duration of the visit,
if it has taken place, and -1 otherwise;
boolean hasTakenPlace()
: that checks whether the visit has
already taken place;
void visit(String res, int dur)
: that changes the status of
the visit so that it has taken place, by setting the result of the visit to
res
and the duration to dur
; if the visit had
already taken place, the method should do nothing;
String toString()
: that returns a string with all the
information about the visit.
Example program:
TestVisit.Java
Part 2.
Write a class UseVisit
, client of Visit
, that
contains the following public static method:
static double averageDuration(Visit[] ar)
: that, given an
archive ar
of visits, represented as an array of visits,
calculates the average duration of the visits that have taken place. If
there are no visits that have taken place in the archive, the method should
return 0.
Example program:
TestUseVisit.java
Solutions:
Visit.java
,
UseVisit.java