Question

In: Computer Science

*// 1- Add JavaDoc to This classes 2- Mak a UML */ import java.util.*; public class...

*//
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));
   }
  
}

Solutions

Expert Solution

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));
   }
  
}

Related Solutions

Add comments to the following code: PeopleQueue.java import java.util.*; public class PeopleQueue {     public static...
Add comments to the following code: PeopleQueue.java import java.util.*; public class PeopleQueue {     public static void main(String[] args) {         PriorityQueue<Person> peopleQueue = new PriorityQueue<>();         Scanner s = new Scanner(System.in);         String firstNameIn;         String lastNameIn;         int ageIn = 0;         int count = 1;         boolean done = false;         System.out.println("Enter the first name, last name and age of 5 people.");         while(peopleQueue.size() < 5) {             System.out.println("Enter a person");             System.out.print("First Name: ");             firstNameIn...
Add code to the Account class and create a new class called BalanceComparator. import java.util.*; public...
Add code to the Account class and create a new class called BalanceComparator. import java.util.*; public final class Account implements Comparable {     private String firstName;     private String lastName;     private int accountNumber;     private double balance;     private boolean isNewAccount;     public Account(             String firstName,             String lastName,             int accountNumber,             double balance,             boolean isNewAccount     ) {         this.firstName = firstName;         this.lastName = lastName;         this.accountNumber = accountNumber;         this.balance = balance;         this.isNewAccount = isNewAccount;     }     /**      * TO DO: override equals      */     @Override     public boolean equals(Object other) {...
import java.util.*; import java.security.*; import javax.crypto.*; import java.nio.file.*; public class CryptoApp {    public static void...
import java.util.*; import java.security.*; import javax.crypto.*; import java.nio.file.*; public class CryptoApp {    public static void main(String[] args) throws Exception { Crypto crypto = new BasicCrypto();        String welcome = "Hello 2043-er's! Let's try this again :-)"; System.out.println(welcome); // First, where are we? //Let's print out our current working directory        Path cwd = FileSystems.getDefault().getPath("").toAbsolutePath(); System.out.println("Current Working Directory: " + cwd); // Read in our file to encrypt    byte[] originalData = Files.readAllBytes(Paths.get(System.getProperty("user.home"), "C-2044-Sample/Crypto/src/encrypt.txt")); // Encrypt it and...
Explain the java class below, how it make: import java.util.*; import java.util.concurrent.TimeUnit; public class RacingGame {...
Explain the java class below, how it make: import java.util.*; import java.util.concurrent.TimeUnit; public class RacingGame {       ArrayList<Driver> player = new ArrayList<Driver>();    CarType car = new CarType("Ferrari","2018",280,90,15);    Formula formula = new Formula(5);// number of laps    long startTime = System.currentTimeMillis();    long currentTime = System.currentTimeMillis();    int totalDis = 0;       public static void main(String[] args)    {        RacingGame formulaRace = new RacingGame();        formulaRace.player.add(new Driver("Saleh",10,3));        formulaRace.formula.setDistance(20);//lap distance        formulaRace.totalDis...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {       public int month;    public int day;    public int year;    public Date(int month, int day, int year) {    this.month = month;    this.day = day;    this.year = year;    }       public Date() {    this.month = 0;    this.day = 0;    this.year = 0;    } } //end of Date.java // Name.java public class Name...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class Qup3 implements xxxxxlist {// implements interface    // xxxxxlnk class variables    // head is a pointer to beginning of rlinked list    private node head;    // no. of elements in the list    // private int count; // xxxxxlnk class constructor    Qup3() {        head = null;        count = 0;    } // end Dersop3 class constructor   ...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence;...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence; Message() { sentence=""; } Message(String text) { setSentence(text); } void setSentence(String text) { sentence=text; } String getSentence() { return sentence; } int getVowels() { int count=0; for(int i=0;i<sentence.length();i++) { char ch=sentence.charAt(i); if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') { count=count+1; } } return count; } int getConsonants() { int count=0; for(int i=0;i<sentence.length();i++)...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution {...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); HashMap labs = new HashMap(); while (true) { System.out.println("Choose operation : "); System.out.println("1. Create a Lab"); System.out.println("2. Modify a Lab"); System.out.println("3. Delete a Lab"); System.out.println("4. Assign a pc to a Lab"); System.out.println("5. Remove a pc from a Lab"); System.out.println("6. Quit"); int choice = sc.nextInt(); String name=sc.nextLine(); switch (choice) { case 1:...
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {   ...
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {    public static void main(String[] args) {        //Generate random array for test and copy that into 3 arrays        int[] arr1=new int[20];        int[] arr2=new int[20];        int[] arr3=new int[20];        int[] arr4=new int[20];        Random rand = new Random();        for (int i = 0; i < arr1.length; i++) {            //Generate random array...
// problem2.java import java.util.*; public class problem_a { public static void main(String[] args) { // test...
// problem2.java import java.util.*; public class problem_a { public static void main(String[] args) { // test the smallest method System.out.print("smallest(1, 0, 2) -> "); System.out.println( smallest(1, 0, 2) ); // test the average method System.out.print("average(95, 85, 90) -> "); System.out.println( average(95, 84, 90) ); } // end main /* * smallest(double, double, double) -> double * * method is given 3 numbers, produces the smallest of the three * * examples: * smallest(1, 0, 2) -> 0.0 */ public static...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT