4 Commits
Author SHA1 Message Date
MehrdadShirvani 6cb8f9a8d8 Update README.md 2026-04-27 04:57:05 +00:00
MehrdadShirvani 4e9b7eb7ea fix: structure 2026-04-27 08:27:31 +03:30
MehrdadShirvani 7eefa807a3 fix: add more details for bonus part 2026-04-27 08:21:49 +03:30
MehrdadShirvani 22fc28130e fix: make comments clear and detailed 2026-04-27 08:21:32 +03:30
8 changed files with 30 additions and 216 deletions
+11 -4
View File
@@ -41,9 +41,9 @@ The project consists of the following classes and interfaces:
| GasCar | | ElectricCar |
| (Class) | | (Class) |
+-------------------+ +-------------------+
^ ^ ^
^ | |
| extends | implements | implements
| | |
|
+-------------------+ +-------------------+ +-------------------+
| SportsCar | | Refuelable | | Chargeable |
| (Class) | | (Interface) | | (Interface) |
@@ -118,7 +118,14 @@ Add a `HybridCar` class
- Create a `HybridCar` class that extends `Car`.
- It will need variables for both battery level and fuel level
- Implement `Refuelable` and `Chargeable` together
- (Optional) Override methods to manage both power sources (driving drains battery first, then gas)
- Service logic for HybridCar:
```
needsService(): return true if mileage > 10000
performService():
Print "Engine oil changed and battery system checked"
Reset fuelLevel to 100
Reset chargeLevel to 100
```
## Workflow
1. Fork the repository to your own Git account
@@ -133,6 +140,6 @@ git checkout -b develop
```
git push origin develop
```
7. Create a Pull Request from `develop` to `main`
7. Create a Pull Request from `develop` to `main` or `master`
# GOOD LUCK! :)
+14 -38
View File
@@ -1,12 +1,5 @@
package org;
import org.model.ElectricCar;
import org.model.GasCar;
import org.model.SportsCar;
import org.model.Vehicle;
import org.util.VehicleInspector;
import org.behavior.Serviceable;
public class Main {
public static void main(String[] args) {
@@ -24,15 +17,8 @@ public class Main {
// ElectricCar tesla = new ElectricCar(...);
// ============================================================
ElectricCar chevrolet = new ElectricCar("Chevrolet", "Bolt EV",
2023, 8500, 5, 65, 80) ;
GasCar toyota = new GasCar("Toyota", "Camery",
2022, 45000, 5, 65, "Petrol");
SportsCar lamborghini = new SportsCar("Lamborghini", "Huracan EVO",
2022, 9500, 2, 55, "Petrol",
3.2) ;
// ============================================================
@@ -46,7 +32,8 @@ public class Main {
// as their parent type (Vehicle).
// ============================================================
Vehicle[] vehicle = {chevrolet, toyota, lamborghini};
// ============================================================
@@ -60,11 +47,9 @@ public class Main {
// behavior and can call inherited methods.
// ============================================================
for (Vehicle v : vehicle)
{
v.basicInfo();
System.out.println();
}
// ============================================================
// TODO 4:
@@ -77,11 +62,9 @@ public class Main {
// • Show subclassspecific inspection messages
// ============================================================
for(Vehicle v : vehicle)
{
VehicleInspector.inspect(v) ;
System.out.println();
}
// ============================================================
// TODO 5:
@@ -97,7 +80,9 @@ public class Main {
//
// ============================================================
Serviceable[] serviceables = {chevrolet, toyota, lamborghini};
// ============================================================
// TODO 6:
@@ -121,17 +106,6 @@ public class Main {
// Add blank lines between each item for readability.
// ============================================================
for (Serviceable s : serviceables)
{
Vehicle v = (Vehicle) s;
if (s.needsService(v))
{
System.out.println(v.getBrand() + " " + v.getModel() + " need service !!");
s.performService();
}
else
System.out.println(v.getBrand() + "" + v.getModel() + "" + " does not need service :)");
}
@@ -144,7 +118,9 @@ public class Main {
//
// ============================================================
System.out.println("=== Workshop Completed ===");
}
}
+1 -22
View File
@@ -19,20 +19,13 @@ public abstract class Car extends Vehicle implements Serviceable {
double mileage, int seats) {
// TODO: Call super constructor
super(brand, model, year, mileage);
this.seats = seats;
}
// TODO: Override getEnergyType() → return "Unknown"
@Override
public String getEnergyType()
{
return "Unknown " ;
}
// TODO: Override showDetails()
@Override
public abstract void showDetails();
// Print brand, model, year, mileage, and number of seats
/*
* Implement Serviceable methods:
@@ -45,18 +38,4 @@ public abstract class Car extends Vehicle implements Serviceable {
* performService():
* - Print: "General car service completed"
*/
@Override
public boolean needsService(Vehicle v)
{
if (this.getMileage() > 10000)
{
return true;
}
return false;
}
@Override
public void performService()
{
System.out.println("General car service completed ");
}
}
+2 -47
View File
@@ -28,57 +28,12 @@ public class ElectricCar extends Car implements Chargeable {
}
// TODO: Override getEnergyType() → return "Electric"
@Override
public String getEnergyType()
{
return "Electric" ;
}
// TODO: Override showDetails()
@Override
public void showDetails() {}
// Call super.showDetails()
// Print battery capacity and charge level
// TODO: Implement charge(double amount)
// Validate negative
// Cap at 100
public void charge(double amount)
{
if (amount<0)
{
System.out.println("Error : The charge amount can not be negative. :)");
return;
}
if (amount==0)
{
System.out.println("Nothing for charge! :)");
return;
}
if (amount>0)
{
chargeLevel+=amount;
if(chargeLevel>100)
{
chargeLevel=100;
System.out.println("Charge is full :)");
}
else
System.out.println("fuel level : " + chargeLevel + "%");
}
}
@Override
public boolean needsService(Vehicle v)
{
if (this.getMileage() > 8000)
return true;
return false;
}
@Override
public void performService()
{
System.out.println("Battery system checked");
chargeLevel = 100 ;
System.out.println("Charge level : 100%");
}
}
+2 -47
View File
@@ -28,57 +28,12 @@ public class GasCar extends Car implements Refuelable {
}
// TODO: Override getEnergyType() → return fuelType + " (Gas)"
@Override
public String getEnergyType()
{
return fuelType+" (Gas)" ;
}
// TODO: Implement refuel(double amount)
// Validate amount
// Cap at 100
public void refuel(double amount)
{
if (amount<0)
{
System.out.println("Error : the refuel amount can not be negative. :)");
return;
}
if (amount==0)
{
System.out.println("Nothing for refuel! :)");
return;
}
if (amount>0)
{
fuelLevel+=amount;
if(fuelLevel>100)
{
fuelLevel=100;
System.out.println("Tank is full :)");
}
else
System.out.println("fuel level : " + fuelLevel + "%");
}
}
// TODO: Override showDetails()
@Override
public void showDetails() {}
@Override
public boolean needsService(Vehicle v)
{
if (this.getMileage() > 12000)
return true;
return false;
}
@Override
public void performService()
{
System.out.println("Engine oil changed");
fuelLevel = 100 ;
System.out.println("fuel level : 100%");
}
// Call super.showDetails()
// Print fuel level and fuel type
}
-21
View File
@@ -25,27 +25,6 @@ public class SportsCar extends GasCar {
}
// TODO: Override showDetails()
// Print header
// Call super.showDetails()
// Print acceleration time
public void showDetails()
{
System.out.println("====Sports Car Specifications====");
super.showDetails() ;
System.out.println("Acceleration : " + zeroToHundred + "s");
}
@Override
public boolean needsService(Vehicle v)
{
if ( this.getMileage() > 5000)
return true;
return false;
}
@Override
public void performService()
{
System.out.println("High-performance brake system checked");
}
}
-28
View File
@@ -21,41 +21,13 @@ public abstract class Vehicle {
}
// TODO: Create getters for all fields
public String getBrand ()
{
return brand;
}
public String getModel ()
{
return model ;
}
public int getYear ()
{
return year;
}
public double getMileage ()
{
return mileage;
}
// TODO: Implement addMileage(double km)
// If km is negative → print error
// Otherwise increase mileage
public void addMileage (double km)
{
if (km<0)
System.out.println("Error: km is negative");
else
mileage += km;
}
// TODO: Declare abstract method getEnergyType()
public abstract String getEnergyType();
public void basicInfo() {
System.out.println(
year + " " + brand + " " + model +
@@ -1,9 +1,6 @@
package org.util;
import org.*;
import org.model.ElectricCar;
import org.model.GasCar;
import org.model.SportsCar;
import org.model.Vehicle;
/*
@@ -21,11 +18,5 @@ public class VehicleInspector {
// If ElectricCar → print "Check battery system"
// If SportsCar → print "Check brakes and performance"
// If GasCar → print "Check engine and oil"
if (v instanceof ElectricCar)
System.out.println("Check battrey system");
else if(v instanceof SportsCar)
System.out.println("Check brakes and performance");
else if(v instanceof GasCar)
System.out.println("Check engine and oil");
}
}