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
Suppose Host A wants to send a large file to host B. The path from Host A to Host B has three links, of rates R1 = 500 kbps, R2=
Lorico [155]

Answer:

The answer is 500 kbps

Explanation:

Consider the given data in the question.

R1 = 500 kbps

R2=2 Mbps

R3 = 1 Mbps

Now as it is mentioned that there is no other traffic in the network.

Thus,

throughput of the file = min {R1,R2,R3}

throughput of the file = min {500 kbps, 2 Mbps, 1 Mbps}

T/P of the file = 500 kbps

7 0
3 years ago
TRUE OR FALSE!!<br> Your location can be identified simply by turning on your cell phone..
Tasya [4]

Answer:

this is true

Explanation:

this is true because of the GPS location device built into your phone

3 0
3 years ago
Read 2 more answers
What is the largest place value in a 12 bit binary number?
azamat
The largest binary number that can be expressed with 12 bits is all 1s, which means 1 followed by 1 followed by 1, up to 12 times.
6 0
3 years ago
In a study of 1228 randomly selected medical malpractice​ lawsuits, it was found that 856 of them were dropped or dismissed. Use
ale4655 [162]

Answer:

<u>Hypothesis</u><u> </u>

H o : No difference between proportions

H 1 : There is a significant difference between proportions

n = 1228

b = 1228 - 856

b = 375

Since n ≥ 25

b = {( a + 0.5 ) - n/2 }\  ( √n )/2

   = {( 372 + 0.5 ) - 1228/2 }\ ( √1228 )/2

   = - 13.789

  • from table : A-2
  • p-value is 0.000
  • given significance level is α = 0.01
  • p-value is less than significance level hence there is enough evidence to reject null hypothesis
  • Which means there is a significance difference between the proportion of lawsuits that go to trail which should be dismissed
4 0
4 years ago
How to reply to text from unknown number?
Leto [7]
Safest way: DO NOT reply and BLOCK number.

If you are not sure if the guy is related to some stuff, it will be better to call him back, instead of texting.
5 0
3 years ago
Other questions:
  • Alpha Technologies, a newly established company, wants to share information about its work with people all over the world. Which
    9·1 answer
  • Why isn't my brainly camera working? I got Brainly Plus and can't even scan questions. I've logged out, I've uninstalled and rei
    14·1 answer
  • Which of the following plug-ins was developed by microsoft and is a software development tool used to write and run internet app
    10·1 answer
  • A Trojan horse:
    6·1 answer
  • The data set monarch from Computer-Active Data Analysis by Lunn andMcNeil (1991) contains the years lived after inauguration,ele
    9·1 answer
  • Write a C program that will load entries from a file containing details of books and prints them.
    14·1 answer
  • SimpleScalar is an architectural simulator which enables a study of how different pro-cessor and memory system parameters affect
    6·1 answer
  • (25 POINTS) Some applications work on all devices while others work on some devices. True or False?
    13·1 answer
  • Why is color important for all objects drawn ?​
    5·1 answer
  • 1. Flash Drive Price - An electronics company makes 64 gigabyte USB flash drives that cost them $8.00 apiece to produce. Write a
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!