Project Euler 22: Assigns scores for names that are imported from text file Project Euler 22


  Using atext file containing over five-thousand first names, and you
  will calculate a score for each name. Begin by reading the names from
  the file and sorting them in alphabetical order. Then, you will
  compute an alphabetical value for each name where A is 1, B is 2, C is
  3 and so on. The alphabetical value of a name is just the sum of the
  values of the letters in the name. To compute the name-score for a
  name, you simply multiply this alphabetical value by its position in
  the sorted list.
  
  For example, when the list is sorted into alphabetical order, COLIN,
  which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the
  list.


So, the name-score for COLIN would be 938 * 53 = 49714.
What is the sum total of all the name-scores in the file?

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

public class ScoringNames {
    BufferedReader x = null;
    String location = "C:\\Users\\xxxxxxxi\\Dropbox\\"
                    + "College\\COSC 1430\\Scoring Names\\names.txt";

    ArrayList&lt;String&gt; names = new ArrayList&lt;String&gt;();
    static ArrayList&lt;Integer&gt; scores = new ArrayList&lt;Integer&gt;();
    static int ns[];

    public void fillNS(){
        for (int x = 0; x &lt; ns.length; x++){
            ns[x] = scores.get(x) * (x+1);
        }
    }

    public void printNS(){
        for (int x = 0; x &lt; ns.length; x++)
            System.out.print(ns[x] + ", ");
    }

    public void readFile(){ //Opens file, and prints every line.
        try{
            x = new BufferedReader(new FileReader(location));
        } catch(FileNotFoundException e) {
            e.printStackTrace();
        }

        try{
            String name = x.readLine();
            while(name != null){
                //System.out.println(name);
                names.add(name);
                name = x.readLine();
            }
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    public void sortNames(){ //Sort names array in alphabetical order
        Collections.sort(names);
    }

    public void printNames(){
        for(String counter: names)
            System.out.println(counter);
    }

    public int alphValue(char x){
        return (x - 'A' + 1);
    }

    public void returnSize(){
        System.out.println(names.size());
    }

    public int nameScore(String name){
        int score = 0;
        char[] tempName = name.toCharArray();
        for (char i : tempName){
                score += alphValue(i);
            }

        return score;
    }

    public void addScores(){
        for(String x : names){
            scores.add(nameScore(x));
        }
    }

    public void printScores(){
        for(int counter: scores)
            System.out.println(counter);
    }

    public int totalNS(int[] x){
        int sum = 0;
        for(int i = 0; i &lt; x.length; i++){
            sum += x[i];
        }
        return sum;
    }

    public static void main(String[] args) {
        ScoringNames abc = new ScoringNames(); 
        abc.readFile(); 
        abc.sortNames(); 
        //abc.printNames(); 
        abc.addScores(); 
        //abc.printScores(); 
        ns = new int[scores.size()];
        abc.fillNS(); 
        //abc.printNS();
        //System.out.println(ns[937]); //"COLIN"
        System.out.println("The sum total of all name scores is: " + 
                            abc.totalNS(ns));
    }

}
Reading the file: you declare the BufferedReader as an instance variable while it is only used locally. Don't do that: variables should always have the smallest scope possible. In addition, resources should normally be closed in the same scope that opens them (which brings me to the point that you never close the buffered reader.)

Furthermore, you put the opening and reading in two different try-catch constructs. That makes no sense. If the first fails, you cannot expect the second to work.

Thus, using "classic" code, you should put it together as a try-with-resources block, which automatically closes the opened resource, something like this:

try (BufferedReader reader = new BufferedReader(new FileReader(location))) {
    String name;
    while((name = reader.readLine()) != null) { // classic construct ;-)
        names.add(name);
    }
}
catch(IOException e) {
    // Do something useful. Especially, do NOT continue program
    // execution, as you don't have any data anyway!
}


But as this is 2017 and the library is quite mature, you should really simply use java.nio.Files:

Files.readAllLines(Paths.get(location))


is all you need.

There are quite a few more problems in your code (especially the mixup of static and instance variables), but alas my time is limited right now.