ElectricCar + car + Vehicle
This commit is contained in:
@@ -19,12 +19,28 @@ 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 void showDetails()
|
||||
{
|
||||
System.out.println("brand : " + GetBrand) ;
|
||||
System.out.println("model : " + GetModel ) ;
|
||||
System.out.println("year : " + GetYear ) ;
|
||||
System.out.println("mileage : " + GetMileage) ;
|
||||
System.out.println("seats : " + seats) ;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Implement Serviceable methods:
|
||||
@@ -37,4 +53,13 @@ public abstract class Car extends Vehicle implements Serviceable {
|
||||
* performService():
|
||||
* - Print: "General car service completed"
|
||||
*/
|
||||
@Override
|
||||
public boolean needsService(Vehicle v)
|
||||
{
|
||||
return this.GetMileage() > 10000 ;
|
||||
}
|
||||
@Override void performService(){
|
||||
System.out.println("General car service completed") ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,9 +28,45 @@ public class ElectricCar extends Car implements Chargeable {
|
||||
}
|
||||
|
||||
// TODO: Override getEnergyType() → return "Electric"
|
||||
public String getEnergyType()
|
||||
{
|
||||
return "Electric" ;
|
||||
}
|
||||
|
||||
// TODO: Override showDetails()
|
||||
|
||||
@Override
|
||||
public String showDetails()
|
||||
{
|
||||
super.showDetails() ;
|
||||
System.out.println("battry capacity : " + batteryCapacity) ;
|
||||
System.out.println("charge level : " + chargeLevel) ;
|
||||
}
|
||||
@Override
|
||||
public void charge(double amount)
|
||||
{
|
||||
if (amount < 0 )
|
||||
{
|
||||
System.out.println("No") ;
|
||||
}
|
||||
else
|
||||
{
|
||||
chargeLevel = chargeLevel + amount ;
|
||||
if (chargeLevel > 100)
|
||||
{
|
||||
chargeLevel = 100 ;
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean needService(vehicle v)
|
||||
{
|
||||
return (this.Getmileage()> 8000)
|
||||
}
|
||||
@Override
|
||||
public void performService()
|
||||
{
|
||||
System.out.println("Battery system checked") ;
|
||||
chargeLevel = 100 ;
|
||||
}
|
||||
// TODO: Implement charge(double amount)
|
||||
// Validate negative
|
||||
// Cap at 100
|
||||
|
||||
@@ -21,12 +21,39 @@ public abstract class Vehicle {
|
||||
}
|
||||
|
||||
// TODO: Create getters for all fields
|
||||
|
||||
public String GetBrand()
|
||||
{
|
||||
return this.brand ;
|
||||
}
|
||||
public String GetModel()
|
||||
{
|
||||
return this.model ;
|
||||
}
|
||||
public int GetYear()
|
||||
{
|
||||
return this.year ;
|
||||
}
|
||||
public double GetMileage()
|
||||
{
|
||||
return this.mileage ;
|
||||
}
|
||||
// TODO: Implement addMileage(double km)
|
||||
public void AddMileage(double km)
|
||||
{
|
||||
if (km < 0 )
|
||||
{
|
||||
System.out.println("error !") ;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.mileage = this.mileage + km ;
|
||||
}
|
||||
}
|
||||
// If km is negative → print error
|
||||
// Otherwise increase mileage
|
||||
|
||||
// TODO: Declare abstract method getEnergyType()
|
||||
public abstract String getEnergyType();
|
||||
|
||||
public void basicInfo() {
|
||||
System.out.println(
|
||||
|
||||
Reference in New Issue
Block a user