Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have been stuck on this assignment all week and could use some help. It must be written in Java 4 Software Requirements Your program

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

I have been stuck on this assignment all week and could use some help. It must be written in Java

4 Software Requirements Your program shall: 1. Open a file named p01-in.txt containing n integers, 1 s ns 1000, with each integer in [0, 32767]. There will be one or more integers per line. A sample input file: Sample p01-in.trt 2 8 3 2 9 8 3 4619 2. The program shall compute runs for k-1, 2. 3, ., n-1 3. The program shall compute runsotal 4. The program shall produce an output file named p01-runs. trt containing runsttal and runst for k = 1, 2, 3, , n- 1 The file shall be formatted as shown in the example file below. Please make sure your output file meets the format shown below, e.g., all text is in lowercase, an underscore separates "runs" from the text that follows it, there is a space following each comma, and each line of text ends with a newline/endline character. During grading, we will compare your output file to our correct output file using an automated comparison program and if there is any mis- match then your program may be considered incorrect and you may lose substantial points. Sample p01-runs.trt runs total, 7 runs 1, 4 runs 2, 2 runs 3, 1 runs 4, 0 runs_5, 0 runs 6, 0 runs 7, runs8, 0 runs.9, 0 runs 10, 0 runs 11, 0 5. If the input file p01-in.trt 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. run program... Sorry, could not open 'p01-in.txt' for reading. Stopping If the output file p01-runs.trt cannot be opened for writing (e.g., because the write access to the file is disabled) then display an error message on the output window and immediately terminate the program, e.g. run program... Sorry, could not open p01-runs.txt' for writing. Stopping 6. 5 Software Design Your program shall: 1. Contain a class named Main. This class shall contain the main method. The main) method shall instantiate an object of the Main class and call run) on that object, see template code below 1/ Main.java public class Main [ public static void main(Stringll pArgs) ( Main mainobjectnew MainO; / Or you can just write: ne Main).run); mainObject.run) // in place of these two lines private void runO // You will start writing code here to implement the software requirement:s 2. One of the primary objectives of this programming project is to learn to use the java. util. ATrayList class. Therefore, you are not permitted to use primitive 1D arrays. Besides, you will quickly discover that the ArrayList class is more convenient to use than 1D arrays. 3. ArrayList listnew ArrayList>() int x- 1; list.add(x); // Legal because of Java autoboxing 4. You must write an exception handler that will catch the FileNotFoundException that gets thrown when the input file does not exist (make sure to test this). The exception handler will print the friendly error message as shown in Software Requirement 5 and immediately terminate the Java program. To immediately terminate a Java program we call a static method named ezit) which is in the java.lang.System class. The erit) method expects an int argument For this project, it does not matter what int argument we send to erit). Therefore, terminate the program this way by sending-1 to erit(. try t Try to open input file for reading catch (FileNotFoundException pExcept) // Print friendly error message System.exit (-1) Page 3 Programming Project 1: 25 pts 5. Similar to Item 4, you must write an exception handler that will catch the FileNotFoundException that gets thrown when the output file cannot be opened for writing. The exception handler will print the message as shown in Software Requirement 6 and then terminate the program. 6. Your programming skills should be sufficiently developed that you are beyond writing the entire code for a program in one method. Divide the program into multiple methods. Remember, a method should have one purpose, i.e., it should do one thing. If you find a method is becoming complicated because you are trying to make that method do more than one thing, then divided the method into 2, 3, 4, or more distinct methods, each of which does one thing. 7. Avoid making every variable or object an instance variable. For this project you shall not declare any instance variables in the class. That is, all variables should be declared as local variables in methods and passed as argu ments to other methods when appropriate. Neatly format your code. Use proper indentation and spacing. Study the examples in the book and the examples the instructor presents in the lectures and posts on the course website. 8. 9. Put a comment header block at the top of each method formatted thusly: *A brief description of what the method does t/ 10. Put a comment header block at the top of each source code file-not just for this project, but for every project we write-formatted thusly (or you may use /**comment style if you wish) CLASS: classname (classname.java) / DESCRIPTION // A description of the contents of this file /I COURSE AND PROJECT INFO // CSE205 Object Oriented Programming and Data Structures, semester and year // Project Number: project-number AUTHOR1: your-name, your-asuriteid, your-email-addr AUTHOR2: your-name, your-asuriteid, your-email-addr 5.1 Software Design: Pseudocode To help you complete the program. I recommend you implement this pseudocode - Note: In the Java implementation, main) vould call runO,so in essence, run) becoses the atarting point --of execution Method runO Returns Nothing Declare ArrayList of Integers list readInputFile("p01-in. txt") --Reads the integers from the input file Declare and create an ArrayList of Integers named listRunsUpCount Declare and create an ArrayList of Integers named listRunsDnCount listRunsUpCountfindRuns (list, RUNS UP) RUNS UP and RUNS DN are named constants, it does not matter what listAunsUpCount findRuns( list, RUNS-UP) listRunsDnCount findRuns( list, RUNS-DN) -value you assign to them as long as the values are different Declare ArrayList of Integers listRunsCount mergel ists( listRunsUPCont, lis tRunsDnCount) writeDutputFile("p01-runs.txt", listRunsCount) RUNS_UP and RUNS DN are named constants, it does not matter what End Methodrun plist is the ArrayList of Integers that were read fro "p01-in.txt". pDir is an int and is either RUNS UP or RUNS DN which speci fies in this method whether we are counting the number of runs up or runs dovn Method findRuns(plist : ArrayLiat of Integers, pDir : int) Returns ArrayList of Integers listAunsCount ar rayListCreate(pList, size(), 0) -- size is the same as PList and each element is init 'd to 0 Declare int variables i 0, K 0 -the left arrow represents the assignment operator Page 4 Programming Project 1: 25 pts Whilei

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

3. How has e-commerce transformed marketing?

Answered: 1 week ago