How can i print the array in VehicleTest.java with out the hashcode behind the array element?
Vehicle.java
public abstract class Vehicle {
// class that can describe many vehicle types
abstract public double GetCarbonFootPrint();
}
Car.java
public class Car extends Vehicle{
private double gallon;
public Car()
{
this.gallon = 0;// set gallon to 0
}
public Car(double gallon)
{
this.gallon = gallon;
}
@Override
public double GetCarbonFootPrint() {
return (this.gallon * 20);// carbon footprint is #gallons*20
}
}
Bicycle.java
public class Bicycle extends Vehicle{
@Override
public double GetCarbonFootPrint() {
return 0; // carbon footprint is always 0
}
}
VehicleTest.java
import java.util.Arrays;
public class VehicleTest {
public static void main(String[]args)
{
// array to hold each vehicle
Vehicle vehicles[] = new Vehicle[2];
vehicles[0] = new Car(40);
vehicles[1] = new Bicycle();
// loop to display results of each vehicles footprint
for(int i = 0; i < vehicles.length; i++)
{
System.out.println("Carbon Footprint for " + vehicles[i] + ": "
+ String.format("%.2f", vehicles[i].GetCarbonFootPrint()));
}
}
}
OUTPUT
Carbon Footprint for Car@1e67b872: 800.00
Carbon Footprint for Bicycle@60addb54: 0.00
//Vehicle.java
public abstract class Vehicle {
// class that can describe many vehicle types
abstract public double GetCarbonFootPrint();
}
/////////////////////////////////////////////////////////
//Car.java
public class Car extends Vehicle{
private double gallon;
public Car()
{
this.gallon = 0;// set gallon to 0
}
public Car(double gallon)
{
this.gallon = gallon;
}
@Override
public double GetCarbonFootPrint() {
return (this.gallon * 20);// carbon footprint is #gallons*20
}
@Override
public String toString() {
return "Car{" +
"gallon=" + gallon +
'}';
}
}
/////////////////////////////////////////////////////////
//Bicycle.java
public class Bicycle extends Vehicle{
@Override
public double GetCarbonFootPrint() {
return 0; // carbon footprint is always 0
}
@Override
public String toString() {
return "Bicycle{}";
}
}
/////////////////////////////////////////////////////////
//VehicleTest.java
public class VehicleTest {
public static void main(String[]args)
{
// array to hold each vehicle
Vehicle vehicles[] = new Vehicle[2];
vehicles[0] = new Car(40);
vehicles[1] = new Bicycle();
// loop to display results of each vehicles footprint
for(int i = 0; i < vehicles.length; i++)
{
System.out.println("Carbon Footprint for " + vehicles[i] + ": "
+ String.format("%.2f", vehicles[i].GetCarbonFootPrint()));
}
}
}
/////////////////////////////////////////////////////////



How can i print the array in VehicleTest.java with out the hashcode behind the array element?...
Java Programming --- complete the given classes DeLand Space Car Dealer needs a new program for their inventory management system. The program needs the following classes: A main class (SpaceCarDealer.java) that includes the main method and GUI. Two instantiable classes: CarDealer.java o Variables to store the dealer name, and the carsOnLot array in Car type. o A constructor to initialize the name variable with the given dealer name. o An accessor method to return the name of the dealer. o...
I need help in getting the second output to show both the commission rate and the earnings for the String method output package CompemsationTypes; public class BasePlusCommissionEmployee extends CommissionEmployee { public void setGrossSales(double grossSales) { super.setGrossSales(grossSales); } public double getGrossSales() { return super.getGrossSales(); } public void setCommissionRate(double commissionRate) { super.setCommissionRate(commissionRate); } public double getCommissionRate() { return super.getCommissionRate(); } public String getFirstName() { return super.getFirstName(); } public String getLastName() { return super.getLastName(); } public String getSocialSecurityNumber() { return super.getSocialSecurityNumber(); } private...
What is wrong with the following Java Code. public class TestEdible { abstract class Animal { /** Return animal sound */ public abstract String sound(); } class Chicken extends Animal implements Edible { @Override public String howToEat() { return "Chicken: Fry it"; } @Override public String sound() { return "Chicken: cock-a-doodle-doo"; } } class Tiger extends Animal { @Override public String sound() { return "Tiger: RROOAARR"; } } abstract class Fruit implements Edible { // Data fields, constructors, and methods...
This is my code that i need to finish. In BoxRegion.java I have no idea how to create the constructor. I tried to use super(x,y) but It is hard to apply. And Also In BoxRegionHashTable, I don't know how to create displayAnnotation BoxRegion.java ------------------------------------------------ public final class BoxRegion { final Point2D p1; final Point2D p2; /** * Create a new 3D point with given x, y and z values * * @param x1, y1 are the x,y coordinates for point...
I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a void method named howToColor(). void howToColor(); } GeometricObject class: public class GeometricObject { } Sqaure class: public class Square extends GeometricObject implements Colorable{ //side variable of Square double side; //Implementing howToColor() @Override public void howToColor() { System.out.println("Color all four sides."); } //setter and getter methods for Square public void setSide(double side) { this.side = side; } public double getSide() { return...
COVERT TO PSEUDOCODE /****************************Vacation.java*****************************/ public abstract class Vacation { /* * private data field */ private double cost; private double budget; private String destination; /** * * @param cost * @param budget * @param destination */ public Vacation(double cost, double budget, String destination) { super(); this.cost = cost; this.budget = budget; this.destination = destination; } //getter and...
please answer correctly
public class Eve public void a print("Eve a ": public void bo print("Eveb "; public String toString() { return "Eve ts": public class Sam extends Eve public void bo a(): print("Sanb ": public String toString() { return "Sants": public class Lucas extends Sam public void a() { print("Lucas a ": print (toString() + " "); public String toString() { String sup = super.toString): return sup""+ sup: public class Josh extends Lucas public void b) { print("Josh b...
I need to return a dynamic array from a class member function and print out the results in main. using pointers and dynamic allocation is required. class example{ int *test public: example(int a){ test = new int[a]; for(int i=0;i<a;i++) test[i]=i; } int *send(){ return test;} } int main(){ example a(3); int *practice = a.send(); int psize = sizeof(a)/sizeof(a[0]); for(int i=0;i<psize;i++) cout <<practice[i] << endl; return 0; }
I need some help with some homework questions. How would I implement the to-do's? ----------------------------------------------------------------------------------------------------------------------------------------------------------- AbstractArrayHeap.Java package structures; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; public abstract class AbstractArrayHeap<P, V> { protected final ArrayList<Entry<P, V>> heap; protected final Comparator<P> comparator; protected AbstractArrayHeap(Comparator<P> comparator) { if (comparator == null) { throw new NullPointerException(); } this.comparator = comparator; heap = new ArrayList<Entry<P, V>>(); } public final AbstractArrayHeap<P, V> add(P priority, V value) { if (priority == null || value...
PLEASE HELP this is the last part of my lab and I need help ): add comments please (: if it is too difficult you do not have to do part 3 but it would be greatly appreciated if you do ! Obtain example code files Circle.java, Shape.java, CircleShape2.java, Sphere.java, and CircleShapeApp.java from the downloaded files in Ch8. Compile and execute the example and understand the polymorphism it performs. (I have copied and pasted all of these files below) Modify...