From 9477eb84f5239295dfb3eeca3ac4c25b5146c113 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Wed, 12 Apr 2023 22:52:52 +0100 Subject: [PATCH] [POO] tp_codecheck tp3 part2.1 --- .../tp03/{ => part1}/TrafficLight1.java | 2 +- .../tp03/{ => part1}/TrafficLight2.java | 2 +- .../tp_codecheck/tp03/part2/RentalCar.java | 72 +++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) rename 1ano/2semestre/poo/src/tp_codecheck/tp03/{ => part1}/TrafficLight1.java (97%) rename 1ano/2semestre/poo/src/tp_codecheck/tp03/{ => part1}/TrafficLight2.java (97%) create mode 100644 1ano/2semestre/poo/src/tp_codecheck/tp03/part2/RentalCar.java diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp03/TrafficLight1.java b/1ano/2semestre/poo/src/tp_codecheck/tp03/part1/TrafficLight1.java similarity index 97% rename from 1ano/2semestre/poo/src/tp_codecheck/tp03/TrafficLight1.java rename to 1ano/2semestre/poo/src/tp_codecheck/tp03/part1/TrafficLight1.java index 16a2a86..b8c314f 100644 --- a/1ano/2semestre/poo/src/tp_codecheck/tp03/TrafficLight1.java +++ b/1ano/2semestre/poo/src/tp_codecheck/tp03/part1/TrafficLight1.java @@ -1,4 +1,4 @@ -package tp_codecheck.tp03; +package tp_codecheck.tp03.part1; /** A simulated traffic light. diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp03/TrafficLight2.java b/1ano/2semestre/poo/src/tp_codecheck/tp03/part1/TrafficLight2.java similarity index 97% rename from 1ano/2semestre/poo/src/tp_codecheck/tp03/TrafficLight2.java rename to 1ano/2semestre/poo/src/tp_codecheck/tp03/part1/TrafficLight2.java index 154113d..a929261 100644 --- a/1ano/2semestre/poo/src/tp_codecheck/tp03/TrafficLight2.java +++ b/1ano/2semestre/poo/src/tp_codecheck/tp03/part1/TrafficLight2.java @@ -1,4 +1,4 @@ -package tp_codecheck.tp03; +package tp_codecheck.tp03.part1; /** A simulated traffic light. diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp03/part2/RentalCar.java b/1ano/2semestre/poo/src/tp_codecheck/tp03/part2/RentalCar.java new file mode 100644 index 0000000..f10c708 --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/tp03/part2/RentalCar.java @@ -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; + } + } +}