feat: Implemented the Table Inheritance pattern (#3105)

* sample classes and tests

* sample classes and tests

* read me addition

* fix violations

* fix quality (coverage)

* fix quality (coverage) #2

* resolved comments
This commit is contained in:
HabibaMekay
2025-01-06 19:03:27 +02:00
committed by GitHub
parent eb7a0dff55
commit c5a6862887
10 changed files with 745 additions and 0 deletions
@@ -0,0 +1,57 @@
package com.iluwatar.table.inheritance;
import lombok.Getter;
/**
* Represents a truck, a type of vehicle with a specific load capacity.
*/
@Getter
public class Truck extends Vehicle {
private double loadCapacity;
/**
* Constructs a Truck object with the given parameters.
*
* @param year the year of manufacture
* @param make the make of the truck
* @param model the model of the truck
* @param loadCapacity the load capacity of the truck
* @param id the unique ID of the truck
*/
public Truck(int year, String make, String model, double loadCapacity, int id) {
super(year, make, model, id);
if (loadCapacity <= 0) {
throw new IllegalArgumentException("Load capacity must be positive.");
}
this.loadCapacity = loadCapacity;
}
/**
* Sets the load capacity of the truck.
*
* @param capacity the new load capacity
*/
public void setLoadCapacity(double capacity) {
if (capacity <= 0) {
throw new IllegalArgumentException("Load capacity must be positive.");
}
this.loadCapacity = capacity;
}
/**
* Returns a string representation of the truck.
*
* @return a string with the truck's details
*/
@Override
public String toString() {
return "Truck{"
+ "id=" + getId()
+ ", make='" + getMake() + '\''
+ ", model='" + getModel() + '\''
+ ", year=" + getYear()
+ ", payloadCapacity=" + getLoadCapacity()
+ '}';
}
}