44.2k views
2 votes
Create a new jdoodle project. Create classes according to the following specifications below.

Class name: Engine
Attributes:
cylinders (int)
ccDisplacement (int)
Behaviors:
default constructor
two-argument constructors
toString - neatly formats the cylinders and ccDisplacement of the engine as a String, and returns that String
Class name: Vehicle
Attributes:
type (String))
gasLeft (int)
Behaviors:
default constructor
two-argument constructor
move (abstract)
addGas (adds the parameter to the gasLeft)
toString - neatly formats the type and gas left as a String, and returns that String
Class Name: Car - inherits from Vehicle
Attributes:
motor (Engine)
color (String)
Behaviors:
default constructor
five-argument constructor
removeAndInstallEngine (replaces cylinders and ccDisplacement with parameters to method)
move - subtracts 1/20th of the parameter (use integer division) from gasLeft
toString - neatly formats the type, gas left, cylinders, displacement, and color as a String, and returns that String (uses calls to Engine's toString, and Vehicle's toString)
Class Name: BuoyancyOperatedAquaticTransport - inherits from Vehicle
Attributes:
motor (Engine)
color (String)
isCommercial (Boolean)
Behaviors:
default constructor
six-argument constructor
move - subtracts 1/10th of the parameter (use integer division) from gasLeft
toString - neatly formats the type, gas left, cylinders, displacement, color, and isCommercial as a String, and returns that String (uses calls to Engine's toString, and Vehicle's toString)
Class Name: Driver
The Driver class uses a main method to test the functionality of the other classes

User Icn
by
8.2k points

1 Answer

5 votes

Final answer:

This question is about creating classes and their attributes and behaviors according to the given specifications.

Step-by-step explanation:

Engine Class

Attributes:

  • cylinders (int)
  • ccDisplacement (int)

Behaviors:

  • default constructor
  • two-argument constructors
  • toString - neatly formats the cylinders and ccDisplacement of the engine as a String, and returns that String

Vehicle Class

Attributes:

  • type (String))
  • gasLeft (int)

Behaviors:

  • default constructor
  • two-argument constructor
  • move (abstract)
  • addGas (adds the parameter to the gasLeft)
  • toString - neatly formats the type and gas left as a String, and returns that String

Car Class

(inherits from Vehicle)

Attributes:

  • motor (Engine)
  • color (String)

Behaviors:

  • default constructor
  • five-argument constructor
  • removeAndInstallEngine (replaces cylinders and ccDisplacement with parameters to method)
  • move - subtracts 1/20th of the parameter (use integer division) from gasLeft
  • toString - neatly formats the type, gas left, cylinders, displacement, and color as a String, and returns that String (uses calls to Engine's toString, and Vehicle's toString)

BuoyancyOperatedAquaticTransport Class

(inherits from Vehicle)

Attributes:

  • motor (Engine)
  • color (String)
  • isCommercial (Boolean)

Behaviors:

  • default constructor
  • six-argument constructor
  • move - subtracts 1/10th of the parameter (use integer division) from gasLeft
  • toString - neatly formats the type, gas left, cylinders, displacement, color, and isCommercial as a String, and returns that String (uses calls to Engine's toString, and Vehicle's toString)

Driver Class

The Driver class uses a main method to test the functionality of the other classes