Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description: This activity will help you understand how and when to use the static keyword. In this activity there can be multiple apartments using the

Description:

This activity will help you understand how and when to use the static keyword. In this activity there can be multiple apartments using the same watertank. You will have to finish the watertank class so that whenever an apartment uses water they use up some of the water in the watertank. This amount should decrease for everyone even if only one apartment uses water. Please follow the steps below:

Steps:

  1. Show a static variable that takes a value for the waterlevel.
  2. Show a method called useWater() that uses some water and reduces the waterlevel amount by 10 units. Make it print out the following string: "Water gushes". If there is no water then print out the following string instead: "No water. Please refill" and do not reduce the waterlevel.
  3. Show a method calld refill() to refill the waterlevel to its maximum amount. Make it print out the following strings: "Watertank is being refilled" and then on the next line: "Watertank is full".
  4. Show a method to print out the waterlevel called printWaterLevel(). Use the following string: "Water level: " and then the waterlevel variable.

Test:

Use the test provided. This test uses the sample code from the main method in Main.java.

Sample output:

Water gushes

Water level: 90

Water gushes

Water level: 80

Watertank is being refilled

Watertank is full

Water level: 100

Water gushes

Water level: 90

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_2

Step: 3

blur-text-image_3

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

Income Tax Fundamentals 2021

Authors: Gerald E. Whittenburg, Martha Altus-Buller, Steven Gill

39th Edition

0357141369, 9780357141366

More Books

Students also viewed these Programming questions