Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9142391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:46:23+00:00 2026-06-17T09:46:23+00:00

I need to use a double vector to store an average of a student.

  • 0

I need to use a double vector to store an average of a student.

The file I’m reading from is set up like this:

2  //num of students
60   //total possible score
John   //name
4 16 9 7 10  //scores

So I need to convert the string to a double, add all the ints from the line, divide into an average, then store the average into the double vector.

the code I have so far is:

public static String line;
public static Scanner in = new Scanner(System.in);
public static void main(String[] args) {


    System.out.println("enter the name of your file");
    String filename = in.next();
    FileIn file = new FileIn(filename);

    String firstLine; // String to hold first line which is number of students total in file.
    String secondLine; //String to hold second line which is number of points available 
    
    
    ArrayList<String> students = new ArrayList<String>();  // holds the students names

    //reads first line of the file. sets that number as the number of students
    firstLine = file.read();
    int numStu = Integer.parseInt(firstLine);
    // Just to test that number is being read correctly.
    System.out.println(numStu + " Number of students");

    //reads the second line of the file. sets that number as the total possible points in a semester
    secondLine = file.read();
    int totalPoints = Integer.parseInt(secondLine);
    // Just to test that number is being read correctly.
    System.out.println(totalPoints + " Total possible points");
    
    
    double avg = 0;
    double[]vector = new double [numStu]; 
    
    readFile(students,numStu,file,vector, avg);
    
    System.out.println(students);
    System.out.println(vector);
}

//puts the names into an arraylist and scores into a double vector
public static void readFile(ArrayList<String> students,int numStu, FileIn file, double[]vector, double avg)
{
    for(int k=0; k<(numStu*2); k++)
    {
                    //odd numbers are the students
        if (k % 2 == 0)
            students.add(file.read());

        else
        {
            //code to read and add the numbers from one line together, and storing the added and averaged score
        }
    }
}


}

As you can see I’m missing the bottom part where im distributing the file elements into a double vector

my FileIn class looks like this:

private String myFileName;
private BufferedReader myFile;
public FileIn(String filename)
{
    myFileName = filename;
    try
    {
        myFile = new BufferedReader(new FileReader(myFileName));
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    finally{}
}

public String read()
{
    String myLine = new String();
    try
    {
        myLine = myFile.readLine();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    finally{}
    return myLine;
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:46:24+00:00Added an answer on June 17, 2026 at 9:46 am

    Complete the following piece of code, and you will know the answer to your own question once you finished it.

    public class Foo {
      public static int main(String[] args) {
        String input = "10 15 20.5 70 40";
    
        // write code to convert the input string to doubles and sum them up
        double sum = ......;
    
        // answer should equals to 155.5
      }
    }
    

    Hints: String.split() and Double.parseDouble(), and make use of a for loop

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading this question , I've decided I need to use something like this: list<vector<double>
I need use this method with three distinct classes: Orders, Customers, Suppliers public void
I need use this code: <%= button_tag :class => btn btn-primary do %> <%=
So, I need use this event so I can navigate trought blog posts. I
I use a quad tree as a datastructure to store points. As I need
If I use std::vector<> or std::string, do I need to allocate them in heap
I have installed Matlab r2010a on my computer I need use the function xlsread
Need to use own imaged markers instead built-in pins. I have several questions. 1.
I need to use maps on running in a physical Android device, how do
I need to use the objdump and readelf commands in my application that runs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.