Question

In: Computer Science

Write in Java. Separate code for each question. The answer to the first question should NOT...

Write in Java. Separate code for each question. The answer to the first question should NOT be comparable.


1. Write a class to represent a AlternativeEnergyCar. Select the fields and methods that fit the modeling of an alternative energy car. Make sure to include code for the constructors, set/get methods, a toString() method.

2. Inheritance – Create two abstract subclasses of AECar, one for Electric cars and one for Altfuel cars. Next create four additional subclasses., two for types of Electric cars and two for Altfuel cars( for example, Altfuel cars might be Hydrogen powered or Biofuel powered.) Decide which properties should be pushed up into a super abstract class and which belong in the individual subclasses. You do not need to code every method – just place a stub placeholders. (This answer should be a UML).

Solutions

Expert Solution

>>Answer

>>Given


AlternativeEnergyCar.java


public class AlternativeEnergyCar implements Comparable<AlternativeEnergyCar>
{
protected double miles;
protected int yearmade;
protected double price;
  
public AlternativeEnergyCar()
{
this.miles = 0;
this.yearmade = 2019;
this.price = 50000;
}
public AlternativeEnergyCar(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(AlternativeEnergyCar otherAECar)
{
return -1*(Double.valueOf(otherAECar.getPrice()).compareTo(this.price));
}
  
}


HydrogenCar.java


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 "\nmiles: "+miles+"\nyear made: "+yearmade+"\nprice: "+price+"\nfuel cost: "+fuelcost+"\ninfastructure: "+infastructure;
}
}


Related Solutions

Java Problem: Please answer both parts of the question fully: (a). Write Java code for a...
Java Problem: Please answer both parts of the question fully: (a). Write Java code for a method to test if a LinkedList<Long> has Long values that form a Fibonacci sequence from the beginning to the end and return true if it is and false otherwise. A sequence of values is Fibonnaci if every third value is equal to sum of the previous two. Eg., 3,4,7,11,18,29 is a Fibonacci sequence whereas 1,2,3,4 is not, because 2+3 is not equal to 4....
Instructions: Please write all answers in java Each problem should be completed as a single separate...
Instructions: Please write all answers in java Each problem should be completed as a single separate .java file, each with its own main(). Inputs should be read using a Scanner object and output should be printed using System.out.println. As you finish each question, submit your code to the autograder at: http://162.243.28.4/grader/homework2.html Make sure to include your name at the top as a single word. The submission utility will test your code against a different input than the sample given. When...
This is an entry to Java Question. Please answer with Pseudocode and Java code for better...
This is an entry to Java Question. Please answer with Pseudocode and Java code for better understanding. We are mainly using basic in and out declarations and are focusing on API for method invocations. Any help would be very appreciated :) Problem 7: Distance (10 points) Use API (Data Science) Data Science is an emergent field from Computer Science with applications in almost every domain including finances, medical research, entertainment, retail, advertising, and insurance. The role of a data analyst...
This is an intro to java question. Please post with pseudocode and java code. Problem should...
This is an intro to java question. Please post with pseudocode and java code. Problem should be completed using repetition statements like while and selection statements. Geometry (10 points) Make API (API design) Java is an extensible language, which means you can expand the programming language with new functionality by adding new classes. You are tasked to implement a Geometry class for Java that includes the following API (Application Programming Interface): Geometry Method API: Modifier and Type Method and Description...
Write a question and answer it. (Question should not be a textbook type, it should be...
Write a question and answer it. (Question should not be a textbook type, it should be interpretation type question) I'm a first grader molecular biology and genetics student
Write a java code that first discards as many whitespace characters as necessary until the first...
Write a java code that first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function. If the first sequence of non-whitespace...
Write a java code that first discards as many whitespace characters as necessary until the first...
Write a java code that first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function. If the first sequence of non-whitespace...
Write a java code to demonstrate the File IO. Your code should get the following information...
Write a java code to demonstrate the File IO. Your code should get the following information from the user. • Get a file name fname for output • Get number of data (numbers) (N) you want to process from the user • Get N numbers from the users through keyboard and store them in an array • Get M (How many numbers to read from file) • (Or)You are free to use same N for M (use N for both...
Write a java code to demonstrate the File IO. Your code should get the following information...
Write a java code to demonstrate the File IO. Your code should get the following information from the user. • Get a file name fname for output • Get number of data (numbers) (N) you want to process from the user • Get N numbers from the users through keyboard and store them in an array • Get M (How many numbers to read from file) • (Or)You are free to use same N for M (use N for both...
Write a java code to demonstrate the File IO. Your code should get the following information...
Write a java code to demonstrate the File IO. Your code should get the following information from the user. • Get a file name fname for output • Get number of data (numbers) (N) you want to process from the user • Get N numbers from the users through keyboard and store them in an array • Get M (How many numbers to read from file) • (Or)You are free to use same N for M (use N for both...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT