Assignemnt #122 and Data From A File

Code

    ///Name: Daniel Tiffany-Appleton
    ///Period: 7
    ///Program Name: Data From A File
    ///File Name: DataFromAFile
    ///Date Finished: 3/28/16
    
    import java.io.File;
    import java.util.Scanner;
    
    public class DataFromAFile 
    {
    
        public static void main(String[] args) throws Exception 
        {
    
            String name;
            int a, b, c, d, sum;
    
            System.out.print("Getting name and three numbers from file.....");
    
            Scanner fileIn = new Scanner(new File("name-and-numbers.txt"));
    
            name = fileIn.nextLine();
            a = fileIn.nextInt();
            b = fileIn.nextInt();
            c = fileIn.nextInt();
            d = fileIn.nextInt();
    
            fileIn.close();
    
            System.out.println("done.");
            System.out.println("Your name is: " + name);
            sum = a + b + c + d;
            System.out.println(a + " + " + b + " + " + c + " + " + d + " = " + sum);
        }
    }
    //This type of scanner might cause problems because if the file is not named exacting what is stated, then the program doesn't work, and it only works with one text file.

    

Picture of the output

Assignment 122