Project A: Construction & Test
Read this document carefully! Any clarification should be sought at the earliest opportunity.
Scuba Diving Calculation Assistant General Guidlines and Rationale
You have been approached by a local dive shop owner, who is tired of having to use a calculator to perform repetitive calculations, to to create an application to facilitate this process. The application you are to create should automate some simple and more complex calculations that are common in the dive industry.
Underlying Concepts and Formulas
In scuba diving most of the time we breathe ‘normal’ air which comprises 21% Oxygen and 79% Nitrogen. This can be safely used to a depth of 68 metres, after which it becomes toxic and represents a considerable risk of causing Central Nervous System (CNS) toxicity. To avoid this possibility certain ‘rules’ are adhered to, one of which is limiting the Partial Pressure of Oxygen (ppO2) in the mixture to a safe level. This level is usually in the range 1.1 ata to 1.6 ata (ata stands for – atmosphere absolute), inclusive. So how do we calculate the (ppO2)? The answer lies within a simple structure called the “Circled T” or “T in the Circle” see Figure 1.
Pg = Partial Pressure of the gas expressed in ata
Fg = Fraction of the gas in the mix expressed as a decimal
P = Absolute pressure at depth expressed in ata
In order to get our P in ata, we need to use another simple formula to convert depth in metres to ata. This is given by:
P(ata) = Depth(m)/10 + 1
So the questions become: How do we use the “T in the Circle”? and what is it really for?
The ‘what is it for’ can be answered by:
Sometimes we want to know the Best Mix of gas for a particular ‘known’ depth, or we may wish to know the maximum (safe) depth we can dive for a particular (kown/desired) fraction of gas, or sometime we may just wish to know the partial pressure of the gas we are breathing when at depth.
The ‘how do we use it’ can be explained as follows:
Simply, the bottom two notations multiplied together (F g * P ) equals the upper notation Pg. i.e. Fg * P = Pg Also, if the upper notation Pg is divided by either of the bottom notations (Fg or P), it will be equal to the remaining notation. i.e. Pg/Fg = P,or Pg/P = Fg
Example 1: Maximum Operating Depth (MOD)
Partial Pressure of O2 = 1.4 ata
Fraction of O2 in the mix is 36% expressed as a decimal = 0.36
Therefore, to calculate the MOD we must: 1.4/0.36 = 3.88 ata or 28.8 metres
Example 2: Partial Pressure of oxygen (PPO2)
Fraction of O2 in the mix is 32% expressed as a decimal = 0.32
Pressure at depth in ata: 30 m = 4 ata
Therefore, to calculate the PPO2 in the mix we must: 0.32*4 = 1.28 ata
Example 3: Fraction of Oxygen (Best Mix)
PPO2 = 1.4 ata
41 metres = 5.1 ata
Therefore, to calculate the Fraction of Oxygen in the mix we must:
1.4/5.1 = 0.27 or 27%
It is also useful to know the Equivalent Air Depth (EAD) to minimise Nitrogen Narcosis,or as Jacques Cousteau called it “Rapture of the deep”. The EAD is calculated on mixtures of gas that contain more than the normal 21% of oxygen – and for the purpose of this assignment upto 50%. i.e. 22 50 inclusive. The simple formula is:
EAD(ata) = (1-Fg)*P(ata)/0.79
once we have the EAD in ata we can convert it to metres by using the depth formula.
Example 4: Equivalent Air Depth (EAD)
The EAD for a 32% mixture of oxygen at a depth of 30 m would be: first convert our depth to ata using the depth formula to get 4 ata, then substitute into the EAD formula:
(1-0.32)*4/0.79 = 3.44 ata
then convert this back to a depth in metres using the depth formula to get 24 m.
Initial Specifications
The prototype will require a demonstration of the core algorithms that will prototype the general operation of the application. It should be a text based application that will accept user input and display the Maximum Operating Depth (MOD) or, the “Best Mix” (BM) for a certain dive or, the Partial Pressure (PP) of O2 or, the Equivalent Air Depth (EAD) for the requested inputs. In addition the application will be able to produce tables for Equivalent Air Depths and Partial Pressures.
Simple Calculations
In the first instance the client wishes to have simple calculations performed to assess the viability of the product and as such only requires that the MOD, BM, PP, EAD be calculated. In addition, the client also requests that an additional calculation be added, SMOD, since the most common partial pressure for the MOD calculation is 1.4 ata.
Your program should ensure that all inputs and outputs are within the acceptable range and are suitable for the calculation selected. Furthermore, the user should not be concerned about upper or lower case entries where text input is required. Errors should be handled ‘gracefully’ and messages should inform the user of the mistake and supply adequate opportunity to either correct the error or perform another calculation.
The following is a typical interaction session (user input is in bold):
Welcome to the Dive Formula Calculator
Select which calculation you wish to perform
Would you like to perform another calculation (y/n)? Y
elect which calculation you wish to perform
Would you like to perform another calculation (y/n)? y
Select which calculation you wish to perform
Would you like to perform another calculation (y/n)? y
Select which calculation you wish to perform
Would you like to perform another calculation (y/n)? Y
Select which calculation you wish to perform
Would you like to perform another calculation (y/n)? n
The Help menu item should give instructions for the acceptable use of the program and the meaning of the menu items. For example, choosing HELP could result in the following output:
You can select from the following choices:
Would you like to perform another calculation (y/n)?
Note: Feel free to design an alternative method for selecting menu items if you wish.
Ensure that you have tested your code comprehensively using JUnit tests
Complex Calculations
Once the simple calculations have been shown to work, the client requires that two tables be produced. The first is an Equivalent Air Depth Table that will show the EAD’s for a start and end percentage of Oxygen and a start and end depth. The client only requires percentages of Oxygen from 18% to 50%, or any combinations within that range, in increments of 1%, and depths from 3 metres to 70 metres, or any combinations within that range, in increments of 3 metres. The second is a Table of Partial Pressures using the same requirement for input as the EAD Table, but any partial pressure above 1.6 should not be displayed. In addition the end values for both the Oxygen content and the depths are to be larger than the start values. These calculations should be added as menu items and produce the required output.
The following is a typical interaction session using the two new menu items (user input is in bold):
Select which calculation you wish to perform
Generating Partial Pressures Table
Enter a start and end percentage of Oxygen: 33 40
Enter a start and end depth (in metres): 15 40
Partial Pressures Table for 33 to 40 percent Oxygen and depths of 15 to 40 metres
=================================================================================
\ 33 34 35 36 37 38 39 40
15 0.83 0.85 0.88 0.90 0.92 0.95 0.98 1.00
18 0.92 0.95 0.98 1.01 1.04 1.06 1.09 1.12
21 1.02 1.05 1.08 1.12 1.15 1.18 1.21 1.24
24 1.12 1.16 1.19 1.22 1.26 1.29 1.33 1.36
27 1.22 1.26 1.30 1.33 1.37 1.41 1.44 1.48
30 1.32 1.36 1.40 1.44 1.48 1.52 1.56 1.60
33 1.42 1.46 1.50 1.55 1.59
36 1.52 1.56
39
Would you like to perform another calculation (y/n)? y
Generating Equivalent Air Depths Table
Enter a start and end percentage of Oxygen: 21 25
Enter a start and end depth (in metres): 3 31
Equivalent Air Depth Table for 21 to 25 percent Oxygen and depths of 3 to 31 metres
===========================================================================
\ 21 22 23 24 25
3 3 3 3 3 2
6 6 6 6 5 5
9 9 9 9 8 8
12 12 12 11 11 11
15 15 15 14 14 14
18 18 18 17 17 17
21 21 21 20 20 19
24 24 24 23 23 22
27 27 27 26 26 25
30 30 29 29 28 28
Would you like to perform another calculation (y/n)? n
Ensure that you have tested your code comprehensively using JUnit tests
GUI Design Specifications
This will be a GUI application that allows for modification of the data through a GUI application. Your delivery of the prototype met with the client’s needs. They were impressed that you were able to translate the business logic into a usable text based application. They now would like you to take this simple prototype and create a functional graphical application.
You are being given freedom in the design of this interface. You must include the following though:
• A widget for the user to specify the percentage of Oxygen
• A widget for the user to specify the partial pressure of Oxygen
• A widget for the user to specify the depth (in metres)
• A widget to enable the user to select the type of (simple) calculation to perform
– EAD/MOD/BestMix/PP/SMOD
• A widget to display the result of any of the calculations
• A drawing space where a cylinder be drawn by the application showing the percentage of Oxygen and Nitrogen in the mixture. This should be dynamic with a change in the percentage of Oxygen be immediately translated to the graphic.
• WidgetsforthestartandendpercentagesofOxygenanddepthsforthecomplexcalculations
• A widget to select which table to produce
• A suitable representation of the tabular output
Deliverables
This application will assess your knowledge of construction by testing your ability to develop: • GUIs,
• Panels,
• Buttons,
• Scrollbars,
• Tables,
• Labels, and
• Mouse interactions
You are free to implement this solution in any fashion that you like.
Remember to analyse the problem as necessary and design a solution that suits the deliverables. Treat this as a professional activity, so inline comments, documentation and application output should be presented appropriately for the target audience. You need to determine the structures you will use. This is an application that may reuse elements and so your development should consider this.
Your code should contain appropriate JavaDoc commenting and inline comments to assist future developers.
A possible GUI is shown in Figure 2. Your solution does not have to be identical to this.
The work you submit should adhere to the guidelines presented in this document. If your code does not compile you will be awarded 0 marks. Code that does not compile will not be investigated further. You will not be given an opportunity to resubmit working code. This is a construction assignment and the responsibility for submitting a working product is yours.
main class Driver.java
package divingcalculations;
public class Driver {
public static void main(String[] args) {
new DiveBroker();
}
}
DiveFormulas.java
package divingcalculations;
public class DiveFormulas {
}
lastly, DiveBroker.java
package divingcalculations;
public class DiveBroker {
}
问题梳理一下,贴出中文意思。