Question

In: Computer Science

Write the definition of a class, swimmingPool, to implement the properties of a swimming pool. Your...

  • Write the definition of a class, swimmingPool, to implement the properties of a swimming pool.
  1. Your class should have the instance variables to store the length (in feet), width (in feet), depth (in feet), the rate (in gallons per minute) at which the water is filling the pool, and the rate (in gallons per minute) at which the water is draining from the pool.
  2. Add appropriate constructors to initialize the instance variables.
  3. Also, add member functions to do the following: determine the amount of water needed to fill an empty or partially filled pool, determine the time needed to completely or partially fill or empty the pool, and add or drain water for a specific amount of time.
  4. This program must have a main program that utilizes a header file that defines the class and an implementation file containing the constructions and functions used in the class definitions.
    • The main program will prompt the user for information using a the pool’s parameter constructor or default constructor with setters and getters.
    • The main program should use the pool class to determine how much and how long it will take fill an empty pool.
    • The main program should use the pool class to determine how much and how long it will take to fill an partially filled pool.
    • The main program should use the pool class to determine how much and how long it will take to empty a full pool.
    • The main program should use the pool class to determine how much and how long it will take to empty a partial filled pool.
  • Test the Results: The objective of testing your program is to make sure you are producing a quality product and that it is operating the way you expect it to work. "It complied, it should work" is not a sufficient test methodology.
  1. Include both normal and abnormal input.
    A normal test is entering data that is expected. Please test your code with a set of input data that will verify that your program work under normal parameters.
    An abnormal test is a test that is expected, but will provide errors back to the user, identifying the error and what was expected. This is usually a boundary test.
  2. Try to cover all paths through your program.
    Code coverage is identifying all possible paths that could be completed in your program.

Solutions

Expert Solution

Thanks for the question.

Here is the completed code for this problem. 

Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. 

If you are satisfied with the solution, please rate the answer. 

Thanks


===========================================================================

public class SwimmingPool {

    private int length;
    private int width;
    private int depth;
    private double rateOfFilling;
    private double rateOfDraining;
    private int currentDepth;

    public SwimmingPool() {
        length = width = depth = 0;
        rateOfDraining = rateOfFilling = 0.0;
        currentDepth = 0;
    }

    public SwimmingPool(int length, int width, int depth) {
        this.length = length;
        this.width = width;
        this.depth = depth;
        this.rateOfFilling = 0;
        this.rateOfDraining = 0;
        currentDepth = 0;
    }

    //determine the amount of water needed to fill an empty
    public double waterToFillCompletely() {
        return length * width * depth;
    }



    //water needed to fill an partially filled pool, given height
    public double waterToFillDepth(int height) {
        return length * width * height;
    }

    //determine the time needed to completely
    public double timeToFillCompletely() {
        return waterToFillCompletely() / rateOfFilling;

    }

    //determine the time needed to completely
    public double timeToDrainCompletely() {
        return waterToFillCompletely() / rateOfDraining;

    }

    public double timeToFillDepth(int height) {
        return waterToFillDepth(height) / rateOfFilling;
    }

    public double timeToDrainDepth(int height) {
        return waterToFillDepth(height) / rateOfDraining;
    }

    // add water upto a given height
    public void addWater(int height) {
        if (height >= 0 && (height + currentDepth) <= depth) {
            currentDepth += height;
        } else {
            System.out.println("Height entered is greater than the depth of the swimming pool.");
        }
    }

    // drain water upto height
    public void drainWater(int height) {
        if (height >= 0 && (currentDepth - height) >= 0) {
            currentDepth -= height;
        } else {
            System.out.println("Invalid height. Current depth will be in negative.");
        }
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getDepth() {
        return depth;
    }

    public void setDepth(int depth) {
        this.depth = depth;
    }

    public double getRateOfFilling() {
        return rateOfFilling;
    }

    public void setRateOfFilling(double rateOfFilling) {
        this.rateOfFilling = rateOfFilling;
    }

    public double getRateOfDraining() {
        return rateOfDraining;
    }

    public void setRateOfDraining(double rateOfDraining) {
        this.rateOfDraining = rateOfDraining;
    }

    public int getCurrentDepth() {
        return currentDepth;
    }

    public void setCurrentDepth(int currentDepth) {
        this.currentDepth = currentDepth;
    }
}

============================================================

import java.util.Scanner;

public class MainSwimmingPool {

    public static void main(String[] args) {

        int length, width, height;
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter length, width and height (separated by a space)? ");
        length = scanner.nextInt();
        width = scanner.nextInt();
        height = scanner.nextInt();
        //The main program will prompt the user for information using a the pool’s parameter constructor or default constructor with setters and getters.
        SwimmingPool pool = new SwimmingPool(length, width, height);

        //The main program should use the pool class to determine how much and how long it will take fill an empty pool.
        double fillingRate, drainingRate;
        System.out.print("Enter filling rate and draining rate (separated by space)? ");
        fillingRate = scanner.nextDouble();
        drainingRate = scanner.nextDouble();

        pool.setRateOfFilling(fillingRate);
        pool.setRateOfDraining(drainingRate);
        System.out.println("Time taken to fill the pool completely is: " + pool.timeToFillCompletely() + " mins");
        //The main program should use the pool class to determine how much and how long it will take to empty a full pool.
        System.out.println("Time taken to drain the pool completely is: " + pool.timeToDrainCompletely() + " mins.");

        //The main program should use the pool class to determine how much and how long it will take to fill an partially filled pool.
        System.out.print("Enter the current depth of the pool: ");
        int currentDepth = scanner.nextInt();
        pool.addWater(currentDepth);

        //The main program should use the pool class to determine how much and how long it will take to empty a partial filled pool.
        System.out.println("Water needed to fill " + currentDepth + " height is: " +
                pool.waterToFillDepth(currentDepth) + " gallons.");
        System.out.println("Time needed will be: " + pool.timeToFillDepth(currentDepth) + " mins.");

        System.out.println("Time needed to drain pool having " + currentDepth + " height is: " +
                pool.timeToDrainDepth(currentDepth));
    }
}

==============================================================


Related Solutions

c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a...
c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data:  Account holder’s name (string)  Account number (int)  Account type (string, check/savings/business)  Balance (double)  Interest rate (double) – store interest rate as a decimal number.  Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. 1.2 Implement...
Pool Corporation, Inc., is the world’s largest wholesale distributor of swimming pool supplies and equipment. Pool...
Pool Corporation, Inc., is the world’s largest wholesale distributor of swimming pool supplies and equipment. Pool Corp. reported the following information related to bad debt estimates and write-offs for a recent year. Allowance for doubtful accounts: Balance at beginning of year $ 9,002 Bad debt expense 4,098 Write-offs (5,110 ) Balance at end of year $ 7,990 Required: 1. Prepare journal entries for the bad debt expense adjustment and total write-offs of bad debts for the current year. 2. Pool...
You are asked to implement a class Pizza, the default values of properties are given as:...
You are asked to implement a class Pizza, the default values of properties are given as: Diameter: 8.0 Name: DefaultName Supplier: DefaultSupplier Hints: A pizza with diameter greater than 15 will be considered as a large pizza. The method IsLargePizza will return a true if the pizza is considered as a large pizza or a false if it is not considered as a large pizza. There are two ToString methods, the one with no parameter passed will return the information...
In C++, define the class bankAccount to implement the basic properties of a bank account. An...
In C++, define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 components of type bankAccount to...
Pool Corporation, Inc., is the world's largest wholesale distributor of swimming pool supplies and equipment. It...
Pool Corporation, Inc., is the world's largest wholesale distributor of swimming pool supplies and equipment. It is a publicly-traded corporation that trades on the NASDAQ exchange. The majority of Pool's customers are small, family-owned businesses. Assume that Pool issued bonds with a face value of $900,000,000 on January 1 of this year and that the coupon rate is 6 percent. At the time of the borrowing, the annual market rate of interest was 2 percent. The debt matures in 9...
A 4.9-m-wide swimming pool is filled to the top. The bottom of the pool becomes completely...
A 4.9-m-wide swimming pool is filled to the top. The bottom of the pool becomes completely shaded in the afternoon when the sun is 22 ∘ above the horizon.
In Florida, real estate agents refer to homes having a swimming pool as pool homes. In...
In Florida, real estate agents refer to homes having a swimming pool as pool homes. In this case, Sunshine Pools Inc. markets and installs pools throughout the state of Florida. The company wishes to estimate the percentage of a pool's cost that can be recouped by a buyer when he or she sells the home. For instance, if a homeowner buys a pool for which the current purchase price is $30,000 and then sells the home in the current real...
In Florida, real estate agents refer to homes having a swimming pool as pool homes. In...
In Florida, real estate agents refer to homes having a swimming pool as pool homes. In this case, Sunshine Pools Inc. markets and installs pools throughout the state of Florida. The company wishes to estimate the percentage of a pool's cost that can be recouped by a buyer when he or she sells the home. For instance, if a homeowner buys a pool for which the current purchase price is $30,000 and then sells the home in the current real...
Dolphin Swimming Pools sells and installs above ground swimming pools as well as pool accessories. For...
Dolphin Swimming Pools sells and installs above ground swimming pools as well as pool accessories. For the current year, they estimate that they would sell and install 200 pools at $5,000 each. Each pool costs Dolphin $4,400 in materials and installation costs. They also expect to sell $800,000 in Accessories. Accessories generate a margin of 30%. Fixed costs (such as the showroom and administration) are $200,000. Required Calculate the Break Even Point in number of swimming pools (assuming that the...
Dolphin Swimming Pools sells and installs above ground swimming pools as well as pool accessories. For...
Dolphin Swimming Pools sells and installs above ground swimming pools as well as pool accessories. For the current year, they estimate that they would sell and install 200 pools at $5,000 each. Each pool costs Dolphin $4,400 in materials and installation costs. They also expect to sell $800,000 in Accessories. Accessories generate a margin of 30%. Fixed costs (such as the showroom and administration) are $200,000. Required A. Calculate the Break Even Point in number of swimming pools (assuming that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT