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
Anni [7]
3 years ago
6

Write a program that accepts a file name from the command line, then initializes an array with test data using that text file as

an input. The file should contain floating-point numbers (use double data type). The program should also have the following methods:
* getTotal. This method should accept a one-dimensional array as its argument and return the total of the values in the array.
* getAverage. This method should accept a one-dimensional array as its argument and return the average of the values in the array.
* getHighest. This method should accept a one-dimensional array as its argument and return the highest value in the array.
* getLowest. This method should accept a one-dimensional array as its argument and return the lowest value in the array.
Computers and Technology
1 answer:
postnew [5]3 years ago
4 0

Answer:

Complete code is given below:

Explanation:

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.util.Arrays;

import java.util.Scanner;

public class ArrayCalcs {

private int size;

String [] parts =null;

// based on number of elements in file, array will create.

double[] arr=null;

public void readFile(String file){

try{

FileReader fr = new FileReader(file+".txt");

BufferedReader br = new BufferedReader(fr);

String line = br.readLine();

int count = 0;

while (line != null) {

parts = line.split(" ");

for( String w : parts)

{

count++;

}

line = br.readLine();

}

size=count;

arr=new double[size];

for(int i=0;i<size;i++){

arr[i]=Double.parseDouble(parts[i]);

}

// System.out.println(count);

// System.out.println(Arrays.toString(parts));

System.out.println(Arrays.toString(arr));

} catch (FileNotFoundException ex){

System.out.println("This file does not exist");

} catch (IndexOutOfBoundsException e){

System.out.println("Thie file has more than 7 lines");}

catch (IOException e) {

System.out.println(e.getMessage());

}

}

public double getTotal(){

double sum=0.0;

for(double d:arr){

sum=sum+d;

}

return sum;

}

public double getAverage(){

double avg=getTotal()/arr.length;

return avg;

}

public double getHighest(){

double high=arr[0];

for(int i=0;i<arr.length-1;i++){

if(arr[i] > high)

high = arr[i];

}

return high;

}

public double getLowest(){

double low=arr[0];

for(int i=0;i<arr.length-1;i++){

if(arr[i] < low)

low= arr[i];

}

return low;

}

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

System.out.println("Enter file name:");

String file=s.next();

ArrayCalcs ac=new ArrayCalcs();

ac.readFile(file);

System.out.println(" Highest Element: "+ac.getHighest());

System.out.println("Lowest Element: "+ac.getLowest());

System.out.println("Total: "+ac.getTotal());

System.out.println("Average: "+ac.getAverage());

}

}

You might be interested in
Please help me with opinions, ideas, any websites that would help, or chart, article, video, or podcast to help support your pos
valina [46]

Answer:

Check explanation.

Explanation:

So, i will be going supporting positive effect of how the reshaping of of the media has affected the film industry. Since brainly do not support me to include links to websites and videos I will only be sharing my opinions on the subject.

One of the ways the media is been reshaped is through the platform known as the Social Networking Sites. This platform has helped people to create an account with them, create content on their sites and share this content. With the development of this platform the film industry can put their content on this platform and show it to the world. On platforms like this, the films can be viewed and shared to many individuals.

These Platforms are been employed by film makers/industry to disseminate their content and also for the generation of revenue.

7 0
3 years ago
To download a webpage, the web browser copies files and transfer them to your ____
Ganezh [65]

Computer is your best answer.


If you download the files, they will show up either on your computer home screen, or in the 'downloads' section of your computer files.



hope this helps

7 0
3 years ago
Read 2 more answers
The CPU converts into information. The CPU is the mastermind of the computer, controlling everything that goes on through a seri
Harman [31]

Answer:

Mathematical sequences

Explanation:

Just did it

5 0
2 years ago
Read 2 more answers
A company that manufactures machine parts order a new system that makes Products at ten times the speed of earlier machines. the
Semmy [17]
D i think hope this helps
7 0
3 years ago
Read 2 more answers
Will this solution really fix the problem?
vova2212 [387]

Answer:

yes it will

Explanation:

6 0
2 years ago
Other questions:
  • Which of the following is a true statement about psychological tests administered by computers? computers make standardization e
    9·1 answer
  • Please help! (I cant figure out)
    13·1 answer
  • Who invented the machine known as colossus?
    9·2 answers
  • PLEASE HELP ASAP<br> Which technology encrypts traffic between a web browser and a website?
    10·2 answers
  • Please help!<br><br> What is a non-iterative programming structure?
    11·1 answer
  • A label control may be added to a form by double-clicking on the Label control icon in the ________ window.
    15·1 answer
  • How to solve household arithmetic​
    7·1 answer
  • ____________________________ and _________________________ are 2 positive impacts of the internet on businesses.
    14·2 answers
  • In a word-processing program, what are the easily accessible icons that allow you to print, save and change fonts with a click o
    8·1 answer
  • Your motherboard has sockets for 184-pin dimm ram. which type of ram should you install?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!