1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ohaa [14]
3 years ago
13

Write a program that:

Computers and Technology
1 answer:
gregori [183]3 years ago
4 0

Answer:

The Java code is given below with appropriate comments for better understanding

Explanation:

//DataAnalyzer.java

import java.util.*;

class DataAnalyzer

{

  private LinkedList<Integer> numbers;

  //Parameterized Constructor that stores the list of numbers

  public DataAnalyzer(LinkedList<Integer> numList)

  {

      //Storing numList to numbers

      numbers = numList;

  }

  //Implementation of min() method that returns minimum number

  public int min()

  {

      //consider starting number is the minimum number

      int minNum = numbers.get(0);

      //Iterate the numbers in the list

      for(int j=0; j < numbers.size(); j++)

      {

          //Comparing each number with minNum

          if( numbers.get(j) < minNum )

              //Update minimum number

              minNum = numbers.get(j);

      }

      //Return minimum number of the list

      return minNum;

  }

  //Implementation of max() method which returns maximum number

  public int max()

  {

      //consider starting number is the max number

      int maxNum = numbers.get(0);

      //Iterate the numbers in the list

      for(int j=0; j < numbers.size(); j++)

      {

          //Comparing each number with maxNum

          if( numbers.get(j) > maxNum )

              //Update maximum number

              maxNum = numbers.get(j);

      }

     

      //Return maximum number of the list

      return maxNum;

  }

  //Implementation of average() method returns average of all numbers

  public double average()

  {

       //Declare sum as type of integer and assign value as zero

      int sum = 0;

      //Declare avg as type of double type

      double avg;

     

      //Iterate the numbers in the list

      for(int j=0; j < numbers.size(); j++)

      {

          //add sum of numbers

          sum = sum + numbers.get(j);

      }

     

      avg = sum / (double)(numbers.size());

      //Return average value of the list

      return avg;

  }

}

DataAnalyzerTester.java

//DataAnalyzerTester.java

import java.util.*;

import java.io.*;

//Implementation of DataAnalyzetTester class

class DataAnalyzerTester

{

  //Main method

  public static void main(String args[])

  {

      try

      {

          //Declare numList as variable of type

      //Linked list that store user input

          LinkedList<Integer> numList = new LinkedList<Integer>();

          int num;

     

          //Declare Scanner class object

          Scanner input = new Scanner(System.in);

          String fileName;

          //Display statement

          System.out.print("\n Enter file name for storing numbers: ");

          fileName = input.nextLine();

         

          //Create a variable as file type

          File createfile = new File(fileName);

          //Creating file

          createfile.createNewFile();

          //Creating a FileWriter Object

          FileWriter writer = new FileWriter(createfile);

         

          System.out.println("\n Start entering numbers (0 to stop): \n\n");

     

          //Reading number

          num = input.nextInt();

     

          //Iterate the loop

          //until user enters 0

          while(num != 0)

          {

              //Writing numbers to the file

              writer.write(num + " \n ");

             

              //Add those numbers to list

              numList.add(num);

              //Get another number from user

              num = input.nextInt();

          }

          //Creating DataAnalyzer object

          DataAnalyzer analyzerObject = new DataAnalyzer(numList);

          //Display statement for min, max and average values

          System.out.println("\n\n Minimum Number: " + analyzerObject.min());

          writer.write("\n\n Minimum Number: " + analyzerObject.min());

          System.out.println("\n\n Maximum Number: " + analyzerObject.max());

          writer.write("\n\n Maximum Number: " + analyzerObject.max());

          System.out.println("\n\n Average: " + analyzerObject.average() + " \n\n");

          writer.write("\n\n Average: " + analyzerObject.average() + " \n\n");

         

          writer.flush();

         

          //Close the file object

          writer.close();

      }

     

      catch(Exception ex)

      {

      //display statement

          System.out.println(ex);

      }

  }

}

You might be interested in
The image type used for graphics that need smaller sizes with no loss of quality is a ___________.
Novosadov [1.4K]
I believe the answer it TIF 
4 0
3 years ago
Blue light reduces quality sleep and comes from
weeeeeb [17]

the answer is electronic screens

hope this helps

3 0
3 years ago
Read 2 more answers
Who plays rocket league?
Rashid [163]

Answer:

I dont

Explanation:

8 0
3 years ago
Read 2 more answers
The parts of a memo are _____.
RoseWind [281]

They would be:

Reader’s name, your name, the date, the subject, and the body of the memo.

4 0
3 years ago
Read 2 more answers
Mt. Everest, the highest mountain in the world, is located in Asia.<br><br> True<br> False
Roman55 [17]
True, it is located on the border of Nepal and Tibet.
8 0
3 years ago
Other questions:
  • A bit shift is a procedure whereby the bits in a bit string are moved to the left or to the right. For example, we can shift the
    12·1 answer
  • What are some tasks Petroleum Engineers perform?
    5·2 answers
  • FINISH THE SENTENCE <br><br> buzzfeed____reddit_____
    5·1 answer
  • How do you take a picture on this app
    10·1 answer
  • How many inches do a tire have to be to sometimes be refer as bald of balding tries
    14·1 answer
  • What does route print do?
    15·1 answer
  • Draw a flowchart diagram for a program that display a person's name x times​
    5·1 answer
  • Select the correct answer.
    14·1 answer
  • High speed printer that produce higher quality printouts but are more expensive is
    15·1 answer
  • Which of the following media forms is the Federal Communications Commission able to regulate content on?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!