What would be best way to use LocalDate for needsMaintenance if the aircrafts last mainenace date is 3 months or more or the last maintenance mileage is 150,000 miles or more ShouldRetire- If the yearsInService is more than 20 years using LocalDate If there are more than 2,000,000 air miles In Java
public class Aircraft
{
// instance vairables
private String aircraftName;
private String regNumber;
private String manufacturer;
privateintmaxRange;
privateintcrewSize;
private LocalDate yearPutInService;
privateintmaxServiceWeight;
privateintnumberOfPassengers;
privateintcurrentAirMiles;
private LocalDate lastMaintenanceDate;
privateintlastMaintenanceMiles;
/**
* Default Constructor
*
* @param lastMaintenanceMiles
* @param lastMaintenanceDate
* @param totalMiles
* @param model
* @param manufacturer
* @param regNumber
* @param vehicleType
*/
public Aircraft(String aircraftName, String regNumber, String manufacturer, intmaxRange, intcrewSize,
LocalDate yearPutInService, int maxServiceWeight, int numberOfPassengers, int currentAirMiles,
LocalDate lastMaintenanceDate, int lastMaintenanceMiles)
{
{
this.aircraftName = aircraftName;
this.regNumber = regNumber;
this.manufacturer = manufacturer;
this.maxRange = maxRange;
this.crewSize = crewSize;
this.yearPutInService = yearPutInService;
this.maxServiceWeight = maxServiceWeight;
this.numberOfPassengers = numberOfPassengers;
this.currentAirMiles = currentAirMiles;
this.lastMaintenanceDate = lastMaintenanceDate;
this.lastMaintenanceMiles = lastMaintenanceMiles;
}
}
publicboolean needsMaintenance()
{
LocalDate currentDate = LocalDate.now();
LocalDate maintenanceDate = lastMaintenanceDate.plusMonths(3);
intmaintenance = 150000;
if (currentDate.isAfter(maintenanceDate) || currentAirMiles - lastMaintenanceMiles >= maintenance)
{
returntrue;
} else
{
returnfalse;
}
}
publicboolean shouldRetire()
{
intyearsInService = Period.between(yearPutInService, LocalDate.now()).getYears();
if (yearsInService >= 20 || currentAirMiles >= 2000000)
{
returntrue;
} else
{
returnfalse;
}
}
public String getAircraftName()
{
returnaircraftName;
}
public String getRegNumber()
{
returnregNumber;
}
public String getManufacturer()
{
returnmanufacturer;
}
publicint getMaxRange()
{
returnmaxRange;
}
publicint getCrewSize()
{
returncrewSize;
}
public LocalDate getYearPutInService()
{
returnyearPutInService;
}
publicint getMaxServiceWeight()
{
returnmaxServiceWeight;
}
publicint getNumPassengers()
{
returnnumberOfPassengers;
}
publicint getCurrentAirMiles()
{
returncurrentAirMiles;
}
publicvoid setCurrentAirMiles(intcurrentAirMiles)
{
this.currentAirMiles = currentAirMiles;
}
public LocalDate getLastMaintenanceDate()
{
returnlastMaintenanceDate;
}
publicvoid setLastMaintenanceDate(LocalDate lastMaintenanceDate)
{
this.lastMaintenanceDate = lastMaintenanceDate;
}
publicint getLastMaintenaceMiles()
{
returnlastMaintenanceMiles;
}
publicvoid setLastMaintenanceMiles(intlastMaintenanceMiles)
{
this.lastMaintenanceMiles = lastMaintenanceMiles;
}
@Override
public String toString()
{
return"Aircraft [aircraftName=" + aircraftName + ", regNumber=" + regNumber + ", manufacturer=" + manufacturer
+ ", lastMaintenanceDate=" + lastMaintenanceDate + ", lastMaintenanceMiles=" + lastMaintenanceMiles
+ "]";
}
}
What would be best way to use LocalDate for needsMaintenance if the aircrafts last mainenace date is 3 months or more or the last maintenance mileage is 150,000 miles or more
ShouldRetire- If the yearsInService is more than 20 years using LocalDate
If there are more than 2,000,000 air miles
In Java
Step by step
Solved in 3 steps