In: Computer Science
*// 1- Add JavaDoc to This classes 2- Mak a UML */ import java.util.*; public class Display { public static void main(String[] args) { altEnerCar car1 = new altEnerCar(20000, 2001, 20000); altEnerCar car2 = new HydrogenCar(0, 2012, 50000, 100, false); altEnerCar car3 = new ElectricCar(0, 2014, 30000, 10, 50); altEnerCar car4 = new NaturalGasCar(0, 2000, 60000, 5, 20); altEnerCar car5 = new PropaneCar(0, 2011, 45000, 10, true); ArrayList<altEnerCar> cars = new ArrayList<altEnerCar>(); cars.add(car1); cars.add(car2); cars.add(car3); cars.add(car4); cars.add(car5); Collections.sort(cars); System.out.println(cars); } }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public class ElectricCar extends NoEmissionsCar { private double batterycharge; public ElectricCar() { this.batterycharge = 200; } public ElectricCar(double miles, int yearmade, double price, double fuelcost, double batterycharge) { super(miles, yearmade, price, fuelcost); this.batterycharge = batterycharge; } @Override public void setFuelCost(double fuelcost) { this.fuelcost = fuelcost; } @Override public double getFuelCost() { return this.fuelcost; } public void setBatteryCharge(double batterycharge) { this.batterycharge = batterycharge; } public double getBatteryCharge() { return this.batterycharge; } @Override public String toString() { return "\tMiles: "+miles+"\tMake year: "+yearmade+"\tPrice: "+price+"\tFuel cost: "+fuelcost+"\tBatery Charge: "+batterycharge; } }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public abstract class EmissionsCar extends altEnerCar { protected double emissions; public EmissionsCar() { this.emissions = 60; } public EmissionsCar(double miles, int yearmade, double price, double emissions) { super(miles, yearmade, price); this.emissions = emissions; } public abstract void setEmissions(double emissions); public abstract double getEmissions(); }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public class HydrogenCar extends NoEmissionsCar { private boolean infastructure; public HydrogenCar() { this.infastructure = false; } public HydrogenCar(double miles, int yearmade, double price, double fuelcost, boolean infastructure) { super(miles, yearmade, price, fuelcost); this.infastructure = infastructure; } @Override public void setFuelCost(double fuelcost) { this.fuelcost = fuelcost; } @Override public double getFuelCost() { return this.fuelcost; } public void setInfastructure(boolean infastructure) { this.infastructure = infastructure; } public boolean getInfastructure(boolean infastructure) { return this.infastructure; } @Override public String toString() { return "\tMiles: "+miles+"\tMake Year: "+yearmade+"\tPrice: "+price+"\tFuel Cost: "+fuelcost+"\tInfrastructure: "+infastructure; } }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public class NaturalGasCar extends EmissionsCar { private double methaneemissions; public NaturalGasCar() { this.methaneemissions = 15; } public NaturalGasCar(double miles, int yearmade, double price, double emissions, double methaneemissions) { super(miles, yearmade, price, emissions); this.methaneemissions = methaneemissions; } @Override public void setEmissions(double emissions) { this.emissions = emissions; } @Override public double getEmissions() { return this.emissions; } public void setMethaneEmissions(double methaneemissions) { this.methaneemissions = methaneemissions; } public double getMethaneEmissions() { return this.methaneemissions; } @Override public String toString() { return "\tMiles: "+miles+"\tMake Year: "+yearmade+"\tPrice: "+price+"\tEmission: "+emissions+"\tMethane Emission: "+methaneemissions; } }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public abstract class NoEmissionsCar extends altEnerCar { protected double fuelcost; public NoEmissionsCar() { this.fuelcost = 30; } public NoEmissionsCar(double miles, int yearmade, double price, double fuelcost) { super(miles, yearmade, price); this.fuelcost = fuelcost; } public abstract void setFuelCost(double fuelcost); public abstract double getFuelCost(); }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public class PropaneCar extends EmissionsCar { private boolean infastructure; public PropaneCar() { this.infastructure = true; } public PropaneCar(double miles, int yearmade, double price, double emissions, boolean infastructure) { super(miles, yearmade, price, emissions); this.infastructure = infastructure; } @Override public void setEmissions(double emissions) { this.emissions = emissions; } @Override public double getEmissions() { return this.emissions; } public void setMethaneEmissions(boolean infastructure) { this.infastructure = infastructure; } public boolean getMethaneEmissions() { return this.infastructure; } @Override public String toString() { return "\tMiles: "+miles+"\tMake Year: "+yearmade+"\tPrice: "+price+"\tEmissions: "+emissions+"\t Infrastructure: "+infastructure; } }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public class altEnerCar implements Comparable<altEnerCar> { protected double miles; protected int yearmade; protected double price; public altEnerCar() { this.miles = 0; this.yearmade = 2019; this.price = 50000; } public altEnerCar(double miles, int yearmade, double price) { this.miles = miles; this.yearmade = yearmade; this.price = price; } public void setMiles(double miles) { this.miles = miles; } public void setYearMade(int yearmade) { this.yearmade = yearmade; } public void setPrice(double price) { this.price = price; } public double getMiles() { return this.miles; } public int getYearMade(int yearmade) { return this.yearmade; } public double getPrice() { return this.price; } public String toString() { return "\nmiles: "+miles+"\nyear made: "+yearmade+"\nprice: "+price; } public int compareTo(altEnerCar otherAECar) { return -1*(Double.valueOf(otherAECar.getPrice()).compareTo(this.price)); } }
import java.util.*; public class Display { public static void main(String[] args) { altEnerCar car1 = new altEnerCar(20000, 2001, 20000); altEnerCar car2 = new HydrogenCar(0, 2012, 50000, 100, false); altEnerCar car3 = new ElectricCar(0, 2014, 30000, 10, 50); altEnerCar car4 = new NaturalGasCar(0, 2000, 60000, 5, 20); altEnerCar car5 = new PropaneCar(0, 2011, 45000, 10, true); ArrayList<altEnerCar> cars = new ArrayList<altEnerCar>(); cars.add(car1); cars.add(car2); cars.add(car3); cars.add(car4); cars.add(car5); Collections.sort(cars); System.out.println(cars); } }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public class ElectricCar extends NoEmissionsCar { private double batterycharge; public ElectricCar() { this.batterycharge = 200; } public ElectricCar(double miles, int yearmade, double price, double fuelcost, double batterycharge) { super(miles, yearmade, price, fuelcost); this.batterycharge = batterycharge; } @Override public void setFuelCost(double fuelcost) { this.fuelcost = fuelcost; } @Override public double getFuelCost() { return this.fuelcost; } public void setBatteryCharge(double batterycharge) { this.batterycharge = batterycharge; } public double getBatteryCharge() { return this.batterycharge; } @Override public String toString() { return "\tMiles: "+miles+"\tMake year: "+yearmade+"\tPrice: "+price+"\tFuel cost: "+fuelcost+"\tBatery Charge: "+batterycharge; } }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public abstract class EmissionsCar extends altEnerCar { protected double emissions; public EmissionsCar() { this.emissions = 60; } public EmissionsCar(double miles, int yearmade, double price, double emissions) { super(miles, yearmade, price); this.emissions = emissions; } public abstract void setEmissions(double emissions); public abstract double getEmissions(); }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public class HydrogenCar extends NoEmissionsCar { private boolean infastructure; public HydrogenCar() { this.infastructure = false; } public HydrogenCar(double miles, int yearmade, double price, double fuelcost, boolean infastructure) { super(miles, yearmade, price, fuelcost); this.infastructure = infastructure; } @Override public void setFuelCost(double fuelcost) { this.fuelcost = fuelcost; } @Override public double getFuelCost() { return this.fuelcost; } public void setInfastructure(boolean infastructure) { this.infastructure = infastructure; } public boolean getInfastructure(boolean infastructure) { return this.infastructure; } @Override public String toString() { return "\tMiles: "+miles+"\tMake Year: "+yearmade+"\tPrice: "+price+"\tFuel Cost: "+fuelcost+"\tInfrastructure: "+infastructure; } }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public class NaturalGasCar extends EmissionsCar { private double methaneemissions; public NaturalGasCar() { this.methaneemissions = 15; } public NaturalGasCar(double miles, int yearmade, double price, double emissions, double methaneemissions) { super(miles, yearmade, price, emissions); this.methaneemissions = methaneemissions; } @Override public void setEmissions(double emissions) { this.emissions = emissions; } @Override public double getEmissions() { return this.emissions; } public void setMethaneEmissions(double methaneemissions) { this.methaneemissions = methaneemissions; } public double getMethaneEmissions() { return this.methaneemissions; } @Override public String toString() { return "\tMiles: "+miles+"\tMake Year: "+yearmade+"\tPrice: "+price+"\tEmission: "+emissions+"\tMethane Emission: "+methaneemissions; } }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public abstract class NoEmissionsCar extends altEnerCar { protected double fuelcost; public NoEmissionsCar() { this.fuelcost = 30; } public NoEmissionsCar(double miles, int yearmade, double price, double fuelcost) { super(miles, yearmade, price); this.fuelcost = fuelcost; } public abstract void setFuelCost(double fuelcost); public abstract double getFuelCost(); }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public class PropaneCar extends EmissionsCar { private boolean infastructure; public PropaneCar() { this.infastructure = true; } public PropaneCar(double miles, int yearmade, double price, double emissions, boolean infastructure) { super(miles, yearmade, price, emissions); this.infastructure = infastructure; } @Override public void setEmissions(double emissions) { this.emissions = emissions; } @Override public double getEmissions() { return this.emissions; } public void setMethaneEmissions(boolean infastructure) { this.infastructure = infastructure; } public boolean getMethaneEmissions() { return this.infastructure; } @Override public String toString() { return "\tMiles: "+miles+"\tMake Year: "+yearmade+"\tPrice: "+price+"\tEmissions: "+emissions+"\t Infrastructure: "+infastructure; } }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author charl */ public class altEnerCar implements Comparable<altEnerCar> { protected double miles; protected int yearmade; protected double price; public altEnerCar() { this.miles = 0; this.yearmade = 2019; this.price = 50000; } public altEnerCar(double miles, int yearmade, double price) { this.miles = miles; this.yearmade = yearmade; this.price = price; } public void setMiles(double miles) { this.miles = miles; } public void setYearMade(int yearmade) { this.yearmade = yearmade; } public void setPrice(double price) { this.price = price; } public double getMiles() { return this.miles; } public int getYearMade(int yearmade) { return this.yearmade; } public double getPrice() { return this.price; } public String toString() { return "\nmiles: "+miles+"\nyear made: "+yearmade+"\nprice: "+price; } public int compareTo(altEnerCar otherAECar) { return -1*(Double.valueOf(otherAECar.getPrice()).compareTo(this.price)); } }