1. Create a class called Elevator that can be moved between floors in an N-storey building. Elevator uses a constructor to initialize the number of floors (N) in the building when the object is instantiated. Elevator also has a default constructor that creates a five- (5) storey building. The Elevator class has a termination condition that requires the elevator to be moved to the main (i.e., first) floor when the object is cleaned up. Write a finalize() method that satisfies this termination condition and verifies the condition by printing a message to the output, Elevator ending: elevator returned to the first floor. In main(), test at least five (5) possible scenarios that can occur when Elevator is used in a building with many floors (e.g., create, move from one floor to another, etc.). Hint: Termination occurs when the instance is set to null. You may wish to investigate “garbage collection” for this exercise. When solving this problem make sure that the user can interact with the program and choose which floor they want

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

1. Create a class called Elevator that can be moved between floors in an N-storey building. Elevator uses a constructor to initialize the number of floors (N) in the building when the object is instantiated.

Elevator also has a default constructor that creates a five- (5) storey building.

The Elevator class has a termination condition that requires the elevator to be moved to the main (i.e., first) floor when the object is cleaned up. Write a finalize() method that satisfies this termination condition and verifies the condition by printing a message to the output, Elevator ending: elevator returned to the first floor.

In main(), test at least five (5) possible scenarios that can occur when Elevator is used in a building with many floors (e.g., create, move from one floor to another, etc.).

Hint: Termination occurs when the instance is set to null. You may wish to investigate “garbage collection” for this exercise.

When solving this problem make sure that the user can interact with the program and choose which floor they want

Expert Solution
Step 1

The Java finalize() approach of item class is a technique that the garbage Collector always calls simply earlier than the deletion/destroying the object that's eligible for garbage collection to carry out smooth-up pastime. easy-up hobby approach last the assets related to that object like Database Connection, network Connection, or we will say resource de-allocation. don't forget, it isn't a reserved keyword. as soon as the finalize() method completes without delay, garbage Collector destroys that item.

Why finalize() approach is used?

finalize() method releases system sources earlier than the garbage collector runs for a particular object. JVM lets in finalize() to be invoked simplest once according to object.

how to override finalize() method?

The finalize method, that's present within the object magnificence, has an empty implementation. In our magnificence, smooth-up activities are there. Then we need to override this approach to define our smooth-up activities.

How Does garbage collection in Java works?

Java garbage series is an automated method. automated garbage collection is the manner of looking at heap reminiscence, identifying which objects are in use and which aren't, and deleting the unused gadgets. An in-use item, or a referenced item, approach that some a part of your software nonetheless keeps a pointer to that item. An unused or unreferenced object is now not referenced through any a part of your application. So the reminiscence utilized by an unreferenced item may be reclaimed. The developer does no longer need to mark gadgets to be deleted explicitly. The garbage series implementation lives in the JVM.

Varieties of activities in Java garbage collection:

two types of garbage collection activity normally happen in Java. those are:

Minor or incremental garbage series: it is stated to have happened when unreachable gadgets inside the younger era heap memory are eliminated.

most important or full garbage series: it's far said to have passed off while the gadgets that survived the minor garbage series and copied into the antique era or permanent technology heap reminiscence are eliminated. whilst as compared to the younger technology, garbage series occurs much less regularly inside the old generation.

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
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