Page 83 - Introduction to Programming with Java: A Problem Solving Approach
P. 83

                2.13 Problem Solving: Asset Management (Optional) 49
set more to ‘y’
while more is equal to ‘y’
input assetName
input expectedLife
input condition
input serviceHistory
input adjustedLife
input age
set remainingLife to adjustedLife 􏰁 age print “Another asset? (y/n): ”
input more
This algorithm does not include prompts for the individual variables. Some of these variables may have multiple components, and you may wish to establish and enforce certain conventions for what input values will be acceptable. For example, condition and serviceHistory may each have several subordinate components. You’ll deal with all those details later.
For step 2, you have five variables: assetName, remainingLife, importance, redundancy,
and priority. The assetName and remainingLife variables are the same as two of the variables
used for step 1, so you won’t need to input those again. But wait! If this is a separate loop, you’ll still have
to identify each asset to make sure the new values are being associated with the right asset. You could do
this by asking the user to re-enter the assetName, or you could do it by looping through all the existing
assets and printing out each name just before asking for the required additional information for that asset.
Apago PDF Enhancer
The second strategy is easier for the user, so you pick it. Here’s an abbreviated pseudocode description of the implementation of step 2:
while another asset exists print assetName input importance input redundancy input priority
Again, the algorithm does not include prompts, and it does not establish and enforce input conventions. You’ll deal with those details later.
For step 3, you identify five variables: assetName, activity, yearsAhead, dollarCost, and annualReserve. Again, assetName is already in the system, so again, you can identify it by printing it out. But in scheduling things, the council members will want to deal with the most important things first, so before you start going through the assets, you’ll want the program to sort them by priority. The sorting operation might be a little tricky. But if you’re lucky, someone else already will have written code for that popular computer task, and you’ll be able to use it instead of “reinventing the wheel.”
The activity, yearsAhead, and dollarCost are inputs, and you’ll want the program to com- pute annualReserve as dollarCost / yearsAhead. After computing the annual reserve for each individual asset, you’ll want the program to add it to a totalAnnualReserve variable, and after the loop you’ll want it to print the final value of totalAnnualReserve. Here’s an abbreviated pseudocode description of the implementation of step 3:











































































   81   82   83   84   85