Question

Pepper's Pill Mill is a pharmaceutical company that is developing a new drug to help fight...

Pepper's Pill Mill is a pharmaceutical company that is developing a new drug to help fight Alzheimer's disease. The drug has performed well in laboratory experiments, and the company has received approval to begin trials with people. To help make sure that the trial is unbiased, they are asking you to develop a Java program that can perform the data analysis and determine the drug's effectiveness.

Each trial consists of 3 groups of individuals undergoing different treatment:

  1. Control Group- No treatment.
  2. Experimental Group - New Drug Administered.
  3. Placebo Group - Fake Drug (sugar pills) Administered.

Every individual in each group gets the same memory evaluation, and the doctor will write down a score for that individual as a number between 0 and 100. There are many patients in each group, so some simple statistics are necessary to determine the effectiveness of the treatment.

DIRECTIONS

Input and Output
Your program should take as input:

  • File names for three input files (one for each group in the trial)
  • A file name for the output file

Your program should output:

  • A file with the trial results

Your program should ask for the names of 3 files (input files) that contain memory evaluation data for the three groups in this trial. Your program should then ask for a name for the file that will hold the trial results (the output file). All files will be located in the same directory as your program.

Each input data file contains a list of integers - one on each line. The study is double-blind, so your program will not know which data file corresponds to which experimental group. Additionally, the group sizes may be different.

For each input file, your program should read in the data from the file. Your program will need to calculate the average and standard deviation for that data set. Your program will also need to determine if there is a significant difference between each pair of groups in this trial.

To determine if there is a significant difference between two groups in the trial, your program must compute the positive difference between the averages of the two groups. If the difference between the averages is larger than the standard deviations of both groups, then this is a significant result.

For example, given the following statistics:

group 1: average = 69.00, standard deviation = 18.42
group 2: average = 47.00, standard deviation = 19.92
group 3: average = 51.58, standard deviation = 19.20

There is a significant difference between group 1 and group 2, because:

69.00 - 47.00 is greater than 18.42 and 69.00 - 47.00 is greater than 19.92

However, there is not a significant difference between group 1 and group 3, because:

69.00 - 51.58 is not greater than 18.42

Your program should write the results to an output file. The results file will have two sections. The first section (Statistics) will list the name of each input file, followed by the average and then the standard deviation for that file. The second section (Results) will list the names of the two files being compared, and an indication (true or false) of whether or not the result is significant.

Here is a generalized example of the output file format:

Statistics:
<data file 1 name>: <average 1> <standard deviation 1>
<data file 2 name>: <average 2> <standard deviation 2>
<data file 3 name>: <average 3> <standard deviation 3>
Results:
<data file 1 name> vs. <data file 2 name> : (true/false)
<data file 1 name> vs. <data file 3 name> : (true/false)
<data file 2 name> vs. <data file 3 name> : (true/false)

Required Class
In addition to the class that contains your main method, you must implement and use the following TrialGroup class in your program. This class will be used to instantiate objects that will represent each of the three groups in a trial.

Each TrialGroup object will store the important information for one trial group:

the name of the file containing the group data (fileName),
the number of data points in that file (count),
the sum of the values in that file (sum),
and the sum of the squares of the values in that file (sumOfSquares).

These stored values will be used to calculate the average, and the standard deviation for the group.

The TrialGroup object will also be able to determine and return:

the average of the values in the group (getAverage),
the standard deviation of the values in the group (getStandardDeviation),
and the name of the file that the values came from (getFileName).

TrialGroup

- fileName : String

- count : int

- sum : int

- sumOfSquares : int

+ TrialGroup(fileName : String) <<constructor>>

+ getAverage( ) : double

+ getStandardDeviation( ) : double

+ getFileName( ) : String

The constructor for this class must initialize a TrialGroup object by:

  1. Storing the file name that is passed in as an argument, in the instance variable fileName.
  2. Opening the file whose name is passed in as an argument (fileName)
  3. Reading in the values in the file and determining the count, sum, and sum of the squares for the values in the file.
  4. Storing these values in the instance variables (count, sum, sumOfSquares)  

The getFileName method will simply return a copy of the string stored in the instance variable fileName.

The getAverage method will compute and return the average of the values in this trial group.

The getStandardDeviation method will compute and return the standard deviation of the values in this trial group.

Here is one way to determine the standard deviation of a set of numbers

Find the following values:

count - How many numbers are in the set
sum - The sum of the numbers in the set
sumOfSquares - The sum of the squares (n * n) of each number (n) in the set

With these values, you can compute the standard deviation like this:

First compute the average (sum / count)
Next compute the squareOfAverage (average * average)
Then compute the averageOfSquares (sumOfSquares / count)
Finally compute the standard deviation: sqrt(averageOfSquares - squareOfAverage)

You may add any attributes (variables) or operations (methods) that you wish to the TrialGroup class. However, you may not delete or change the details of any of the attributes and operations in the given class diagram above.

Test Data

For your testing convenience, Pepper has have provided 3 sets of test files of dummy data, and example output files based on the test files. Download these text files from the link below. Your program should use good programming practice and structure, including the definition and use of at least one class.

data1.dat:

57
96
84
72
64
60
83
33
52
89

data2.dat:

54
47
74
83
35
65
35
57
26
62
12
14
58
40
43

data3.dat:

30
37
52
62
23
70
43
89
77
57
35
44

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi Friend,

Here is the TrialGroup.java and the TrialGroupTest.java file. I have ran it against the 3 data files and the output is coming the same as given in the question.

When you run the driver class, enter the location of the file names and execute, I have shared the screenshot at the end for your assistance.

thank you , incase you need any help do let me know !

________________________________________________________________________________________

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class TrialGroup {

    private String fileName;
    private int count;
    private int sum;
    private int sumOfSquares;

    public TrialGroup(String fileName) {
        this.fileName = fileName;
        count = 0;
        sum = 0;
        sumOfSquares = 0;
        readFileContents();
    }

    public double getAverage() {

        return (1.0 * sum / count);
    }

    public double getStandardDeviation() {
        double average = getAverage();
        double squareOfAverage = average*average;
        double averageOfSquares=sumOfSquares/count;
        return Math.sqrt(averageOfSquares-squareOfAverage);

    }

    public String getFileName() {
        return fileName;
    }

    private void readFileContents() {

        File file = new File(fileName);
        try {
            Scanner scanner = new Scanner(file);
            while (scanner.hasNextLine()) {
                count += 1;
                int value = Integer.parseInt(scanner.nextLine());
                sum += value;
                sumOfSquares += value * value;
            }
            scanner.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

}

________________________________________________________________________________________

import java.util.Scanner;

public class TrialGroupTest {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter Data file 1 path: ");
        String dataFile1 = scanner.nextLine();

        System.out.print("Enter Data file 2 path: ");
        String dataFile2 = scanner.nextLine();

        System.out.print("Enter Data file 3 path: ");
        String dataFile3 = scanner.nextLine();

        TrialGroup groupOne = new TrialGroup(dataFile1);
        TrialGroup groupTwo = new TrialGroup(dataFile2);
        TrialGroup groupThree = new TrialGroup(dataFile3);

        System.out.println("group 1: average = " + String.format("%.2f", groupOne.getAverage()) + " standard deviation = " + String.format("%.2f", groupOne.getStandardDeviation()));
        System.out.println("group 2: average = " + String.format("%.2f", groupTwo.getAverage()) + " standard deviation = " + String.format("%.2f", groupTwo.getStandardDeviation()));
        System.out.println("group 3: average = " + String.format("%.2f", groupThree.getAverage()) + " standard deviation = " + String.format("%.2f", groupThree.getStandardDeviation()));


    }
}

________________________________________________________________________________________

thanks..

Add a comment
Know the answer?
Add Answer to:
Pepper's Pill Mill is a pharmaceutical company that is developing a new drug to help fight...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads...

    import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads numbers from a file, calculates the mean and standard deviation, and writes the results to a file. */ public class StatsDemo { // TASK #1 Add the throws clause public static void main(String[] args) { double sum = 0; // The sum of the numbers int count = 0; // The number of numbers added double mean = 0; // The average of the...

  • Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global...

    Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global variables should be used. PART B: (Statistics Program) – (50%) Please read this lab exercise thoroughly, before attempting to write the program. Write a program that reads the pairs of group number and student count from the text file (user must enter name of file) and: Displays the number of groups in the file (5 %) Displays the number of even and odd student...

  • Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global...

    Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global variables should be used. PART B: (Statistics Program) – (50%) Please read this lab exercise thoroughly, before attempting to write the program. Write a program that reads the pairs of group number and student count from the text file (user must enter name of file) and: Displays the number of groups in the file (5 %) Displays the number of even and odd student...

  • create a new Java application called "WeightedAvgWithExceptions" (without the quotation marks), according to the following guidelines...

    create a new Java application called "WeightedAvgWithExceptions" (without the quotation marks), according to the following guidelines and using try-catch-finally blocks in your methods that read from a file and write to a file, as in the examples in the lesson notes for reading and writing text files. Input File The input file - which you need to create and prompt the user for the name of - should be called 'data.txt', and it should be created according to the instructions...

  • Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file...

    Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file doesn’t exist. You will process through the file skipping any text or real (double) numbers. You will print the max, min, sum, count, and average of the integers in the file. You will want to create test files that contain integers, doubles, and Strings. HINT: Use hasNextInt() method and while loop. You may also want to use Integer.MAX_VALUE and Integer.MIN_VALUE for the initialization of...

  • create a new Java application called "WeightedAvgDataAnalyzer" (without the quotation marks), that modifies the DataAnalyzer.java in...

    create a new Java application called "WeightedAvgDataAnalyzer" (without the quotation marks), that modifies the DataAnalyzer.java in Horstmann Section 7.5, pp. 350-351 according to the specifications below. The input file should be called 'data.txt' and should be created according to the highlighted instructions below. Note that even though you know the name of the input file, you should not hard-code this name into your program. Instead, prompt the user for the name of the input file. The input file should contain...

  • Question 2 (10 points) (quality.py): We are provided with data from a quality control process in...

    Question 2 (10 points) (quality.py): We are provided with data from a quality control process in a manufacturing firm. The data file, "data.csv", contains several measurements. Each measurement is written in a separate line and each line contains two elements, the area where the measurement is made, and the measured value. These two values are separated with a comma (.). We are tasked to process this data in the following forms. a. First, we need to read the data from...

  • 7.2 Write a program that prompts for a file name, then opens that file and reads...

    7.2 Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form: X-DSPAM-Confidence: 0.8475 Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below. Do not use the sum() function or a variable named sum in your solution. You can download the sample data at http://www.py4e.com/code3/mbox-short.txt when you are...

  • Description: Create a program called numstat.py that reads a series of integer numbers from a file...

    Description: Create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the name of file, sum of numbers, count of numbers, average of numbers, maximum value, minimum value, and range of values. Purpose: The purpose of this challenge is to provide experience working with numerical data in a file and generating summary information. Requirements: Create a program called numstat.py that reads a series of integer numbers from a file and determines...

  • Please Use C++ for coding . . Note: The order that these functions are listed, do...

    Please Use C++ for coding . . Note: The order that these functions are listed, do not reflect the order that they should be called. Your program must be fully functional. Submit all.cpp, input and output files for grading. Write a complete program that uses the functions listed below. Except for the printodd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT