程序代写代做代考 Java Wenzhou-Kean University

Wenzhou-Kean University
Department of Computer Science

Assignment # 3 (CPS2231)
(Sec – W01, W02)
Issue Date: 04-15-2017 Max Marks: 50
Due Date: 04-21-2017 till 11:59 pm
Question:
You are required to write a java code that generate first N triangle numbers and store them in a text file. The value of N should be given by the user. A triangle number is a number that is obtained by counting the objects that can form an equilateral triangle, as in the diagram given bellow. The nth triangular number is the number of dots composing a triangle with n dots on each side, and is equal to the sum of the n natural numbers from 1 to n. i.e. . For example, the value of . You can see the detail definition of triangle numbers on this Wikipedia page http://en.wikipedia.org/wiki/Triangular_number.

You are required to write a program that generates the first 1,000 triangle numbers and prints them out to a text file “TriNums_??????.txt”, ten numbers per line separated by commas. If the txt file does not exists, create a new file and if the file already exists overwrite it. Use proper messages and exceptions during the file creation. Additionally, while generating the numbers, you are to count how many times each digit 0-9 appears as the last digit (the ones digit) of those numbers. To do this, simply create an array of 10 integers that will be used as counters keeping track of how many times the corresponding digit appeared as the last digit. After printing all 1,000 triangle numbers to the file and examining their ones digit, print out the resulting counts at the end of the file. Use A_3_??????.java as the name of your java code file, where ?????? is your university ID.
After writing the data to the text file your program close the file properly and then reopen the file, read the data and then display it on the screen.
Example: This is a sample of the TriNums_??????.txt file that your A_3_??????.java program should create:
1, 3, 6, 10, …, 55,
….., 249750, 500500,
count for 0 = xx
count for 1 = xx
count for 2 = xx
count for 3 = xx
count for 4 = xx
count for 5 = xx
count for 6 = xx
count for 7 = xx
count for 8 = xx
count for 9 = xx

The output on the screen should looks like the following
The following data is read from the file…
1
3
6
15



249750
500500
count for 0 = 200
count for 1 = xx
count for 2 = xx
count for 3 = xx
count for 4 = xx
count for 5 = xx
count for 6 = xx
count for 7 = xx
count for 8 = xx
count for 9 = xx

Requirements:
A. You must start your program with header comments that provide your name and University ID, and also a declaration statement (“I have neither given nor received unauthorized help on this assignment”), and a short description of the program.
B. Each method that you write (except main), should be preceded by proper comments which describe what the method does, what the parameters are, and what it returns.
C. You should use a consistent programming style. This should include the following.
a. Meaningful variable & method names
b. Consistent indenting
c. Use of “white-space” and blank lines to make the code more readable
d. Use of comments to explain pieces of tricky code
e. A descriptive comment before each method (other than main, which already has a short description of the program).
f. Lines that do not extend beyond column 100 (or column 80 is even better)
Marks Distribution:
1. Creating the output file properly using exceptions. [05]
2. Generating and writing Tringle Numbers to the file correctly. [10]
3. Counting and writing different digits to the file correctly. [10]
4. Reading the file and displaying the Triangle Numbers and count of digits correctly. [10]
5. Applying proper logic so that the program should not terminate unexpectedly. [05]
6. Using properly commenting and programming style. [10]
Note: Try to write your own code, do not copy it from any other person. I reserve the right to give zero marks or any other penalty to similar/copy programs.
Use assign3 as the class name of your java code. Copy that java code in notepad or any text editor, save the file name as A_3_?????? , where replace ?????? with your university ID. Now Zip both the files together, give the name A_3_?????? to this zip file and then upload the file on turnitin.

Important points to be observed for assignment submission.
· Submit the soft copy through the turnitin account by using the link already send to you.
· Do not send the soft copy to me.
· Late submissions: Ten percent marks will be deducted for every day of late submission.