CSE205 Object Oriented Programming and Data Structures Programming Project 1 1 Project Instructions We are currently working on a system for having you submit your programs for grading in such a way...

1 answer below »
Attached Programming Project 1 Instructions for your guidance, please adhere strictly.


CSE205 Object Oriented Programming and Data Structures Programming Project 1 1 Project Instructions We are currently working on a system for having you submit your programs for grading in such a way that we can automate as much of the grading as possible (so we can return graded projects sooner). We will let you know when that is ready and you can submit your project. In the meantime, please work on the project so you can complete it before the deadline—the deadline is specified in the Course Schedule section of the Syllabus. 2 Learning Objectives 1. To properly use the Integer wrapper class. 2. To declare and use ArrayList class objects. 3. To write code to read from, and write to, text files. 4. To write an exception handler for an I/O exception. 5. To write a Java class and instantiate objects of that class. 3 Background1 Let list be a nonempty sequence or list of non-negative random integers, each in the range [0, 32767] and let n be the length of list, e.g., here is one sample list: list = { 2, 8, 3, 2, 9, 8, 6, 3, 4, 6, 1, 9 } where n = 12. List elements are numbered with an index or subscript starting at 0, so the first 2 in list is at index 0, the 8 to the right of the 2 is at index 1, the 3 to the right of the 8 is at index 2, and so on, up to the final 9 which is at index 11. 3.1 Run Up Definition We define a run up in a list to be a (k + 1)-length subsequence of list (k > 1), starting at index i (0 ≤ i < n)="" denoted="" by="" listi,="" listi+1,="" listi+2,="" ...,="" listi+k="" (0="" ≤="" k="">< n)="" that="" is="" monotonically="" increasing.="" monotonically="" increasing="" means="" that="" listi+j="" ≤="" listi+j+1="" for="" each="" j="0," 1,="" 2,="" 3,="" ...,="" k)="" or="" in="" other="" words,="" each="" successive="" integer="" in="" the="" run="" up="" subsequence="" is="" greater="" than="" the="" integer="" which="" precedes.="" since="" the="" length="" of="" a="" run="" up="" is="" k="" +="" 1="" the="" value="" of="" k="" is="" 1="" less="" than="" the="" length="" of="" the="" run="" up.="" for="" example,="" if="" the="" length="" of="" the="" run="" up="" is="" 5="" then="" k="" is="" 4.="" note="" that="" a="" subsequence="" consisting="" of="" only="" one="" integer="" cannot="" be="" a="" run="" up="" because="" if="" it="" were,="" the="" length="" of="" the="" subsequence="" would="" be="" k="" +="" 1="1," meaning="" that="" k="0," but="" by="" definition,="" k="" must="" be=""> 1. Consequently, all runs up must be subsequences of length 2.≥ It may help to think of k as counting the number of spaces or holes in between each integer of the run up subsequence. Consider the run up {3 4 6}. The length of this subsequence is 3 meaning that k is 2. Notice that there are two spaces or holes in between 3 and 4 and in between 4 and 6. That is what k represents. 3.2 Run Down Definition Similarly, a run down in list is a (k + 1)-length subsequence (k > 1) starting at index i (0 ≤ i < n)="" denoted="" by="" listi,="" listi+1,="" listi+2,="" ...,="" listi+k="" (0="" ≤="" k="">< n),="" that="" is="" monotonically="" decreasing.="" monotonically="" decreasing="" means="" that="" listi+j="" ≥="" listi+j+1="" for="" each="" j="0," 1,="" 2,="" 3,="" ...,="" k)="" or="" in="" other="" words,="" each="" successive="" integer="" in="" the="" run="" down="" subsequence="" is="" less="" than="" the="" integer="" which="" precedes="" it.="" since="" the="" length="" of="" a="" run="" down="" is="" k="" +="" 1="" the="" value="" of="" k="" is="" 1="" less="" than="" the="" length="" of="" the="" run="" down.="" for="" example,="" if="" the="" length="" of="" the="" run="" down="" is="" 7="" then="" k="" is="" 6.="" note="" that="" a="" subsequence="" consisting="" of="" only="" one="" integer="" cannot="" be="" a="" run="" down="" because="" if="" it="" were,="" the="" length="" of="" the="" subsequence="" would="" be="" k="" +="" 1="1," meaning="" that="" k="0," but="" by="" definition,="" k="" must="" be=""> 1. Consequently, all runs down must be subsequences of length 2.≥ It may help to think of k as counting the number of spaces or holes in between each integer of the run down subsequence. Consider the run down {9 8 6 3}. The length of this subsequence is 4 meaning that k is 3. Notice that there are three spaces or holes: in between 9 and 8; in between 8 and 6; and in between 6 and 3. That is what k represents. 1 A student asked me where the idea and rationale for this project came from. In statistics, there is a pair of tests of randomness which are called the runs up and runs down tests. When I was a grad student in computer science, I wrote my master's thesis on pseudorandom number generation algorithms, and to test the randomness quality of the various algorithms I investigated, one of the tests I wrote and performed was the runs up and runs down tests. © Kevin R. Burger :: Computer Science & Engineering :: Arizona State University :: rev 286211 Page 1 CSE205 Object Oriented Programming and Data Structures Programming Project 1 3.3 The Runs Up in the Example List For the example list shown above we have the following runs up: list0 to list1 = {2, 8} is monotonically increasing because 2 < 8.="" the="" length="" of="" this="" subsequence="" is="" k="" +="" 1="2" so="" k="1." list3="" to="" list4="{2," 9}="" is="" mono.="" increasing="" because="" 2="">< 9.="" the="" length="" of="" this="" subsequence="" is="" k="" +="" 1="2" so="" k="1." list7="" to="" list9="{3," 4,="" 6}="" is="" mono.="" increasing="" because="" 3="">< 4="">< 6.="" the="" subsequence="" length="" is="" k="" +="" 1="3" so="" k="2." list10="" to="" list11="{1," 9}="" is="" mono.="" increasing="" because="" 1="">< 9.="" the="" subsequence="" length="" is="" k="2" so="" k="1." note="" that="" we="" do="" not="" consider="" {3,="" 4}="" and="" {4,="" 6}="" to="" be="" runs="" up="" because="" both="" those="" subsequences="" are="" subsequences="" of="" the="" subsequence="" {3,="" 4,="" 6}="" which="" is="" a="" run="" up.="" 3.4="" the="" runs="" down="" in="" the="" example="" list="" for="" the="" example="" list="" shown="" above="" we="" have="" the="" following="" runs="" down.="" list1="" to="" list3="{8," 3,="" 2}="" is="" monotonically="" decreasing="" because="" 8=""> 3 > 2 . The subsequence length is k + 1 = 3, so k = 2. list4 to list7 = {9, 8, 6, 3} is mono. decreasing because 9 > 8 > 6 > 3. The subsequence length is k + 1 = 4, so k = 2. list9 to list10 = {6, 1} is mono. decreasing because 6 > 1. The subsequence length is k + 1 = 2, so k = 1. Note that we do not consider {8, 3} and {3, 2} to be runs down because both those subsequences are subsequences of the subsequence {8, 3, 2} which is a run down. 3.5 The Problem Given a list of integers of variable length, we are interested in the value of k for each run up and run down in the list. In particular we are interested in the total number of runs for each possible value of k, which we shall denote by runsk, 1 < k="">< n. for the example list with n = 12, we have: k runsk runs 1 4 {2, 8}, {2, 9}, {1, 9}, and {6, 1} note: subsequence lengths are k + 1 = 1 + 1 = 2 2 2 {3, 4, 6} and {8, 3, 2} note: subsequence lengths are k + 1 = 2 + 1 = 3 3 1 {9, 8, 6, 3} note: subsequence lengths are k + 1 = 3 + 1 = 4 4 none none 5 none none … 10 none none 11 none none finally, we define runstotal to be be the sum from k = 1 to n - 1 of runsk. for the example list, runstotal = 4 + 2 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 = 7. 4 software requirements for this project, you will write a complete java program which meets these software requirements: 1. this is software requirement 1 (swr 1). open a file named p1-in.txt containing n integers, 1 ≤ n 1000, with≤ each integer in [0, 32767]. there will be one or more integers per line. here is a sample input file for the list of §3. sample p1-in.txt 2 8 3 2 9 8 6 3 4 6 1 9 2. swr2. the program shall compute runsk for k = 1, 2, 3, ..., n - 1. 3. swr 3. the program shall compute runstotal. 4. swr 4. the program shall produce an output file named p1-runs.txt containing runstotal and runsk for k = 1, 2, 3, ..., n - 1. the file shall be formatted as shown in the example file below: © kevin r. burger :: computer science & engineering :: arizona state university :: rev 286211 page 2 cse205 object oriented programming and data structures programming project 1 sample p1-runs.txt runs_total: 7 runs_1: 4 runs_2: 2 runs_3: 1 runs_4: 0 runs_5: 0 runs_6: 0 runs_7: 0 runs_8: 0 runs_9: 0 runs_10: 0 runs_11: 0 5. swr 5. if the input file p1-in.txt cannot be opened for reading (because it does not exist) then display an error message on the output window and immediately terminate the program, e.g., you program shall display a message similar to this and then exit: run your program… test case input file could not be opened... oops, could not open 'p1-in.txt' for reading. the program is ending. 6. swr 6. if the output file p1-runs.txt cannot be opened for writing (e.g., because write access to the file is disabled or you are trying to open the file in a location which is prohibited) then display an error message on the output window and immediately terminate the program, e.g., run your program… test case output file could not be opened... oops, could not open 'p1-runs.txt' for writing. the program is ending. 5 software design requirements you are free to create your n.="" for="" the="" example="" list="" with="" n="12," we="" have:="" k="" runsk="" runs="" 1="" 4="" {2,="" 8},="" {2,="" 9},="" {1,="" 9},="" and="" {6,="" 1}="" note:="" subsequence="" lengths="" are="" k="" +="" 1="1" +="" 1="2" 2="" 2="" {3,="" 4,="" 6}="" and="" {8,="" 3,="" 2}="" note:="" subsequence="" lengths="" are="" k="" +="" 1="2" +="" 1="3" 3="" 1="" {9,="" 8,="" 6,="" 3}="" note:="" subsequence="" lengths="" are="" k="" +="" 1="3" +="" 1="4" 4="" none="" none="" 5="" none="" none="" …="" 10="" none="" none="" 11="" none="" none="" finally,="" we="" define="" runstotal="" to="" be="" be="" the="" sum="" from="" k="1" to="" n="" -="" 1="" of="" runsk.="" for="" the="" example="" list,="" runstotal="4" +="" 2="" +="" 1="" +="" 0="" +="" 0="" +="" 0="" +="" 0="" +="" 0="" +="" 0="" +="" 0="" +="" 0="7." 4="" software="" requirements="" for="" this="" project,="" you="" will="" write="" a="" complete="" java="" program="" which="" meets="" these="" software="" requirements:="" 1.="" this="" is="" software="" requirement="" 1="" (swr="" 1).="" open="" a="" file="" named="" p1-in.txt="" containing="" n="" integers,="" 1="" ≤="" n="" 1000,="" with≤="" each="" integer="" in="" [0,="" 32767].="" there="" will="" be="" one="" or="" more="" integers="" per="" line.="" here="" is="" a="" sample="" input="" file="" for="" the="" list="" of="" §3.="" sample="" p1-in.txt="" 2="" 8="" 3="" 2="" 9="" 8="" 6="" 3="" 4="" 6="" 1="" 9="" 2.="" swr2.="" the="" program="" shall="" compute="" runsk="" for="" k="1," 2,="" 3,="" ...,="" n="" -="" 1.="" 3.="" swr="" 3.="" the="" program="" shall="" compute="" runstotal.="" 4.="" swr="" 4.="" the="" program="" shall="" produce="" an="" output="" file="" named="" p1-runs.txt="" containing="" runstotal="" and="" runsk="" for="" k="1," 2,="" 3,="" ...,="" n="" -="" 1.="" the="" file="" shall="" be="" formatted="" as="" shown="" in="" the="" example="" file="" below:="" ©="" kevin="" r.="" burger="" ::="" computer="" science="" &="" engineering="" ::="" arizona="" state="" university="" ::="" rev="" 286211="" page="" 2="" cse205="" object="" oriented="" programming="" and="" data="" structures="" programming="" project="" 1="" sample="" p1-runs.txt="" runs_total:="" 7="" runs_1:="" 4="" runs_2:="" 2="" runs_3:="" 1="" runs_4:="" 0="" runs_5:="" 0="" runs_6:="" 0="" runs_7:="" 0="" runs_8:="" 0="" runs_9:="" 0="" runs_10:="" 0="" runs_11:="" 0="" 5.="" swr="" 5.="" if="" the="" input="" file="" p1-in.txt="" cannot="" be="" opened="" for="" reading="" (because="" it="" does="" not="" exist)="" then="" display="" an="" error="" message="" on="" the="" output="" window="" and="" immediately="" terminate="" the="" program,="" e.g.,="" you="" program="" shall="" display="" a="" message="" similar="" to="" this="" and="" then="" exit:="" run="" your="" program…="" test="" case="" input="" file="" could="" not="" be="" opened...="" oops,="" could="" not="" open="" 'p1-in.txt'="" for="" reading.="" the="" program="" is="" ending.="" 6.="" swr="" 6.="" if="" the="" output="" file="" p1-runs.txt="" cannot="" be="" opened="" for="" writing="" (e.g.,="" because="" write="" access="" to="" the="" file="" is="" disabled="" or="" you="" are="" trying="" to="" open="" the="" file="" in="" a="" location="" which="" is="" prohibited)="" then="" display="" an="" error="" message="" on="" the="" output="" window="" and="" immediately="" terminate="" the="" program,="" e.g.,="" run="" your="" program…="" test="" case="" output="" file="" could="" not="" be="" opened...="" oops,="" could="" not="" open="" 'p1-runs.txt'="" for="" writing.="" the="" program="" is="" ending.="" 5="" software="" design="" requirements="" you="" are="" free="" to="" create="">
Answered 2 days AfterJan 18, 2022

Answer To: CSE205 Object Oriented Programming and Data Structures Programming Project 1 1 Project Instructions...

Pawan answered on Jan 21 2022
112 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here