Programming Assignment 2 Solution



Write a program that reads the contents of a file into a character array and sums the characters that represent the numerical digits. The file will contain ASCII values.


  1. If your code does not compile, you will receive an automatic score of 0. It is YOUR responsibility to come see ME for help if you need it.

  2. (1 point) The source code file must be named

  1. (1 point) Include a proper Javadoc comment for the program that includes a description of the program and also includes your name.

  2. Your program should:

    1. (2 points) Read the name of a text file from the user that contains ASCII values and open the file for reading. You should do this either in the main method or a method separate from the ones described below. Remember that the purpose of a method is to perform one individual task in the program.

    2. (5 points) Your program must have a method that will read in all values from a file and store all the values as characters in an array. Do not use an ArrayList. The maximum possible number of values in the file will be 100. Keep in mind that you will not know ahead of time how many values are in the file. You will need to carefully consider how to handle this.

    1. (5 points) Write a method that will sum the digits 0 through 9 in a character array and return the sum of the digits. Again, do not use an ArrayList. Make certain the code in the method also considers if a character in the array is not a digit! (I will test for this.)

    1. (1 point) Let the user know the sum of the digits in a user-friendly manner.

  1. (3 points) You should have proper Javadoc comments directly above all methods with a description of the method and any necessary tags and descriptions.

  1. (2 points) Use good programming practices throughout the code (variable names are descriptive and follow variable naming conventions, properly indent different parts of the code, vertically line up curly braces or headers, lines of code are not longer than 80 characters, output is user-friendly, etc.).

Submit the source file in Blackboard

Log into Blackboard and go to our course page. Under Content in the left menu, open the folder for the Programming Assignments. Click on the link for Program 2. Under Assignment Submission, use Browse My Computer next to Attach File and find the .java file. Only submit the .java file! When the file has been attached, click the Submit button.

error: Content is protected !!