Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels ; Double engineCapacity ; Boolean isElectric , String manufacturer ; Supply

Implement the following Java class: Vehicle

Class should contain next instance variables:

  • Integer numberOfWheels;
  • Double engineCapacity;
  • Boolean isElectric,
  • String manufacturer;

Supply your class with:

  1. Default constructor (which sets all variables to their respective default values)
  2. Constructor which accepts all the variables
  3. All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle is electric. If it is not set engineCapacity to the new value, but if it is electric leave the value at 0 and display an error message);

Your class will implement following methods:

  1. Public Boolean isSameManufacturer(Vehicle v); **
  2. Public String toString(); ***

** - this method will compare two objects by checking whether or not the manufacturer variables are the same

*** - this method will output all the information with a neat formatting

Write a driver program which will creates at least 2 object of this Class and tests all the methods

This is the code I have now. I really have no idea what else to do. I am stuck.

This is the Vehicle class:

public class Vehicle { private int numberOfWheels; private double engineCapacity; private boolean isElectric; private String manufacturer; private String Vehicle; { numberOfWheels = 4; engineCapacity = 2.0; isElectric = false; manufacturer = "Nissan"; } public Vehicle(int numberOfWheels, double engineCapacity, boolean isElectric, String manufacturer) { this.engineCapacity = engineCapacity; this.isElectric = isElectric; this.manufacturer = manufacturer; this.numberOfWheels = numberOfWheels; } public int getnumberOfWheels() { return numberOfWheels; } public void setnumberOfWheels() { } public double getengineCapacity() { return engineCapacity; } public void setengineCapacity(double engineCapacity, boolean isElectric) { if (isElectric == true) System.out.print("error, please ignore"); else if (isElectric == false) engineCapacity = 1.0; } public boolean getisElectric() { return true || false; } public void setisElectric(String manufacturer, boolean isElectric) { if ("Nissan".equals(manufacturer)) isElectric = true; else isElectric = false; } public String getmanufacturer() { return manufacturer; } public boolean isSameManufacturer(String manufacturer, v) { if (vehicle.getmanufacturer() = vehicle2.getmanufacturer()) return true; else return false; } @Override public String toString() { System.out.println("This vehicle was made by " + manufacturer); System.out.println("It is has " + numberOfWheels + " wheels"); System.out.println("It has the capacity of " + engineCapacity); System.out.println("Is this car electric?" +isElectric); return null; }

}

this is the main class:

import java.util.Scanner; import static jdk.nashorn.tools.ShellFunctions.input; public class Driver {

/** * @param args the command line arguments */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Vehicle John = new Vehicle(3, 4000, true, "Nissan"); Vehicle Doe = new Vehicle(); Doe.setnumberOfWheels(Scanner input); if (isSameManufacturer == true) { System.out.println ("not same"); } } Please help me. Can you fill in what I am missing?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Statistical And Scientific Database Management International Working Conference Ssdbm Rome Italy June 21 23 1988 Proceedings Lncs 339

Authors: Maurizio Rafanelli ,John C. Klensin ,Per Svensson

1st Edition

354050575X, 978-3540505754

More Books

Students also viewed these Databases questions

Question

Have I incorporated my research into my outline effectively?

Answered: 1 week ago