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
They have outlined their technical needs and have sent some of the documentation along with the potential provider's SLAs and te
iren2701 [21]

Answer:

A concern that might be expressed by the legal department after reviewing the SLAs and terms of service is:

c. Ensuring that there is a guarantee that the cloud service provider will provide notice in the event that they decide to discontinue operations.

Explanation:

The SLA that the legal department will review should include a description of the services to be provided, expected service levels, measurement metrics for each service, each party's duties and responsibilities, and the contract remedies or penalties for breach, among others.  But the legal department will be mostly concerned with legal remedies during breaches, liability limitation and warranties, and intellectual property protection issues than with more technical issues.  This is despite the fact that all the terms of the SLA will be diligently reviewed by the legal department.

7 0
3 years ago
3. In a 32-bit CPU, the largest integer that we can store is 2147483647. Verify this with a
Semenov [28]

Answer:

No, it can't be verified with a pseudocode.

Explanation:

We can not verify this with a pseudocode because the largest integer that we can store in 32-bit integer goes by the formula 2^32 - 1 = 4, 294, 967,295 and this means that it has 32 ones. Or it may be 2^31 - 1 = 2, 147, 483,647 which is a two complement signed integer.

Despite the fact that it can not be verified by using pseudocode, we can do the Verification by writting programs Through some programming language or in plain English code.

In a 32-bit CPU, the largest integer that we can store is 2147483647 because we can store integer as 2^31 and - (2^31 + 1).

5 0
3 years ago
When you send an email how many computers does it go to
Xelga [282]

once you have sent the email it will only go to the server which then the person receiving it would log on therefore requesting the emails recived.

I'm not 100% sure my answer is classed as correct but I would say it doesn't go to a computer it just gets stored on a server in till requested

4 0
3 years ago
Consider the code fragment below (with nested loops). int sum = 0;for (int i = 1; i &lt; 5; i++) for (int j = 1; j &lt;= i; j++)
sammy [17]

Answer:

Option d is the correct answer for the above question.

Explanation:

  • The first loop of the program has a second loop and then the statement. In this scenario, the second loop executes for the value of the first loop and the statement executes for the value of the second loop.
  • The first loop executes 4 times, Then the second loop or inner loop executes n times for the n iteration of the first loop, for example, 1 time for the first iteration of the first loop, 2 times for the second iteration of the first loop and so on.
  • Then the inner loop executes (1+2+3+4) iteration which gives the result 10 iterations.
  • The sum initial value is 0 and the "sum++", increase the value of the sum by 1.
  • So the value of the sum becomes 10 after completing 10 iterations of the inner for loop.
  • Hence the 10 will be the output. So the Option d is the correct answer while the other is not.
3 0
3 years ago
Why must programs written in a high-level language be translated into machine language?
eimsori [14]
The only thing that a computer actually understands is machine language. English-like constructs are gibberish to a computer, so they need to be translated by a compiler to machine language to run natively.
4 0
3 years ago
Other questions:
  • Suppose we eliminate tcp and instead rely exclusively on udp as our only transport layer protocol. ⢠how does this impact opera
    15·1 answer
  • Janis is preparing a financial document. She needs to use the dollar symbol placed above the number key 4. Which key will Janis
    12·2 answers
  • Which organization safeguards americans from health, safety, and security hazards and threats?
    14·2 answers
  • Computer-based networks that trigger actions by sensing changes in the real or digital world are known as: global marketing plat
    6·1 answer
  • What can be designed to create annoying glitches or destroy data
    11·1 answer
  • What is a benefit of the rise in citizen journalism? Multiple answer choice below
    13·1 answer
  • The
    6·1 answer
  • Second Largest, Second Smallest Write a program second.cpp that takes in a sequence of integers, and prints the second largest n
    15·1 answer
  • When you sign in to your Microsoft account with another Windows device, your settings will appear very differently than they do
    7·1 answer
  • What are 3 of the most important things about internet safety that you would recommend and why
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!