Monday, January 16, 2012

Toonie Fish Tank Java Programming

This is a problem which asked you to find out how many rolls of Toonies it would take to overflow a certain sized fish tank filled with a specified amount of water. It ignores the space that the paper of the Toonie rolls would occupy.



Solution

//****************************************************************************
// TripTime.java
// CS151A, Assignment 3 PP 3 question #2
// This class Calculates the amount of toonie rolls needed to overflow a partially filled fish tank
//****************************************************************************

import java.util.*;
import java.math.*;

public class ToonieFishTank
{
    public static void main (String[] args)
    {
        double toonie_diameter;
        double toonie_thickness;
        double number_toonies_in_roll;
        double volume_roll_of_toonies_mm;
        double volume_roll_of_toonies_cm;
        double pi;
        double toonie_radius;
        double conversion_mm3_to_cm3;

        //Assigned values for Toonie Calculation//

        toonie_diameter = 28;
        toonie_thickness = 1.8;
        number_toonies_in_roll = 25;
        pi = 3.14159265358979323846264338327950288419716939937510;
        conversion_mm3_to_cm3 = 1000;

        //Start of Toonie Calculation//

        toonie_radius = toonie_diameter / 2;

        volume_roll_of_toonies_mm = pi*(Math.pow((toonie_radius),2))*(toonie_thickness * number_toonies_in_roll);

        volume_roll_of_toonies_cm = volume_roll_of_toonies_mm / conversion_mm3_to_cm3;

        //End of Toonie Calculation. Start of Fish Tank//

        double fish_tank_height;
        double fish_tank_width;
        double fish_tank_length;
        double volume_tank;
        double volume_water;
        double remainder_volume;
        double amount_of_rolls_needed;
        double percentage_water;

        fish_tank_height = 30;
        fish_tank_width = 30;
        fish_tank_length = 60;

        volume_tank = fish_tank_height * fish_tank_width * fish_tank_length;

        percentage_water = 3.000/4.000;

        volume_water = volume_tank * percentage_water;

        remainder_volume = volume_tank - volume_water;

        amount_of_rolls_needed = remainder_volume / volume_roll_of_toonies_cm;

        System.out.println("It would take " + (int)(amount_of_rolls_needed +1) + " rolls of toonies to overflow the fish tank.");
    }
}

No comments:

Post a Comment