Do the following in Java and provided source code with screenshots of correct output! 1. Create an interface Vehicle that contains three void, abstract methods named Start, Stop and Change Speed. 2 .Create an Airplane class (not abstract) that uses the Vehicle interface in Q1. The code for all methods should print simple messages to the screen using System.out.println(). Add an integer speed variable that is changed using the Change Speed method. ChangeSpeed adds 5 to the speed each time it is called. Create a default constructor that sets the initial speed to 0. Don't create other constructors or any setter/getter methods. 3. Create an abstract class Car that also uses the Vehicle interface in Q1 and has three variables, Year, Make, and Speed. Include the following: One constructor that accepts the car's year and make as arguments. The constructor should also assign 0 to the speed variable. Do not create other constructors. Create a void method sound but leave it unimplemented. Create a variable Count that keeps track of the number of car instances. When each new car is created, the counter should increment by 1. Create a getCount method that returns the number of car instances held in the Count variable. Don't implement the Vehicle interface methods. Don't implement any setters/getters. 4.Create a class SportsCar that inherits from the Car class in Q3. Include the following: A variable Roof that holds the type of roof (Ex: Convertible, Hard-Top, Soft-Top) A variable Doors that holds the car's number of doors (Ex: 2, 4) Implement the Change Speed method to add 20 to the speed each time it is called. Add exception handling to the Change Speed method to keep the speed under 65. Implement the sound method to print, "broooom," to the screen. Create one constructor that accepts the car's roof, doors, year and make as arguments and assigns the values appropriately. Do not create any other constructors. The interface methods should print simple messages to the screen using System.out.println(). 5.Create a driver class Playground that contains the function, public static void main(String[] args) {}. Create 2 SportsCar and 2 Airplane instances using their constructors. Add all 4 instances into a single array called, "elements." Create a loop that examines each element in the array, "elements." If the elements item is a SportsCar, run the sound method and if the item is an Aeroplane, run it's ChangeSpeed method. Run the getCount() method (created in Q3) to display how many total cars were created.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Do the following in Java and provided source code with screenshots of correct output!

1. Create an interface Vehicle that contains three void, abstract methods named Start, Stop and Change Speed.

2 .Create an Airplane class (not abstract) that uses the Vehicle interface in Q1. The code for all methods should print simple messages to the screen using System.out.println(). Add an integer speed variable that is changed using the Change Speed method. ChangeSpeed adds 5 to the speed each time it is called. Create a default constructor that sets the initial speed to 0. Don't create other constructors or any setter/getter methods.

3. Create an abstract class Car that also uses the Vehicle interface in Q1 and has three variables, Year, Make, and Speed. Include the following:

  • One constructor that accepts the car's year and make as arguments. The constructor should also assign 0 to the speed variable. Do not create other constructors.
  • Create a void method sound but leave it unimplemented.
  • Create a variable Count that keeps track of the number of car instances. When each new car is created, the counter should increment by 1.
  • Create a getCount method that returns the number of car instances held in the Count variable.
  • Don't implement the Vehicle interface methods. Don't implement any setters/getters.

4.Create a class SportsCar that inherits from the Car class in Q3. Include the following:

  • A variable Roof that holds the type of roof (Ex: Convertible, Hard-Top, Soft-Top)
  • A variable Doors that holds the car's number of doors (Ex: 2, 4)
  • Implement the Change Speed method to add 20 to the speed each time it is called.
  • Add exception handling to the Change Speed method to keep the speed under 65.
  • Implement the sound method to print, "broooom," to the screen.
  • Create one constructor that accepts the car's roof, doors, year and make as arguments and assigns the values appropriately. Do not create any other constructors.
  • The interface methods should print simple messages to the screen using System.out.println().

5.Create a driver class Playground that contains the function, public static void main(String[] args) {}.

  • Create 2 SportsCar and 2 Airplane instances using their constructors.
  • Add all 4 instances into a single array called, "elements."
  • Create a loop that examines each element in the array, "elements." If the elements item is a SportsCar, run the sound method and if the item is an Aeroplane, run it's ChangeSpeed method.
  • Run the getCount() method (created in Q3) to display how many total cars were created.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Introduction to Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education