Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The American Red Cross wants you to write a program that will calculate the average pints of blood donated during a blood drive. The program

The American Red Cross wants you to write a program that will calculate the average pints of blood donated during a blood drive. The program should take in the number of pints donated during the drive, up to twenty-four hour drive period, from an input file, bloodDrive.txt. The average pints, highest pints, and lowest pints donated during that period should be calculated and written to a file called bloodResults.txt. We will only run the program once so a yeso loop is not needed.

Step 1: Note that the getHigh, getLow, and getAverage functions do not change. We need to modify modules getPints and displayInfo to meet the new requirements. Complete the pseudocode below for the two modules according to instructions:

In the getPints Module (notice there is a new pass-by-reference parameter count)

Declare an input file with the name bloodInFile.

Open the internal file (bloodInFile) and a text file named bloodDrive.txt.

If cannot open file then display an error message

Set count = 0

Input one value from the file

While not end-of-file, store value in the array[count], add 1 to count, and input another value

Close the file.

Module getPints(Real pints[], Integer Ref count)

End Module

In the displayInfo Module

Declare an output file with the name bloodOutFile.

Open the internal file (bloodOutFile) and a text file named bloodResults.txt.

Write the string Report generated by [YourName] to the file.

Write the string Blood drive period: to the file.

Write the value of hours to the file.

Write the string Average Pints: to the file.

Write the value of averagePints to the file.

Do the same thing for highest pints and lowest pints

Close the bloodOutFile.

Module displayInfo(Integer hours, Real averagePints,

Real highPints, Real lowPints,)

End Module

Pseudocode for the main module (MAX_HOURS is a global named constant)

Module main()

//Declare local variables

Declare Real pints[MAX_HOURS]

Declare Integer hours

Declare Real avePints, highPints, lowPints

Call getPints(pints, hours)

Display hours: , hours

Set avePints = getAverage(pints, hours)

Set highPints = getHigh(pints, hours)

Set lowPints = getLow(pints, hours)

Call displayInfo(hours, avePints, highPints, lowPints)

End Module

Page BreakLab 9.2 Java Code

Convert the blood drive program from Lab 9.1 to Java code with the help of Java Companions Ch. 10. Create a text file name bloodDrive.txt in the project folder with the following values.

43

25

64

35

19

37

46

Run your program and check against the following output file, bloodResults.txt. If there are errors, go back through the steps to troubleshoot. You might want to output relevant information such as input data to the screen to see what is going on.

Report generated by [YourName]

Blood drive period: 7

Average pints: 38.4

Highest pints: 64.0

Lowest pints: 19.0

You might want to try another test case with fewer or more than 7 values to make sure your program can handle it. Dont forget to format the results properly.? When your code is complete and runs properly, print both the source code and the output file for the test case above.?

image text in transcribed

That is the current program that created but need help in doing the steps required. There are some modifications needed but having trouble doing so.

import java.text.DecimalFormat; import java.util.Scanner; public class Averagepints { public static void main(String[l args) int counter; int hours-7 float arr[]=new float[hours]; float min, max, total-0; float avg; Scanner sc- new Scanner(System.in); System.out.println("Enter data for 7 hours.In"); for (counter-e;counter max) max-arr[counter]; if (arr[counter]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago