COMP 401 Midterm. Tuesday, Oct 18, pm-3:15pm. Instructions

Similar documents
CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

CSE 131 Introduction to Computer Science Fall Exam II

Exam Percentage: / 55 = %

Final Exam Practice. Partial credit will be awarded.

CSE 131 Introduction to Computer Science Fall Exam II

Final Exam. COMP Summer I June 26, points

CSE 131 Introduction to Computer Science Fall Final Exam

CSE 131S Introduction to Computer Science Summer SON Exam I

Arrays Classes & Methods, Inheritance

Midterms Save the Dates!

CSE 131 Introduction to Computer Science Fall Exam I

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

More on variables and methods

Final Exam COMP Fall 2004 Dec 16, 2004

CSE 131 Introduction to Computer Science Fall Exam I

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

CSE 131 Introduction to Computer Science Fall Exam II

COMP 524 Spring 2018 Midterm Thursday, March 1

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Full file at

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Midterm Examination

Assignment 5: MyString COP3330 Fall 2017

CS 152 Computer Programming Fundamentals Coding Standards

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

CSE 131 Introduction to Computer Science Fall Exam I

Programming with Java

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

Prelim 2. CS 2110, 5:30 PM, November 17, 2016

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CS-202 Introduction to Object Oriented Programming

printf( Please enter another number: ); scanf( %d, &num2);

Prelim 1. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer. OO Recursion Loop invariants Max Score Grader

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016

Prelim 1. CS 2110, March 15, 2016, 5:30 PM Total Question Name True False. Short Answer

Question: Total Points: Score:

Tutorials. Tutorial every Friday at 11:30 AM in Toldo 204 * discuss the next lab assignment

Computational Expression

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

CSc 328, Spring 2004 Final Examination May 12, 2004

CMPS 134: Computer Science I Fall 2011 Test #1 October 5 Name Dr. McCloskey

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! printed

CS 101 Fall 2006 Midterm 1 Name: ID:

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

Basics of Java Programming

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing.

Getting started with Java

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

BLM2031 Structured Programming. Zeyneb KURT

CS 170 Exam 2. Version: A Fall Name (as in OPUS) (print): Instructions:

Lec 3. Compilers, Debugging, Hello World, and Variables

Fall 2017 CISC124 9/16/2017

CS/ECE 374 Fall Homework 1. Due Tuesday, September 6, 2016 at 8pm

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2010) - All Sections Midterm Examination

CMSC 331 Second Midterm Exam

CS31 Discussion 1E. Jie(Jay) Wang Week5 Oct.27

Prelim 1. CS 2110, March 15, 2016, 7:30 PM Total Question Name True False. Short Answer

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CS Operating system

PROGRAMMING STYLE. Fundamentals of Computer Science I

Welcome to CompSci 201

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

University of Massachusetts Amherst, Electrical and Computer Engineering

CIS Introduction to Computer Programming Spring Exam 1

Lab # 2. For today s lab:

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

There are several files including the start of a unit test and the method stubs in MindNumber.java. Here is a preview of what you will do:

Computer Science Spring 98 Midterm Examination Professor L. Rowe

QUIZ: What value is stored in a after this

Chapter 1 Introduction to java

ASSIGNMENT 2. COMP-202A, Fall 2013, All Sections. Due: October 20 th, 2013 (23:59)

CS 1322 Test 2 - Version 1 Tuesday June 24 th

Prelim 1. CS 2110, 13 March 2018, 5:30 PM Total Question Name Short answer

gcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world

COE318 Lecture Notes Week 5 (Oct 3, 2011)

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

CMPSCI 187 / Spring 2015 Hangman

Midterms Save the Dates!

Prelim 1. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

CS Exam 1 Review Suggestions

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

CS164: Final Exam. Fall 2003

CS100J February 13, 2001

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Key Differences Between Python and Java

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

CS100J April 17, 2001

CS 113 PRACTICE FINAL

CS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12

CS 142 Style Guide Grading and Details

Introduction to Computing II (ITI 1121) Final Examination

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Using C++, design an Abstract Data Type class named MyGrades. The class must have the following private members :

CS 101 Fall 2005 Midterm 2 Name: ID:

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Oct Decision Structures cont d

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

Algorithms and Programming I. Lecture#12 Spring 2015

Transcription:

COMP 401 Midterm Tuesday, Oct 18, 2016 2pm-3:15pm Instructions 1. Please spread out and try and sit in alternate seats. 2. This is a closed book exam. 3. You will not be penalized for errors in Java syntax. 4. Write on the exam itself. Write on a blank page if there is not enough space to solve a problem. 5. There are: 5 numbered pages including this one and any marked blank pages. 3 questions. 75 possible points. Point values appear in brackets next to each question. 6. You are not required to comment or annotate any code you write, but may get partial credit if you write appropriate comments/annotations but incorrect code. 7. If you need to make any assumptions to clarify a problem, write your assumptions down. Only reasonable assumptions get full credit. 8. Please inform the proctor of anything in the exam that you think is a mistake. 9. Your code will be evaluated not only for correctness, but also for time and space efficiency and style. 10. You cannot use any Java capabilities not covered in class. 11. To answer questions about some piece of code given here, you can mark the code directly. 12. If you do not understand some English word, do not hesitate to ask the proctor. Naturally, you are expected to know the computer science terms defined in class. 13. Write clearly using a pen/pencil with a dark color we will be scanning your exams. 14. Please try and write in the allocated space, as that will reduce mistakes in grading of scanned exams. 15. Put your initials/onyen in the header of each page, in case the pages are separated. NAME, ONYEN, and EMAIL if it is not onyen@live.unc.edu (ALL CAPITALS PLEASE) (NAME) (ONYEN) EMAIL Pledge: I have neither given nor received unauthorized aid on this exam. (signed) For survey purposes, please indicate the time at which you turned in the exam. Please do not write below 1. /47 2. /18 3. /10 Total: / 75

1. [47 pts.] REPLACING SPACE CHARACTERS WITH UNDERSCORES Write a class, ASpaceReplacer, that fulfills the requirements below. You can define other types and refer to them in your class. The requirements for ASpaceReplacer are that it: 1. Implements a method named replacementchar, which takes a parameter of type char. If the parameter is a space ( ), it returns an underscore ( _ ). Otherwise it returns the parameter. The method has default rather than public access. 2. Implements a method named replacementstring, which takes a string as a parameter and returns a copy of this string with each space replaced with an underscore. It has default access. 3. Provides an editable String property, Input; and a read only String property, Output. 4. Provides constructor that takes a String parameter defining the initial value of Input. 5. Makes sure that the value of the Output property is aways a copy of the Input property with each space replaced with an underscore. Thus, if Input is: "H e L Lo 1!", Output is: "H_e_L_Lo_1! ". 6. Makes sure that the getters of the two properties do not do any scanning, directly or by calling other methods. All methods in the class are instance methods. The relevant String instance methods you should use are: public char charat(int index) //Returns the char value at the specified index. public int length()//returns the length of this string. In addition, you need to use the String + operator, which returns a concatenation of its two operands. The constraints given above describe only some of the conditions your code must satisfy. Certain relevant stylistic rules, covered in class, are not explicitly stated. A major part of your grade will depend on how well you apply these rules. In other words, you must adhere to the same requirements that you would if this was a class assignment (with a perfect human grader!), except where explicitly stated otherwise. You can assume all types you define in this exam are in the same package (the default package), and do not need to give any package declaration. You also do not need to give any annotations or comments. Use the last page if you need more space. 2

3

2. [18 pts.] REPLACING LOWERCASE LETTERS WITH UPPERCASE LETTERS (a)[14pts] Write a subclass of ASpaceReplacer, AnUpperCaser, that is like ASpaceReplacer, except that a different character replacement is involved: The value of the Output property is a copy of the Input property with each lowercase letter replaced with the corresponding uppercase letter. Thus, if Input is: "H e L Lo 1!", Output is: " H E L LO 1!". The relevant Character static methods are.: public static boolean islowercase(char ch// Determines if ch is lowercase public static char touppercase(char ch)// Converts ch to uppercase Again, be sure to satisfy these constraints while following relevant stylistic rules, covered in class, not explicitly stated. (It might help you to realize that if m1() and m2() are instance methods in a class, then the call, m2(), by m1() is really the call this.m2(), where this is the object on which m1() is called. For example, the call, replacementstring(), is really the call, this. replacementstring(). Recall also that which implementation of m2() is called can depend on the class of this. If this hint confuses you, ignore it!) You can get points for this question even if you do not attempt problem 1 as long as you state the assumptions you make about the implementation of ASpaceReplacer. If this class declares a method that is a variation of a method in the superclass, you can describe how the declared method is different rather than giving the code of the entire method. You must, however, give the header of each method declared in this class. Use the last page if the space below is not enough. 4

(b)[4pts] Explain whether it makes logical sense for AnUpperCaser to be a subclass of ASpaceReplacer. 3. [10 pts.] MAIN USER OF THE TWO CLASSES Complete the main method below by using the two classes above to convert the value of astring, "H e L Lo 1!", to the replacement strings "H_e_L_Lo_1! " and " H E L LO 1!". The two results should be printed on the console. You can create additional variables to perform the replacements. This question is intended to help you demonstrate your ability to use the two classes correctly, following style rules you have learned in class. You can get points for this question even if you do not attempt problems 1 and 2. public class CharacterReplacerUser { public static void main(string[] args) { String astring = "H e L Lo 1!"; 5