[POO] tp_codecheck tp3 part2.1

This commit is contained in:
TiagoRG 2023-04-12 22:52:52 +01:00
parent a3dab6d3a6
commit c632b75f80
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
3 changed files with 74 additions and 2 deletions

View File

@ -1,4 +1,4 @@
package tp_codecheck.tp03;
package tp_codecheck.tp03.part1;
/**
A simulated traffic light.

View File

@ -1,4 +1,4 @@
package tp_codecheck.tp03;
package tp_codecheck.tp03.part1;
/**
A simulated traffic light.

View File

@ -0,0 +1,72 @@
package tp_codecheck.tp03.part2;
public class RentalCar {
private boolean rented;
private static int rentedCount = 0;
private static int availableCount = 0;
/**
* Constructs a rental car.
*/
public RentalCar() {
// your work here
rented = false;
RentalCar.availableCount++;
}
/**
* Get number of cars available.
*
* @return count of cars that are available
*/
public static int numAvailable() {
// your work here
return RentalCar.availableCount;
}
/**
* Get number of cars rented.
*
* @return count of cars that are rented
*/
public static int numRented() {
// your work here
return RentalCar.rentedCount;
}
/**
* Try to rent this car.
*
* @return true if the car was successfully rented, false if it was already
* rented
*/
public boolean rentCar() {
// your work here
if (this.rented) {
return false;
} else {
this.rented = true;
RentalCar.rentedCount++;
RentalCar.availableCount--;
return true;
}
}
/**
* Return rented car.
*
* @return true if the car was previously rented and is now returned,
* false if it was not previously rented
*/
public boolean returnCar() {
// your work here
if (this.rented) {
this.rented = false;
RentalCar.rentedCount--;
RentalCar.availableCount++;
return true;
} else {
return false;
}
}
}