CS 180 Final Exam Review 12/(11, 12)/08

Similar documents
Contents Chapter 1 Introduction to Programming and the Java Language

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

Introduction to Programming Using Java (98-388)

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

Mathematics/Science Department Kirkwood Community College. Course Syllabus. Computer Science CSC142 1/10

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

JAVA MOCK TEST JAVA MOCK TEST II

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Table of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

Casting -Allows a narrowing assignment by asking the Java compiler to "trust us"

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

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

Do not turn to the next page until the start of the exam.

Do not turn to the next page until the start of the exam.

CSC Java Programming, Fall Java Data Types and Control Constructs

Arrays Classes & Methods, Inheritance

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

CS180 Review. Recitation Week 15

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

SELF-STUDY. Glossary

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Java Just in Time: Collected concepts after chapter 22


Midterm assessment - MAKEUP Fall 2010

CMP 326 Midterm Fall 2015

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

Index COPYRIGHTED MATERIAL

Core Java Contents. Duration: 25 Hours (1 Month)

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

Final Exam CS 251, Intermediate Programming December 13, 2017

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068

CSE Lab 8 Assignment Note: This is the last lab for CSE 1341

1 Shyam sir JAVA Notes

Objective Questions. BCA Part III Paper XIX (Java Programming) page 1 of 5

CS Exam 1 Review Suggestions

Training topic: OCPJP (Oracle certified professional Java programmer) or SCJP (Sun certified Java programmer) Content and Objectives

Language Features. 1. The primitive types int, double, and boolean are part of the AP

Review sheet for Final Exam (List of objectives for this course)

COURSE DESCRIPTION. John Lewis and William Loftus; Java: Software Solutions; Addison Wesley

15CS45 : OBJECT ORIENTED CONCEPTS

We are on the GUI fast track path

JAVA REVIEW cs2420 Introduction to Algorithms and Data Structures Spring 2015

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Java Just in Time: Collected concepts after chapter 18

Come & Join Us at VUSTUDENTS.net

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

VALLIAMMAI ENGINEERING COLLEGE

CS 209 Programming in Java #10 Exception Handling

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

C22a: Problem Solving using Recursion

CS 101 Exam 1 Spring 200 Id Name

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

This page intentionally left blank

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015

Java Programming Lecture 6

F1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept

Name Section. CS 21a Introduction to Computing I 1 st Semester Final Exam

Window Interfaces Using Swing Objects

First Name: AITI 2004: Exam 2 July 19, 2004

1 Looping Constructs (4 minutes, 2 points)

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

PROGRAMMING FUNDAMENTALS

RAIK 183H Examination 2 Solution. November 10, 2014

Window Interfaces Using Swing Objects

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

First Name: AITI 2004: Exam 2 July 19, 2004

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Mobile MOUSe JAVA2 FOR PROGRAMMERS ONLINE COURSE OUTLINE

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2014

Announcements. Final exam. Course evaluations. Saturday Dec 15 10:20 am -- 12:20 pm Room: TBA

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

The Islamic University Gaza Department of Electrical & Computer Engineering. Midterm Exam Spring 2012 Computer Programming II (Java) ECOM 2324

Chapter 13 Lab Advanced GUI Applications

The Java language has a wide variety of modifiers, including the following:

CSE 113 A. Announcements - Lab

COP 3330 Final Exam Review

Sample Examination Paper Programming and Software Development

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:

Murach s Beginning Java with Eclipse

CS260 Intro to Java & Android 03.Java Language Basics

SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts

Pace University. Fundamental Concepts of CS121 1

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Inheritance and Interfaces

University of Cape Town ~ Department of Computer Science. Computer Science 1011H/1016S ~ January Exam

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

CO Java SE 8: Fundamentals

RAIK 183H Examination 2 Solution. November 11, 2013

WA1278 Introduction to Java Using Eclipse

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Transcription:

CS 180 Final Exam Review 12/(11, 12)/08

Announcements Final Exam Thursday, 18 th December, 10:20 am 12:20 pm in PHYS 112 Format 30 multiple choice questions 5 programming questions More stress on topics (chap 11 15) covered after exam 2 Recursion Dynamic Data Structures Window Interfaces using Swing Applets and HTML More Swing

Object-Oriented Design Methods Extract functionalities of a program which will be performed multiple times Encapsulation and Information Hiding Classes, Objects, and Polymorphism Covered in more detail later

Primitives int, double, boolean, float, char, etc. These are NOT Objects Can be compared with ==,!=, <=, >=, etc. Wrapper classes for each primitive Why do we need them? Explicit type-casting may need to be done byte short int long float double

Objects and Classes Class variables hold references (the address) to the objects Always compare with the equals() method Do NOT use == to compare objects Assignment operators assign references they do not make separate copies Constructors should be used to initialize class variables Calling methods Need object Static methods Can use class name Cannot access non-static methods/variables inside Pass by value always Keyword: this

Strings Strings are a type of object Also should not be compared with == Important String functions charat indexof substring length Concatenation operator +

Selection Statements Modifies the flow of control of the program if/else construct Must have a boolean condition to check against are strongly recommended, but not necessary for one line statements switch construct Multi-way branch which makes a decision based on a char, byte, short, or int type default case break statement

Repetition statements - Loops for while do-while Beware of - Off-by-one errors Infinite looping Overflow

Arrays Linear collection of data Can hold primitives or class types, but must all be of the same type length tells the number of elements in the array Member, not a method Indexed from 0 to length 1 Multiple dimension arrays Convenient to use for-loops to iterate through members of the array Remember arrays are reference types

Exceptions Use a try/catch/finally block to handle exceptions thrown by a program Use throw statement to notify caller of an error User defined exceptions must extend Exception

File I/O Useful classes FileInputStream, DataInputStream, FileReader, BufferedReader, Scanner, PrintWriter, DataOutputStream, etc. ObjectInputStream, ObjectOutputStream Used to write objects to a file Any object serialized by a stream must implement Serializable Which classes are used to write text and which are used to write binary? Always close files you open

Inheritance and Polymorphism Differences between abstract classes and interfaces Polymorphism can simplify code Extend specific classes from general classes Use protected keyword to protect information and methods Reuse inherited functionality from parent class. Call to base class s constructor is always called at the first line of constructor.

Dynamic Data Structures Inner classes Lists Node class Circularly linked lists Doubly linked lists Trie data structure ( from project 7 ) Java Collections Vector ArrayList LinkedList

Recursion Break down a problem to one or more sub-problems Be concerned only with the current level of recursion Two necessary cases Base case Recursive step

GUI and Event-driven Programming Common classes JFrame JPanel JLabel JMenu, JMenuItem JButton Layouts BorderLaout GridLayout FlowLayout

Challenges

Types Given the following classes, which of the following declarations are valid? public interface I public interface J extends I public interface K public abstract class A public class B extends A implements J, K public class C extends B public class D extends A implements I A a = new B(); B b = new J(); C c = new B(); B b = new C(); I i = new A(); I i = new B(); I i = new D(); K k = new C();

Types Given the following classes, which of the following declarations are valid? public interface I public interface J extends I public interface K public abstract class A public class B extends A implements J, K public class C extends B public class D extends A implements I A a = new B(); B b = new J(); C c = new B(); B b = new C(); I i = new A(); I i = new B(); I i = new D(); K k = new C(); valid B is a subclass of A invalid cannot instantiate interfaces invalid B is the superclass of C valid C is a subclass of B invalid A does not implement I valid A implements J, and J is-a I valid D implements I valid C extends B which implements K

Recursion and Linked Lists Question- A gradebook is made out of the the following Node class. class Node private int[] values; private Node next; public Node(int[] values, Node next) public int[] getvalues() public void setvalues(int[] values) public Node getnext() public void setnext(node next) // these values are sorted in ascending order 1) Each Node contains an array of scores that are within a certain range. 2) The gradebook contains a linked list of the Node class. For example, you may use the 1 st Node to store all the scores in the F range, the 2 nd Node to store all the scores in the D range, the 3 rd Node to store all the scores in the C range, etc.

Recursion and Linked Lists Question continued- Each node represents a non-overlapping group of grade values and each successive Node contains a range of group values greater than the previous Node. Write an efficient method gradeexists(int), which returns true if the grade exists within the Gradebook, and false otherwise. Since the values array is sorted, you should take advantage of this and perform a binary search for the specified value.

Recursion and Linked Lists Approach to the solution: The solution can be broken into two parts: 1. Finding the node which might contain the grade. Since all nodes have non-overlapping ranges (in sorted order) and the arrays in turn are sorted, we only need to compare the range of each node with the given grade. 2. Do binary search on the values in that node.

Recursion and Linked Lists Part 1: public boolean gradeexists(int grade) Node temp = gradebook; while (temp!= null) int[] values = temp.getvalues(); if (grade < values[0]) return false; if (grade >= values[0] && grade <= values[values.length-1]) return binarysearch(values, grade, 0, values.length-1); temp = temp.getnext(); return false;

Recursion and Linked Lists Part 2: private boolean binarysearch(int[] array, int value, int lo, int hi) if (lo > hi) return false; if (lo == hi) return array[lo] == value; int mid = (hi + lo)/2; if (array[mid] == value) return true; else if (array[mid] > value) return binarysearch(array, value, lo, mid-1); else return binarysearch(array, value, mid+1, hi);

Recursion Write a function ispalindrome(string) which takes in a String and returns true if the String is a palindrome, false otherwise. Ignore the case of the letters and skip over blanks when you make the comparison. public boolean ispalindrome(string s)

Recursion Solution: public boolean ispalindrome(string s) if (s == null) return false; if (s.length() <= 1) return true; return ( s.charat(0) == s.charat(s.length()-1) && ispalindrome(s.substring(1, s.length()-1)) ); public static void main(string[] args)... result = ispalindrome(s.tolowercase().replace(, ));

GUI Question: Create a complete Java GUI program that allows the user to enter the text for JLabels, possibly with multiple lines, and then preview them. You should use the following design: Title Enter Text: Label Preview: Text Area Label Preview Button The user can enter text in the text area. Then, when the button is pushed, this text is displayed as a label in the label preview.

GUI - solution public class CH12 extends JFrame implements ActionListener JButton thebutton = new JButton( "Preview" ); JTextArea thetext = new JTextArea(); JLabel thelabel = new JLabel(); public CH12() super( "Label Previewing Program" ); setsize( 400, 200 ); //button in south JPanel apanel = new JPanel(); apanel.add( thebutton ); this.add( "South", apanel ); //label in north apanel = new JPanel(); apanel.add( new JLabel("The Label Previewer") ); this.add( "North", apanel ); JPanel centerpanel = new JPanel( new GridLayout(1,2) ); //text area in center left apanel = new JPanel( new BorderLayout()); apanel.add( "North", new JLabel("Enter Text:") ); thetext.setlinewrap( true ); apanel.add( "Center", thetext ); centerpanel.add( apanel ); //preview label in center right apanel = new JPanel( new BorderLayout()); apanel.add( "North", new JLabel("Label Preview:") ); apanel.add( "Center", thelabel ); centerpanel.add( apanel ); this.add( "Center", centerpanel ); thebutton.addactionlistener( this );

GUI solution contd. public void actionperformed( ActionEvent e ) thelabel.settext( thetext.gettext() ); public static void main( String[] args ) JFrame ch12frame = new CH12(); ch12frame.setvisible( true ); //end of class def

Arrays Write a method which takes in an array of integers and replaces the values of the array with a value c i, where c i is defined as c i = the sum of the numbers in indices 0 i in the incoming array. public void cumulativearray(int[] a)

Arrays Write a method which takes in an array of integers and replaces the values of the array with a value c i, where c i is defined as c i = the sum of the numbers in indices 0 i in the incoming array. public void cumulativearray(int[] a) if (a.length <= 1) return; for (int k=1; k<a.length; k++) a[k] = a[k] + a[k-1];

What is the output? public class A private int x; public static int dostuff() x = 100; x /= 3; x++; return x; public static void main(string[] args) System.out.println(A.doStuff());

What is the output? public class A private int x; public static int dostuff() x = 100; x /= 3; x++; return x; Because this method is static, it does not have access to non-static class variables. This code will not compile because x is nonstatic. public static void main(string[] args) System.out.println(A.doStuff());

Linked Lists Given an appropriate Node class, write a method which removes every other node from the list, starting with the second. public Node removeeveryother(node l)

Linked Lists Given an appropriate Node class, write a method which removes every other node from the list, starting with the second. public Node removeeveryother(node l) Node l1 = l; while (l1!= null && l1.next!= null) l1.next = l1.next.next; l1 = l1.next; return l;

Linked Lists Now write the same method, but recursively. public Node removeeveryother(node l)

Linked Lists Now write the same method, but recursively. public Node removeeveryother(node l) // base case if (l == null l.next == null) return l; // recursive case Node l1 = removeeveryother(l.next.next); l.next = l1; return l;