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
Need help ASPA!!!!!!!!!
professor190 [17]
Answer is D the internet
7 0
3 years ago
Read 2 more answers
Attackers need a certain amount of information before launching their attack. One common place to find information is to go thro
VARVARA [1.3K]

Answer:

The answer is Letter D. Dumpster diving.

Explanation:

This process of going through a target's trash is known in the community as dumpster diving. This attack is a technique used to retrieve information that could be used to carry out an attack on a computer network.

It is important to inform that the dumpster diving it is not limited to searching through  the trash for obvious treasures like acess codes or passwords written down on sticky notes.

8 0
2 years ago
The first documented use of work release was in the ____.
sattari [20]
I'd say in the United States.

This United States penological practice was inaugurated in 1913 by state senator Henry Huber. Typically, under the work release program, a prisoner who is sufficiently trusted  is employed outside the jail during working hours and returns to confinement at the end of the shift.



6 0
3 years ago
What group actively creates technology recommendation for the web?
xxMikexx [17]

The NETP provides actionable recommendations to implement technology and conduct research and development successfully that can advance the effective use of technology to support learning and teaching.


Hope this helps :)



6 0
3 years ago
Read 2 more answers
What specific database stores local user accounts on local computers, and allows users to sign in to and access resources only o
Yuki888 [10]

Answer:

The Security Account Manager

Explanation:

The Security Account Manager (SAM), This is a database file found in Windows Operating Systems.... Windows XP, Windows Vista, Windows 7, 8.1 and 10 that stores users' passwords. It can be used to authenticate local and remote users. It is  an important and vital component of how Windows stores passwords locally on the computer.

5 0
3 years ago
Other questions:
  • Pretrial services programs are also known as early intervention programs. <br> a. True <br> b. False
    15·1 answer
  • The concept of vertical farming allows agriculture to occur when there is not enough___Available .
    13·1 answer
  • There was an airplane crash, every single person on board died, but yet two people survived. How is this possible?
    5·2 answers
  • ________ software provides a means of sharing, distributing, and searching through documents by converting them into a format th
    13·1 answer
  • Which is the last step in conducting a URL search?
    5·2 answers
  • What are the three default security levels within software restriction policies?
    12·1 answer
  • Bran is writing a book on operation system errors. Help him complete the sentences.
    7·1 answer
  • If you cause a car accident, which type of insurance will require you to pay the least out of pocket?
    5·2 answers
  • The system partition is the partition that contains the files required to load the operating system (bootmgr, and BCD). The syst
    9·1 answer
  • What is the ability for a system to respond to unexpected failures or system crashes as the backup system immediately and automa
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!