Exercise 6A (Midterm Simulation)
Questo esercizio - come il midterm - è disponibile solo in lingua inglese.We want to realize a program to handle a document archive. For each document the following information is stored: name of the author, title of the document, and number of available copies.
Part 1.
Write a class Document
that implements the following methods:
Document(String a, String t)
: constructor that, given author
and title, constructs a document for which the number of available copies
is 0;
String toString()
: that returns a string with all the
information about the document;
void createCopies(int n)
: that increments by n
the number of available copies;
void sellCopies(int n)
: that decrements by n
the number of available copies; (if n
is greater than the
number of available copies, then such number should become 0);
String getAuthor()
: that returns the name of the author of
the document;
String getTitle()
: that returns the title of the document;
int getCopies()
: that returns the number of available
copies of the document.
An example program that uses class Document
is given:
TestDocument.java
Part 2.
Write a class UseDocument
, client of Document
, that
contains the following public static methods:
static String authorMaxCopies(Document d1, Document d2)
:
that, given two documents d1
and d2
, returns
the author of the document among d1
and d2
for
which more copies are available. If for both documents the same number
of copies are available, the method should return the concatenation of the
names of the two authors, separated by " and "
.
static boolean bothAvailable(Document d1, Document d2, int count)
:
that, given two documents d1
and d2
, returns
true
if at least count
copies of both documents are
available and false
otherwise.
An example program that uses class UseDocument
is given:
TestUseDocument.java
Soluzioni:
Document.java
,
UseDocument.java
Esercizio 6B (Istruzioni condizionali)
Progettare e realizzare una classe Java CassaCambioDollari
,
che rappresenta casse automatiche che consentono di cambiare dollari in euro.
Delle casse sono d'interesse le seguenti funzionalità:
"Scorta insufficiente"
.
Il tasso di scambio Euro/Dollaro è definito come la quantità di
Euro ottenuti cambiando un Dollaro:
0.5 se la quantità di dollari cambiati è minore di 10
0.9 se la quantità di dollari cambiati è tra 10 e 100
1.0 se la quantità di dollari cambiati è maggiore di 100.
Soluzione: ExchangeMachine.java