Assignment 17 Deadline: Oct pm COSC211 CRN15376 Session 14 (Oct. 29)

Similar documents
Project #1 Computer Science 2334 Fall 2008

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

An exception is simply an error. Instead of saying an error occurred, we say that an.

10/8/2018 Programming Data Structures. class diagram for assignment 08 review: polymorphism review: exception new: File I/O

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

Menu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:

Recitation: Loop Jul 7, 2008

Lab and Assignment Activity

File class in Java. Scanner reminder. File methods 10/28/14. File Input and Output (Savitch, Chapter 10)

Full file at

H212 Introduction to Software Systems Honors

10/22/2018 Programming Data Structures

Files & Exception Handling. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

Chapter 4 Loops. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Assignment 19 Deadline: Nov pm COSC211 CRN15376 Session 15 (Nov. 7)

Programming Assignment Comma Separated Values Reader Page 1

Chapter 12. File Input and Output. CS180-Recitation

COMP102: 181. Menu. More while loops. Admin: Test. Peter Andreae

CS165 Practice Final Exam

Files. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

Files. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

Name: Checked: Preparation: Write the output of DeckOfCards.java to a text file Submit through Blackboard by 8:00am the morning of Lab.

Reading Input from Text File

CMPSCI 187: Programming With Data Structures. Lecture #24: Files and a Case Study David Mix Barrington 2 November 2012

Name: Checked: Preparation: Investment Calculator with input and output to text files Submit through Blackboard by 8:00am the morning of Lab.

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

Spring 2013 Homework Assignment #3. Due: 8 November 2012, 11:00pm Covers Chapters: 11, 13.

Quiz 1. In class on Tuesday (April 14) Review learning goals (from lecture) Review lectures 1 4, PSA 1 You should be able to:

9/24/2018 Programming Data Structures

Final Exam. CSC 121 Fall Lecturer: Howard Rosenthal. Dec. 13, 2017

CS165 Practice Final Exam Answer Key

Introduction IS

CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016

CSIC Computing Project

CS 151. Exceptions & Javadoc. slides available on course website. Sunday, September 9, 12

STUDENT LESSON AB24 Recursive Array Programming

Exception Handling. General idea Checked vs. unchecked exceptions Semantics of... Example from text: DataAnalyzer.

Mandatory Assignment 1, INF 4130, 2017

CSE 143: Computer Programming II Spring 2015 HW7: 20 Questions (due Thursday, May 28, :30pm)

PIC 20A Exceptions. Ernest Ryu UCLA Mathematics. Last edited: November 27, 2017

Simple Java Input/Output

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

1. An operation in which an overall value is computed incrementally, often using a loop.

CISC 323 (Week 9) Design of a Weather Program & Java File I/O

Input from Files. Buffered Reader

Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM

Programming Languages and Techniques (CIS120)

Final Exam Practice. Partial credit will be awarded.

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name:

Input/Output (I/0) What is File I/O? Writing to a File. Writing to Standard Output. CS111 Computer Programming

Exceptions - Example. Exceptions - Example

Outline for Today CSE 142. Programming a Teller Machine. CSE142 Wi03 I-1. ATM Algorithm for Dispensing Money

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

CS 455 Midterm 2 Spring 2018 [Bono] Apr. 3, 2018

Question 0. (1 point) Write the correct ID of the section you normally attend on the cover page of this exam if you have not already done so.

COMP String and Console I/O. Yi Hong May 18, 2015

STUDENT LESSON A12 Iterations

Administration. Exceptions. Leftovers. Agenda. When Things Go Wrong. Handling Errors. CS 99 Summer 2000 Michael Clarkson Lecture 11

Final Exam. CSC 121 Fall Lecturer: Howard Rosenthal. Dec. 13, 2017

CSE 143. Lecture 9: introduction to recursion reading: 12.1

CS 231 Data Structures and Algorithms Fall 2018

Unit 10: exception handling and file I/O

CSE 143: Computer Programming II Summer 2015 HW6: 20 Questions (due Thursday, August 13, :30pm)

CSCI 200 Lab 2 Inheritance, Polymorphism & Data Streams

Question 1. (2 points) What is the difference between a stream and a file?

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name:

Introduction to Java Written by John Bell for CS 342, Spring 2018

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name

Agenda: Discussion Week 7. May 11, 2009

You must define a class that represents songs. Your class will implement the Song interface in $master/proj2/cs61b/song.java.

Programming Assignment 8 ( 100 Points )

ECE 122. Engineering Problem Solving with Java

JAVA BASICS II. Example: FIFO

CS100M November 30, 2000

CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03

Lecture 11 (review session for intro to computing) ============================================================== (Big-Oh notation continued)

You will not be tested on JUnit or the Eclipse debugger. The exam does not cover interfaces.

CSCI-140 Midterm Review October 10, 2015 Presented by the RIT Computer Science Community

CS 200 File Input and Output Jim Williams, PhD

CS 61B Data Structures and Programming Methodology. July 7, 2008 David Sun

Advanced Java Concept Unit 1. Mostly Review

A Guide Illustrating the Core Java Equivalent to Selected Tasks Done Using the HSA Class Library

Streams and File I/O

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

Input-Output and Exception Handling

CPSC Introduction to Computer Science for Computer Science Majors II Monir Zaman (Md Moniruzzaman)

CS1083 Week 2: Arrays, ArrayList

Exercise 4: Loops, Arrays and Files

Give one example where you might wish to use a three dimensional array

Question 1a) Trace of program

ECE242 Data Structures and Algorithms Fall 2008

Object-Oriented Programming Design Topic : Exception Programming

Experiment No: Group B_4

Chapter 2: Basic Elements of Java

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

WES-CS GROUP MEETING #9

CS61BL. Lecture 1: Welcome to CS61BL! Intro to Java and OOP Testing Error-handling

CS Week 11. Jim Williams, PhD

Transcription:

This in-class assignment has 2 points in total. Every bug costs 0.1-0.3 based on its severity. The deadline for this assignment is Tuesday, Oct. 30, NOON, 12 pm. In addition to the 2 points, we have an extra credit of 0.5 to implement a recursive method, printcombinations. Note: Make sure your console output is exactly the same as the output in this instruction. Otherwise, you may get 0.1 point off. Overall goal: in this assignment, you are asked to read a file, which contains a 2D array. Then, write a recursive method to find the max value of the array. Then (optional, extra credit), please write a recursive program that outputs all combinations of each subarray in order. For example, a b 1 2 d if the 2D array is: Then, the extra credit method needs to output: a 1 d a 2 d b 1 d b 2 d We will split this assignment into three parts. Each part is accomplished by a method. method 1. readfile: this method is to read an input file and initialize the 2D array method 2. findmax: this method is to find the max int number from a 2D array method 3. printcombinations: this method prints all the combinations of each subarray in order. Before these steps, first, let s create a Java project. Then, create a Main class and a main method (just like what you did in the beginning of assignment13, assignment14, and assignment15 J). Go to the GitHub repository for assignment17, there is an input file, called: 2D.txt You can download the file OR create a file in your project and copy the content of input.txt to your local file. After this setup, you should have a Main class and a main method in your project, and a txt file, input.txt 1

Step 1. Read the input file We can start from the first method, readfile. The input parameter is String filename, which specifies a file. This method should return a 2D array. In this assignment, we are going to use FileInputStream and Scanner to read the file. These classes throw FileNotFoundExceptionand. we are going to use throws clause in the method signature. So, the method signature should look like: Shortcut-Note: Let s assume the input file has only three lines. Hint: we can get a line by the nextline() method of class Scanner. To split the string by space, we can use split method. For example, if we have a String variable, str. Suppose str is a b c. Then str.split( ) will return a String array that has { a, b, c }. After finishing this method, you can call this method in the main method with 2D.txt. The method call should look like the following. Please use System.out.println and System.out.print prints the array (returned by the method call). You need to use try-catch block to catch the FileNotFoundExceptionand that readfile throws. Inside the catch block, System.out.println the message of the exception and call System.exit(1) to exit the program once we catch an IOException from readfile. Run the main method, and the console output should look like the following picture. Change the input of the method call to input2.txt, and run the main method. The console output should look like the following picture. In the main method, change the input2.txt back to 2D.txt. Step 2. findmax The next step is to create a recursive method, findmax. The input for this method is a 2D array, and a row index. The return type is a String. So, the method signature **should** look like this: 2

In the main method, if we call findmax with the array returned by readfile, and a row index of 0, like the following picture: The findmax should return an int value of 11. System.out.println the result, and run the main method, then the console should have the following output. [Extra credit: 0.5] Step 3. printcombinations The next step is to create a recursive method, printcombinations. The input for this method is a temporary string, an int index, a 2D array. The return type is a String. So, the method signature looks like this (this is the method signature for the solution, if you can create a recursive method that has the same output, the input parameter list can be different.): After finishing the printcombinations method, this method should be called in the main method, like the following picture. Run the main method, the console should have the following output. 3

4

5

<End> 6