We want to realize a program to handle an archive of records. For each record the following information is stored: name of the author, title of the record, and price.
Parte 1.
Write a class Record
that implements the following methods:
Record(String a, String t)
: constructor that, given author
and title, constructs a record whose price is initially 0.0 (the record
is not being sold yet);
String toString()
: that returns a string with all the
information about the record;
void incrementPrice(double p)
: that increments the price by
the amount p
;
String getAuthor()
: that returns the author of the record;
String getTitle()
: that returns the title of the record;
double getPrice()
: that returns the price of the record.
Example program:
TestRecord.java
Part 2.
Write a class UseRecord
, client of Record
, that
contains the following public static methods:
static String titleLowerPrice(Record r1, Record r2)
: that, given two records r1
and r2
, returns
the title of the record among r1
and r2
with
the lowest price. If both records have the same price, the method should
return the concatenation of the titles of the two records, separated by a
","
.
static double averagePriceAuthor(Record[] arch, String auth)
: that, given an archive arch
of records, rappresented
simply as an array of records, and an author auth
, returns
the average price of all records of the author auth
that are
being sold (i.e., whose price is greater than 0). If there are no
records sold by the author, the method should return 0.
Example program:
TestUseRecord.java
Solutions:
Record.java
,
UseRecord.java