Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please write a code and add comments to explain the mindset so I can learn the strategies and mindset to write a code

Can you please write a code and add comments to explain the mindset so I can learn the strategies and mindset to write a code like this in the future. Thank you and have a blessed day

Background

  • This assignment demonstrates the notion of inheritance using Java. Your boss has requested that you design an application that needs a Car class. Later that same day, the designers tell you that you now need a Truck class. Your gut tells you that they will probably want a golf cart class by the end of the week. How can you leverage the common pieces of these three types of objects by using one generic base class?

Objective for this Lab

  • You are going to create four small Java classes; a driver class that has the static main method, a regular Java class named Vehicle, then two classes named Car and Truck, respectively that inherit from Vehicle class.
  • Driver class with the static main method
  • Vehicle class - generic primary super class
  • Car class - class that inherits the vehicle class
  • Truck class - class that inherits the vehicle class
  • Required Methods
  • Your application needs the following methods.
  • start()
  • stop()
  • turn()
  • getSpeed()
  • setSpeed()
  • increaseSpeed()
  • decreaseSpeed()
  • openTrunk()
  • closeTrunk()
  • openTailgate()
  • closeTailgate()
  • The generic Vehicle only contains the generic methods, start, stop, getSpeed, etc. The Car class contains the trunk methods and the Truck class contains the tailgate methods.
  • Most methods simply need to display a simple message so you know it is being executed, like this:
  • public void stop()
  • {
  • System.out.println("Stopping");
  • }
  • The setSpeed, getSpeed and increaseSpeed methods need a little Java code to set instance variables.
  • Create a method that uses the super keyword.
  • Develop a constructor that calls its superclasss constructor.

ReplyForward

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

More Books

Students also viewed these Databases questions