Skip to content

Commit 50be660

Browse files
committed
fix violations
1 parent bb3899a commit 50be660

File tree

7 files changed

+274
-87
lines changed

7 files changed

+274
-87
lines changed
Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,52 @@
11
package com.iluwatar;
22

3+
/**
4+
* Represents a car with a specific number of doors.
5+
*/
36
public class Car extends Vehicle {
47
private int numDoors;
58

9+
/**
10+
* Constructs a Car object.
11+
*
12+
* @param year the manufacturing year
13+
* @param make the make of the car
14+
* @param model the model of the car
15+
* @param numDoors the number of doors
16+
* @param id the unique identifier for the car
17+
*/
618
public Car(int year, String make, String model, int numDoors, int id) {
719
super(year, make, model, id);
820
this.numDoors = numDoors;
921
}
1022

11-
public void SetNumDoors(int doors){
12-
this.numDoors=doors;
23+
/**
24+
* Sets the number of doors for the car.
25+
*
26+
* @param doors the number of doors
27+
*/
28+
public void setNumDoors(int doors) {
29+
this.numDoors = doors;
1330
}
14-
public int GetNumDoors(){
31+
32+
/**
33+
* Gets the number of doors for the car.
34+
*
35+
* @return the number of doors
36+
*/
37+
public int getNumDoors() {
1538
return numDoors;
1639
}
1740

18-
@Override public String toString() {
19-
return "Car{" + "id=" + getId() + ", make='" + getMake() + '\'' + ", model='" + getModel() + '\'' + ", year=" + getYear() + ", numberOfDoors=" + GetNumDoors() + '}';
41+
@Override
42+
public String toString() {
43+
return "Car{"
44+
+ "id=" + getId()
45+
+ ", make='" + getMake() + '\''
46+
+ ", model='" + getModel() + '\''
47+
+ ", year=" + getYear()
48+
+ ", numberOfDoors=" + getNumDoors()
49+
+ '}';
2050
}
21-
2251
}
52+

table-inheritance/src/main/java/com/iluwatar/Main.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package com.iluwatar;
22

3+
/**
4+
* The main entry point of the application demonstrating the use of vehicles.
5+
*/
36
public class Main {
7+
8+
/**
9+
* The main method to demonstrate adding and retrieving vehicles from the database.
10+
*
11+
* @param args command-line arguments
12+
*/
413
public static void main(String[] args) {
5-
Vehicle_Database database = new Vehicle_Database();
14+
VehicleDatabase database = new VehicleDatabase();
615

716
Car car = new Car(2020, "Toyota", "Corolla", 4, 1);
8-
Truck truck = new Truck(2018, "Ford", "F-150", 60,2);
17+
Truck truck = new Truck(2018, "Ford", "F-150", 60, 2);
918

1019
database.saveVehicle(car);
1120
database.saveVehicle(truck);
@@ -21,4 +30,4 @@ public static void main(String[] args) {
2130
Truck retrievedTruck = database.getTruck(truck.getId());
2231
System.out.println("Retrieved Truck: " + retrievedTruck);
2332
}
24-
}
33+
}
Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,56 @@
11
package com.iluwatar;
22

3+
/**
4+
* Represents a truck, a type of vehicle with a specific load capacity.
5+
*/
36
public class Truck extends Vehicle {
47
private double loadCapacity;
58

9+
/**
10+
* Constructs a Truck object with the given parameters.
11+
*
12+
* @param year the year of manufacture
13+
* @param make the make of the truck
14+
* @param model the model of the truck
15+
* @param loadCapacity the load capacity of the truck
16+
* @param id the unique ID of the truck
17+
*/
618
public Truck(int year, String make, String model, double loadCapacity, int id) {
7-
super(year,make, model, id);
8-
this.loadCapacity=loadCapacity;
19+
super(year, make, model, id);
20+
this.loadCapacity = loadCapacity; // Added spaces around '='
921
}
1022

11-
public void SetLoadCapacity(double capacity){
12-
this.loadCapacity=capacity;
23+
/**
24+
* Sets the load capacity of the truck.
25+
*
26+
* @param capacity the new load capacity
27+
*/
28+
public void setLoadCapacity(double capacity) {
29+
this.loadCapacity = capacity; // Added spaces around '='
1330
}
14-
public double GetLoadCapacity(){
31+
32+
/**
33+
* Retrieves the load capacity of the truck.
34+
*
35+
* @return the load capacity
36+
*/
37+
public double getLoadCapacity() {
1538
return loadCapacity;
1639
}
1740

18-
@Override public String toString() {
19-
return "Truck{" + "id=" + getId() + ", make='" + getMake() + '\'' + ", model='" + getModel() + '\'' + ", year=" + getYear() + ", payloadCapacity=" + GetLoadCapacity() + '}'; }
20-
}
41+
/**
42+
* Returns a string representation of the truck.
43+
*
44+
* @return a string with the truck's details
45+
*/
46+
@Override
47+
public String toString() {
48+
return "Truck{"
49+
+ "id=" + getId()
50+
+ ", make='" + getMake() + '\''
51+
+ ", model='" + getModel() + '\''
52+
+ ", year=" + getYear()
53+
+ ", payloadCapacity=" + getLoadCapacity()
54+
+ '}';
55+
}
56+
}
Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,114 @@
11
package com.iluwatar;
22

3-
public class Vehicle{
3+
/**
4+
* Represents a generic vehicle with basic attributes like make, model, year, and ID.
5+
*/
6+
public class Vehicle {
47

5-
private String make, model;
6-
private int year, id;
8+
private String make;
9+
private String model;
10+
private int year;
11+
private int id;
712

8-
9-
Vehicle(int year, String make, String model, int id){
10-
this.make=make;
11-
this.model=model;
12-
this.year=year;
13-
this.id=id;
13+
/**
14+
* Constructs a Vehicle object with the given parameters.
15+
*
16+
* @param year the year of manufacture
17+
* @param make the make of the vehicle
18+
* @param model the model of the vehicle
19+
* @param id the unique ID of the vehicle
20+
*/
21+
public Vehicle(int year, String make, String model, int id) {
22+
this.make = make; // Added spaces around '='
23+
this.model = model;
24+
this.year = year;
25+
this.id = id;
1426
}
1527

16-
public void setMake(String make){
17-
this.make=make;
28+
/**
29+
* Sets the make of the vehicle.
30+
*
31+
* @param make the make to set
32+
*/
33+
public void setMake(String make) {
34+
this.make = make; // Added spaces around '='
1835
}
36+
37+
/**
38+
* Gets the make of the vehicle.
39+
*
40+
* @return the make
41+
*/
1942
public String getMake() {
2043
return make;
2144
}
2245

23-
public void setModel(String model){
24-
this.model=model;
46+
/**
47+
* Sets the model of the vehicle.
48+
*
49+
* @param model the model to set
50+
*/
51+
public void setModel(String model) {
52+
this.model = model; // Added spaces around '='
2553
}
26-
public String getModel(){
54+
55+
/**
56+
* Gets the model of the vehicle.
57+
*
58+
* @return the model
59+
*/
60+
public String getModel() {
2761
return model;
2862
}
2963

30-
public void setYear(int year){
31-
this.year=year;
64+
/**
65+
* Sets the year of manufacture for the vehicle.
66+
*
67+
* @param year the year to set
68+
*/
69+
public void setYear(int year) {
70+
this.year = year; // Added spaces around '='
3271
}
33-
public int getYear(){
72+
73+
/**
74+
* Gets the year of manufacture for the vehicle.
75+
*
76+
* @return the year
77+
*/
78+
public int getYear() {
3479
return year;
3580
}
3681

82+
/**
83+
* Gets the unique ID of the vehicle.
84+
*
85+
* @return the ID
86+
*/
3787
public int getId() {
3888
return id;
3989
}
90+
91+
/**
92+
* Sets the unique ID of the vehicle.
93+
*
94+
* @param id the ID to set
95+
*/
4096
public void setId(int id) {
41-
this.id = id;
97+
this.id = id; // Added spaces around '='
4298
}
4399

44-
45-
@Override public String toString() {
46-
return "Vehicle{" + "id=" + id + ", make='" + make + '\'' + ", model='" + model + '\'' + ", year=" + year + '}';
100+
/**
101+
* Returns a string representation of the vehicle.
102+
*
103+
* @return a string with the vehicle's details
104+
*/
105+
@Override
106+
public String toString() {
107+
return "Vehicle{"
108+
+ "id=" + id
109+
+ ", make='" + make + '\''
110+
+ ", model='" + model + '\''
111+
+ ", year=" + year
112+
+ '}';
47113
}
48-
}
114+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.iluwatar;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
/**
7+
* Manages the storage and retrieval of Vehicle objects, including Cars and Trucks.
8+
*/
9+
public class VehicleDatabase {
10+
11+
private Map<Integer, Vehicle> vehicleTable = new HashMap<>();
12+
private Map<Integer, Car> carTable = new HashMap<>();
13+
private Map<Integer, Truck> truckTable = new HashMap<>();
14+
15+
/**
16+
* Saves a vehicle to the database. If the vehicle is a Car or Truck, it is added to the respective table.
17+
*
18+
* @param vehicle the vehicle to save
19+
*/
20+
public void saveVehicle(Vehicle vehicle) {
21+
vehicleTable.put(vehicle.getId(), vehicle);
22+
if (vehicle instanceof Car) {
23+
carTable.put(vehicle.getId(), (Car) vehicle);
24+
} else if (vehicle instanceof Truck) {
25+
truckTable.put(vehicle.getId(), (Truck) vehicle);
26+
}
27+
}
28+
29+
/**
30+
* Retrieves a vehicle by its ID.
31+
*
32+
* @param id the ID of the vehicle
33+
* @return the vehicle with the given ID, or null if not found
34+
*/
35+
public Vehicle getVehicle(int id) {
36+
return vehicleTable.get(id);
37+
}
38+
39+
/**
40+
* Retrieves a car by its ID.
41+
*
42+
* @param id the ID of the car
43+
* @return the car with the given ID, or null if not found
44+
*/
45+
public Car getCar(int id) {
46+
return carTable.get(id);
47+
}
48+
49+
/**
50+
* Retrieves a truck by its ID.
51+
*
52+
* @param id the ID of the truck
53+
* @return the truck with the given ID, or null if not found
54+
*/
55+
public Truck getTruck(int id) {
56+
return truckTable.get(id);
57+
}
58+
59+
/**
60+
* Prints all vehicles in the database.
61+
*/
62+
public void printAllVehicles() {
63+
for (Vehicle vehicle : vehicleTable.values()) {
64+
System.out.println(vehicle);
65+
}
66+
}
67+
}
68+

table-inheritance/src/main/java/com/iluwatar/Vehicle_Database.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)