CSCI 160 Midterm Review Rasanjalee DM.

Slides:



Advertisements
Similar presentations
Introduction to Programming G51PRG University of Nottingham Revision 1
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Classes, Encapsulation, Methods and Constructors (Continued) Class definitions Instance data Encapsulation and Java modifiers Method declaration and.
C Programming Day 1 based upon Practical C Programming by Steve Oualline CS550 Operating Systems.
Constructors & An Introduction to Methods. Defining Constructor – Car Example Public class car { String Model; double speed; String colour; { Public Car.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
Classes and Objects: Recap A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Declaring Variables You must first declare a variable before you can use it! Declaring involves: – Establishing the variable’s spot in memory – Specifying.
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
Copyright 2006 by Pearson Education 1 reading: 4.1 Cumulative sum.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
CS102--Object Oriented Programming Review 1: Chapter 1 – Chapter 7 Copyright © 2008 Xiaoyan Li.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
Chapter 7: User-Defined Methods
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
Hello, world! Dissect HelloWorld.java Compile it Run it.
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
Introduction to Object-Oriented Programming
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
The Java Programming Language
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
A First Simple Program /* This is a simple Java program. Call this file "Example.java".*/ class Example { // Your program begins with a call to main().
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Introduction to Java Java Translation Program Structure
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Copyright Curt Hill Variables What are they? Why do we need them?
Chapter 2 topics Concept # on Java Subset Required for AP Exam print and println10. Testing of output is restricted to System.out.print and System.out.println.
Java methods Methods break down large problems into smaller ones Your program may call the same method many times saves writing and maintaining same code.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
Classes - Intermediate
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Methods.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Eastside Robotics Alliance / Newport Robotics Group 1 T/Th, 6:30 – 8:30 PM Big Picture School Day 3 · 10/9/2014.
C++ Lesson 1.
Information and Computer Sciences University of Hawaii, Manoa
The need for Programming Languages
JAVA MULTIPLE CHOICE QUESTION.
3 Introduction to Classes and Objects.
Yanal Alahmad Java Workshop Yanal Alahmad
User-Defined Classes and ADTs
Java Programming with BlueJ
An Introduction to Java – Part I, language basics
Classes, Encapsulation, Methods and Constructors (Continued)
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Simple Classes in Java CSCI 392 Classes – Part 1.
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Introduction to Object-Oriented Programming
In this class, we will cover:
Methods/Functions.
Introduction to java Part I By Shenglan Zhang.
Corresponds with Chapter 5
Presentation transcript:

CSCI 160 Midterm Review Rasanjalee DM

Multiple Choice Questions

Question The Java compiler translates Java programs into machine language programs. TRUE FALSE

Answer The Java compiler translates Java programs into machine language programs. [FALSE]

Question System.out is an example of a method. TRUE FALSE

Answer System.out is an example of a method. TRUE FALSE [FALSE]

Question ice-cream is an illegal identifier in Java. TRUE FALSE

Answer ice-cream is an illegal identifier in Java. TRUE FALSE [TRUE]

Question Constructors have return type void. TRUE FALSE

Answer Constructors have return type void. TRUE FALSE [FALSE]

Fill in the Blanks

Questions Every variable in Java must be __________ before it is used. Single quotes are used with constants of the __________ type.

Answers Every variable in Java must be __________ before it is used. [declared] 2. Single quotes are used with constants of the __________ type. [char]

Questions A(n) __________ is used for signaling the end of the input. A(n) __________ is an action that an object can take and is specified in the class definition. Compiling a file called Game.java will produce a file called __________.

Answers A(n) __________ is used for signaling the end of the input. [sentinel value] A(n) __________ is an action that an object can take and is specified in the class definition. [method] Compiling a file called Game.java will produce a file called __________. [Game.class]

Question A(n) __________ is a data item that belongs to an object. __________ is the word used to say that there are no restrictions on the use of a method or data item can be used. The reserved word __________ can be used as a name for the calling the current object.

Answer A(n) __________ is a data item that belongs to an object. [instance variable] 4. __________ is the word used to say that there are no restrictions on the use of a method or data item can be used. [public] 5. The reserved word __________ can be used as a name for the calling object. [this]

Short Answer Questions

Question Add parentheses to the following expressions to indicate how Java will interpret them. (a) a * b * c - d / e (b) a + - b * c - d

Answer ((a * b) * c) - (d / e) (a + ((-b) * c)) - d

Question After the following statements have been executed, how many Fraction objects will exist, not counting garbage objects? Fraction f1 = new Fraction(1, 2); Fraction f2 = new Fraction(3, 5); Fraction f3 = f2;f2 = null;f1 = f2;

Answer One

Question Answer the questions below about this class. What are the names of the instance variables declared in this class? What are the signatures of the constructors declared in this class? What are the names of the parameters declared in this class? What are the signatures of the methods declared in this class? e) What are the names of the constants declared in this class?

Answer Answer the questions below about this class. What are the names of the instance variables declared in this class? name, slalomPoints, giantSlalomPoints, superGPoints, ussaNumber b) What are the signatures of the constructors declared in this class? public Skier (String name, String ussaNumber) c) What are the names of the parameters declared in this class? name, ussaNumber What are the signatures of the methods declared in this class? public String getBestEvent() e) What are the names of the constants declared in this class? MAXIMUM_POINTS

Code Analysis

Question What does the following program print? int[] arr = {1, 1, 0, 0, 0}; for (int i = 2; i < arr.length; i++) arr[i] = arr[i-1] + arr[i-2];

Answer What does the following program print? 11235 index = 0 1 2 3 4 int[] arr = {1, 1, 0, 0, 0}; for (int i = 2; i < arr.length; i++) arr[i] = arr[i-1] + arr[i-2]; i arr[i-1] arr[i-2] arr[i] arr 2 1 1 1+1 =2 11200 3 2 1 2+1 =3 11230 4 3 2 2+3 = 5 11235

Question Show the EXACT output the following programs generate: public class e21 { public static void main (String args[]) { int num = 4; printNumbers(num); } private static void printNumbers(int n) { for (int i=1; i <= n; i++) { for (int k=1; k <= 2*(i-1)+1; k++) System.out.print(i); System.out.println();

Answer 1 222 33333 4444444

Write Java Code

Question Write one line java statement declaring and creating a 1-d double array that stores whether or not precipitation was recorded on each day of one (non-leap year)

Answer boolean[] precipRecord = new boolean[365];

Question Write a one-line java statement declaring and creating a 2-d array named matrix with 24 rows and 80 columns.

Answer double[][] matrix = new double[24][80];

Question Write 1 or more java statements to display all the elements of the last column of the 2-d array matrix from the previous part

Answer for(int i=0; i<matrix.length; i++) System.out.println(matrix[i][79]);

Question Write 1 or more java statements to compute and print the product of all the elements in the second row of the 2-d array matrix

Answer double product = 1 for(int i=0; i<matrix.length; i++) { product *= matrix[1][i]; } System.out.println(product);

Question Write 1 or more java statements to compute and print the number of upper case characters in a saying (stored in variable saying)

Answer int upper= 0; for(int i=0;i<saying.length;i++) { if(saying.charAt(i)>=‘A’ && saying.charAt(i)<=‘Z’) upper+; } System.out.println(upper);

Question Write a method named toBinary that accepts an integer as a parameter and returns a string of that number's representation in binary. For example, the call of toBinary(42) should return "101010". We will assume a positive parameter.

Answer private static String toBinary(int num) { if (num == 0) return "0"; String str=""; while (num != 0) str = (num%2)+str; num /= 2; } return str;