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...
Why is java programming better than bash scripting. Why should programmers write in java code ?...
Why is java programming better than bash scripting. Why should programmers write in java code ? Come up with situations where java is a better option.
Write a Java test program, all the code should be in a single main method, that...
Write a Java test program, all the code should be in a single main method, that prompts the user for a single character. Display a message indicating if the character is a letter (a..z or A..Z), a digit (0..9), or other. Java's Scanner class does not have a nextChar method. You can use next() or nextLine() to read the character entered by the user, but it is returned to you as a String. Since we are only interested in the...
Language for this question is Java write the code for the given assignment Given an n...
Language for this question is Java write the code for the given assignment Given an n x n matrix, where every row and column is sorted in non-decreasing order. Print all elements of matrix in sorted order.Input: The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer n denoting the size of the matrix. Then the next line contains the n x n elements...
As in previous labs, please write the Java code for each of the following exercises in...
As in previous labs, please write the Java code for each of the following exercises in BlueJ. For each exercise, write a comment before the code stating the exercise number. Make sure you are using the appropriate indentation and styling conventions Exercise 1 (15 Points) In BlueJ, create a new project called Lab6 In the project create a class called Company Add instance data (fields) for the company name (a String) and the sales for the current period (a double)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT