Question

In: Computer Science

perform each of the following steps: a) Read the problem statement. b) Formulate the algorithm using...

perform each of the following steps:

a) Read the problem statement.

b) Formulate the algorithm using pseudocode and top-down, stepwise refinement.

c) Define the algorithm in JavaScript.

d) Test, debug and execute the JavaScript.

e) Process three complete sets of data.

Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording the number of miles driven and the number of gallons used for each tankful. Develop a script that will take as input the miles were driven and gallons used (both as integers) for each tankful. The script should calculate and output HTML5 text that displays the number of miles per gallon obtained for each tankful and prints the combined number of miles per gallon obtained for all tankfuls up to this point. Use prompt dialogs to obtain the data from the user.

Solutions

Expert Solution

Algorithm:

1.Start

2.Declare 2 variable totalMiles ,gallons

3.Take user input for the two variables

4.Calculate mpg using the formula totalMiles/gallons

5.Return the value of mpg

<!DOCTYPE html>
<html>
  <head>
    <title>Miles per Gallon</title>
    <meta charset="UTF-8" />
    <script type="text/javascript">
      function calcMPG() {
        var totalMiles = document.forms[0].totalMileage.value;
        var gallons = document.forms[0].gallonsUsed.value;

        if (isNaN(totalMiles) || isNaN(gallons)) {
          window.alert("Each textbox must contain only numbers!");
        } else {
          if (gallons > 0) {
            document.forms[0].milesPerGallon.value = (
              totalMiles / gallons
            ).toFixed(1);
          }
        }
      }
    </script>
  </head>

  <body>
    <script type="text/javascript">
      document.write("<p><h2>Miles Per Gallon Calculator</h2></p>");
      document.write(
        "<p><h5>To find miles per gallon, enter total miles travelled and gallons of gas used.</h5></p>"
      );
    </script>
    <form action="">
      <p>
        Miles:
        <input
          type="text"
          name="totalMileage"
          value="0"
          size="10"
          onchange="calcMPG()"
        />
      </p>
      <p>
        Gallons Used:
        <input
          type="text"
          name="gallonsUsed"
          value="0"
          size="10"
          onchange="calcMPG()"
        />
      </p>
      <p>
        Miles Per Gallon:
        <input type="text" name="milesPerGallon" value="0" size="10" />
      </p>
    </form>
  </body>
</html>

Related Solutions

Formulate the following problem using the following steps. a. Define the decision variables. b. Specify the...
Formulate the following problem using the following steps. a. Define the decision variables. b. Specify the objective function. c. Specify the constraints and simplify them so that the left hand side of each constraint only contains terms involving the decision variables. ChemLabs uses raw materials I and II to produce two domestic cleaning solutions A and B. The daily availabilities of raw materials I and II are 150 and 145 units respectively. One unit of solution A consumes .5 unit...
In each of the following exercises, formulate an appropriate null hypothesis and perform a test of...
In each of the following exercises, formulate an appropriate null hypothesis and perform a test of that null hypothesis at the 5% and 1% significance levels. Use a one-sided or two-sided test as appropriate. 10. An instructor administers a 2-minute sit-up test to a class of 10 students, obtaining the following scores. X : 55,45,48,62,58,60,42,44,53,55 The instructor expects students to have an average score of no more than 45 on the sit-up test. Part (a) Assume that 10 is the...
For each problem, perform the following steps. Assume that all variables are normally or approximately normally distributed.
  For each problem, perform the following steps. Assume that all variables are normally or approximately normally distributed. State the hypothesis and identify the claim. Find the critical value(s). Compute the test value. Make the decision. Summarize the results. The average temperatures for a 25-day period for Birmingham, Alabama, and Chicago, Illinois, are shown. Based on the samples, at α = 0.10, can it be concluded that it is warmer in Birmingham? [4] Birmingham Chicago 78 82 68 67 68...
For each problem, perform the following steps. Assume that all variables are normally or approximately normally distributed.
  For each problem, perform the following steps. Assume that all variables are normally or approximately normally distributed. State the hypothesis and identify the claim. Find the critical value(s). Compute the test value. Make the decision. Summarize the results. According to the 2005-2006 National Pet Owners Survey, only 16% of pet dogs were adopted from an animal shelter and 15% of pet cats were adopted. To test this difference in proportions of adopted pets, a survey was taken in a...
For each problem, perform the following steps. Assume that all variables are normally or approximately normally distributed.
  For each problem, perform the following steps. Assume that all variables are normally or approximately normally distributed. State the hypothesis and identify the claim. Find the critical value(s). Compute the test value. Make the decision. Summarize the results. The heights (in feet) for a random sample of world famous cathedrals are listed below. In addition, the heights for a sample of the tallest buildings in the world are listed. Is there sufficient evidence at α = 0.05 to conclude...
solve the following LP. Formulate and algebraically solve the problem. Show all steps. what is the...
solve the following LP. Formulate and algebraically solve the problem. Show all steps. what is the new optimal z value max z=65x1+35x2+20x3 8x1+6x2+x3<=48 4x1+2x2+1.5x3<=20 2x1+1x2+0.5x3<=8 x2<=5 x1,x2,x3>=0 interpret the meaning of the shadow prices
Please formulate and solve each of the following problems. For each problem, you should include the...
Please formulate and solve each of the following problems. For each problem, you should include the final SOLVER printout (either your final spreadsheet or an answer report), as well as (1) clear and precise definitions for all decision variable; (2) your objective function indicating whether it is to be maximized and minimized; (3) all constraints, including non-negativity and integrality (if necessary); and (4) what the optimal decision is (in words) and what outcome will be produced. A manufacturer of stereos...
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm...
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm being used) Requirements Choose one problem with an algorithm and implement it. You should show and explain the result whatever you got. I recommend using N-Queen problem (at least N=8 or more) or any simple perfect games. For example, - N-Queen problem with hill climbing - N-Queen problem with simulated annealing - N-Queen problem with genetic algorithm - Tic-Tac-Toe with Minimax
For each test below, follow the following steps. (1) state the hypotheses, (2) formulate an analysis...
For each test below, follow the following steps. (1) state the hypotheses, (2) formulate an analysis plan (3) analyze sample data (4) interpret the results You may use the TI-83 to calculate the test statistic and p-value, but be sure you indicate which test you are using. Test III – Test a New Drug (Part 2) Suppose the Acme Drug Company develops a new drug, designed to prevent colds. The company states that the drug is more effective for women...
For each test below, follow the following steps. (1) state the hypotheses, (2) formulate an analysis...
For each test below, follow the following steps. (1) state the hypotheses, (2) formulate an analysis plan (3) analyze sample data (4) interpret the results You may use the TI-83 to calculate the test statistic and p-value, but be sure you indicate which test you are using. Test II – Test a New Drug Suppose the Acme Drug Company develops a new drug, designed to prevent colds. The company states that the drug is equally effective for men and women....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT