3 length + 23 size = 2



Similar documents
J a v a Quiz (Unit 3, Test 0 Practice)

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

Quick Reference ebook

CS 103X: Discrete Structures Homework Assignment 3 Solutions

Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test

Moving from CS 61A Scheme to CS 61B Java

Paramedic Program Pre-Admission Mathematics Test Study Guide

Java Basics: Data Types, Variables, and Loops

12-6 Write a recursive definition of a valid Java identifier (see chapter 2).

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

How do you compare numbers? On a number line, larger numbers are to the right and smaller numbers are to the left.

Course Syllabus. MATH 1350-Mathematics for Teachers I. Revision Date: 8/15/2016

3.1. RATIONAL EXPRESSIONS

Fraction Vocabulary. It is important that vocabulary terms are taught to students.

Grade 7/8 Math Circles Fall 2012 Factors and Primes

AP Computer Science Java Subset

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

NEW MEXICO Grade 6 MATHEMATICS STANDARDS

Example of a Java program

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

Topic 11 Scanner object, conditional execution

Numerator Denominator

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Multiplying Binomials and Factoring Trinomials Using Algebra Tiles and Generic Rectangles

PREPARATION FOR MATH TESTING at CityLab Academy

8 Divisibility and prime numbers

Number of Divisors. Terms. Factors, prime factorization, exponents, Materials. Transparencies Activity Sheets Calculators

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Math 0980 Chapter Objectives. Chapter 1: Introduction to Algebra: The Integers.

The C Programming Language course syllabus associate level

Using Algebra Tiles for Adding/Subtracting Integers and to Solve 2-step Equations Grade 7 By Rich Butera

Contents. 9-1 Copyright (c) N. Afshartous

YOU CAN COUNT ON NUMBER LINES

PROPERTIES OF ELLIPTIC CURVES AND THEIR USE IN FACTORING LARGE NUMBERS

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Sample CSE8A midterm Multiple Choice (circle one)

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Chapter 3. Input and output. 3.1 The System class

Unit 6. Loop statements

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Grades 7-8 Mathematics Training Test Answer Key

Copy in your notebook: Add an example of each term with the symbols used in algebra 2 if there are any.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

MATH-0910 Review Concepts (Haugen)

Florida Math for College Readiness

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

The Euclidean Algorithm

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Common Core Standards for Fantasy Sports Worksheets. Page 1

of surface, , , of triangle, 548 Associative Property of addition, 12, 331 of multiplication, 18, 433

An Introduction to Number Theory Prime Numbers and Their Applications.

Integer Operations. Overview. Grade 7 Mathematics, Quarter 1, Unit 1.1. Number of Instructional Days: 15 (1 day = 45 minutes) Essential Questions

Answer: Quantity A is greater. Quantity A: Quantity B:

Programming in Java Course Technology, a part of Cengage Learning.

SECTION P.5 Factoring Polynomials

Polynomial and Synthetic Division. Long Division of Polynomials. Example 1. 6x 2 7x 2 x 2) 19x 2 16x 4 6x3 12x 2 7x 2 16x 7x 2 14x. 2x 4.

Recursion and Dynamic Programming. Biostatistics 615/815 Lecture 5

CS170 Lab 11 Abstract Data Types & Objects

s = s = s =

Chapter 1. Computation theory

Microsoft Access 3: Understanding and Creating Queries

Decision-making Computer Science Lesson to Prepare for UIL Computer Science Contest

MACM 101 Discrete Mathematics I

8 Primes and Modular Arithmetic

Acing Math (One Deck At A Time!): A Collection of Math Games. Table of Contents

Answer Key for California State Standards: Algebra I

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Determinants can be used to solve a linear system of equations using Cramer s Rule.

Java Interview Questions and Answers

Building Java Programs

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

GRADE 6 MATH: SHARE MY CANDY

Vocabulary Cards and Word Walls Revised: June 29, 2011

Java Program Coding Standards Programming for Information Technology

Grade 5 Mathematics Curriculum Guideline Scott Foresman - Addison Wesley Chapter 1: Place, Value, Adding, and Subtracting

The following program is aiming to extract from a simple text file an analysis of the content such as:

Programmierpraktikum

AP Computer Science Java Mr. Clausen Program 9A, 9B

z 0 and y even had the form

Grade 6 Math Circles March 10/11, 2015 Prime Time Solutions

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

3 cups ¾ ½ ¼ 2 cups ¾ ½ ¼. 1 cup ¾ ½ ¼. 1 cup. 1 cup ¾ ½ ¼ ¾ ½ ¼. 1 cup. 1 cup ¾ ½ ¼ ¾ ½ ¼

Chapter 4, Arithmetic in F [x] Polynomial arithmetic and the division algorithm.

Solve addition and subtraction word problems, and add and subtract within 10, e.g., by using objects or drawings to represent the problem.

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

CS/COE

PostgreSQL Functions By Example

Grundlæggende Programmering IT-C, Forår Written exam in Introductory Programming

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

MAT Program Verication: Exercises

A Short Guide to Significant Figures

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Math: Essentials+ (GN105A) 4 Credit Hours Spring 2015

Curriculum Map. Discipline: Computer Science Course: C++

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

MATH 90 CHAPTER 1 Name:.

Transcription:

This pledged exam is closed textbook, open class web site, and two pieces of paper with notes. You may not access any other code or websites including your own. Write your email id and name on every page of the test. The only window to be open on your computer is a single browser. Whenever you are writing a message method as your answer to an exercise, there is a grading preference for the use of the this variable and inspectors and mutators when appropriate. Pledge: Warm up 1. Write a complete program Shoe.java that prompts its user for the length of the user s foot in centimeters. The program reports the person s metric shoe size. Metric shoe size can be approximated as follows: 3 length + 23 size = 2, are the mathematical symbols for casting a decimal value to an integer. The following where demonstrates a sample run. Enter foot length (centimeters): 29.5 Metric shoe size: 39 import java.util.*; public class Shoe { public static void main( String[] args ) { Page 1 of 14

2. Suppose x and y are initialized object variables of the same type (e.g., they are both Color variables). Complete the initialization of boolean variable b so that it indicates whether x and y reference the same object. boolean b = ; 3. Suppose x and y are initialized object variables of the same type (e.g., they are both Color variables). Complete the initialization of boolean variable b so that it indicates whether x and y reference objects with like attributes. boolean b = ; Adding functionality to existing classes 4. Define a void message method absolute() that is to be part of the class Calculator. The method updates the total of its calculator to its absolute value. The following code segment demonstrates its usage. Calculator c = new Calculator(); c.add( -7 ); // running total is now -7 c.absolute(); // running total is now 7 public void absolute() { 5. Define a void message method square() that is to be part of the class Calculator. The method updates the total of its calculator to be the square of its current value. The following code segment demonstrates its usage. Calculator c = new Calculator(); c.add( 7 ); // running total is now 7 c.square(); // running total is now 49 public void square() { Page 2 of 14

6. Define a Rational message method invert() that is to be part of the class Rational. The method returns a new Rational that is a flipping of its rational; i.e., its numerator becomes the new Rational s denominator and its denominator becomes the new Rational s numerator. The following code segment demonstrates its usage. Rational a = new Rational( 3, 5 ); // a is 3 / 5 Rational b = a.invert(); // b is 5 / 3 public Rational invert() { 7. Define a void message method reduce() that is to be part of the class Rational. The method takes one int parameter v. If v is a factor of both its numerator and the denominator, then the method divides both of them by v. If instead v is not a common factor, then no changes are made to its numerator and denominator. The following code segment demonstrates its usage. Rational a = new Rational( 6, 9 ); // a is 6 / 9 a.reduce( 7 ); // a is 6 / 9 as 7 is not a common factor a.reduce( 3 ); // a is 2 / 3 as 3 is a common factor public void reduce( int v ) { Page 3 of 14

8. Define a void message method swap() that is to be part of the class Rational. The method takes one Rational parameter r. The method swaps the numerator and denominator of its rational with Rational r. The following code segment demonstrates its usage. Rational a = new Rational( 6, 9 ); // a is 6 / 9 Rational b = new Rational( 3, 4 ); // b is 3 / 4 a.swap( b ); // a is 3 / 4 and b is 6 / 9 public void swap( Rational r ) { 9. Define a boolean message method isolderthan() that is to be part of the class Song. The method takes one Song parameter s and returns whether its song has an earlier recording year than Song s. The following code segment demonstrates its usage. Song s1 = new Song( n1, p1, y1 ); Song s2 = new Song( n2, p2, y2 ); boolean b = s1.isolder( s2 ); // is s1 recorded earlier than s2 public boolean isolderthan( Song s ) { Page 4 of 14

10. Define a boolean message method atmorethan() that is to be part of the class Movie. The method takes one Movie parameter m and returns whether its movie is playing at more theaters than Movie m. The following code segment demonstrates its usage. Movie m1 = new Movie( "Water for Elephants" ); Movie m2 = new Movie( "Thor" );... boolean b = m1.atmorethan( m2 ); // is m1 at more theaters than m2 public boolean atmorethan( Movie m ) { Library methods 11. Write an int library method factorial() that takes one int parameter n. The loop- based method returns n!; i.e., 1 * 2 * 3 * * n. The following code segment demonstrates its usage. int v = factorial( 5 ); // v is 120; i.e., 1 * 2 * 3 * 4 * 5 public static int factorial( int n ) { Page 5 of 14

12. Write an int library method choose() that takes two int parameter n and k. The method returns n! / (k! * (n - k)! ) The following code segment demonstrates its usage. int a = choose( 2, 2 ); // is 1 int b = choose( 3, 2 ); // is 3 int c = choose( 4, 2 ); // is 6 public static int choose( int n, int k ) { 13. Write a recursive int library method gcd() that takes two int parameter x and y and returns their greatest common divisor. If y is zero, the greatest common divisor of x and y equals x. If y is not zero, the greatest common divisor of x and y equals the greatest common divisor of y and r, where r is the remainder of x divided by y. The following code segment demonstrates its usage. int n = gcd( 72, 54 ); // is 18 public static int gcd( int x, int y ) { Page 6 of 14

14. Write a recursive int library method choose() that takes two int parameter n and k and returns the number of ways subsets of size k can be made from a set of size n. If k is 0, then the number of ways of making the subsets is 1. Otherwise, if n is 0, then the number of ways of making the subsets is 0; Otherwise, the number of ways of making the subsets is the sum of two quantities: o o The number of ways subsets of size k 1 can be made from a set of size n 1; The number of ways subsets of size k can be made from a set of size n 1. The following code segment demonstrates its usage. int a = choose( 2, 2 ); // is 1 int b = choose( 3, 2 ); // is 3 int c = choose( 4, 2 ); // is 6 public static int choose( int n, int k ) { Library methods for array manipulation 15. Write an int library method product() that takes one int[] parameter x. The method returns the product of the element values. The following code segment demonstrates its usage. int[] a = { 3, 1, 4, 1, 5, 9 }; int p = product( a ); // p is 540; i.e., 3 * 1 * 4 * 1 * 5 * 9 public static int product( int[] x ) { Page 7 of 14

16. Write a boolean library method gotit() that takes a single int[] parameter x and one int parameter v. The method returns whether any of the elements in x are equal to v. The following code segment demonstrates its usage. int[] a = { 3, 1, 4, 1, 5, 9 }; boolean b1 = gotit( a, 4 ); // b1 is true, because x has a 4 boolean b2 = gotit( a, 8 ); // b2 is false, because x does not have a 8 public static boolean gotit( int[] x, int v ) { 17. Write a boolean library method isincreasing() that takes a single int[] parameter x. The method returns whether the element values for array x are in strictly increasing order. int[] a = { 3, 1, 4 }; int[] b = { 1, 3, 3, 4 } int[] c = { 1, 3, 4, 5, 9 }; boolean b1 = isincreasing( a ); // is false as 3 >= 1 boolean b2 = isincreasing( b ); // is false as 3 >= 3 boolean b3 = isincreasing( c ); // is true as 1 < 3 < 4 < 5 < 9 public static boolean isincreasing( int[] x ) { Page 8 of 14

18. Write a int[] library method glue() that takes a two int[] parameters x and y (the arrays can have different numbers of elements). The method returns a new int[] array whose length is the sum of the lengths of arrays x and y. The initial elements in the new array are to come from x and the remaining elements are to come from y. Suggestion: use two while loops. int[] a = { 3, 1, 4 }; int[] b = { 1, 5, 9, 2 }; int[] c = glue( a, b ); // c is 3, 1, 4, 1, 5, 9, 2 public static int[] glue( int[] x, int[] y ) { 19. Write an int library method count() that takes one int[][] parameter x and one int parameter v. The method returns the number of elements in the two- dimensional array that equal v. The following code segment demonstrates its usage. int[][] a = { { 3, 1, 4, 1 }, { 5, 9, 2, 6 } }; int n1 = count( x, 1 ); // n1 becomes 2 int n2 = count( x, 12 ); // n2 becomes 0 public static int count( int[][] x, int v ) { Page 9 of 14

Class Pixel implementation see handout for specification 22. public static boolean legallevel( int n ) { 23. public Pixel() { 24. public Pixel( int r, int g, int b ) { 25. public Pixel( int n ) { Page 10 of 14

26. public void setred( int r ) { 27. public void setgreen( int g ) { 28. public void setblue( int b ) { 29. public void setrgb( int r, int g, int b ) { 30. public int getred() { Page 11 of 14

31. public int getgreen() { 32. public int getblue() { 33. public Color tocolor() { 34. public int toint() { 35. public boolean samered( Pixel p ) { Page 12 of 14

36. public boolean samegreen( Pixel p ) { 37. public boolean sameblue( Pixel p ) { 38. public boolean same( Pixel p ) { 39. public Pixel clone() { Page 13 of 14

40. public String tostring() { 20. True or false True False I am part of the class picture. True False Since the last test I have attended every class or had an excused absence. True False I did the Collab survey for this class. True False I did the exit survey for this class. Page 1 / 12 Page 8 / 8 Page 2 / 16 Page 9 / 8 Page 3 / 8 Page 10 / 12 Page 4 / 8 Page 11 / 15 Page 5 / 8 Page 12 / 15 Page 6 / 8 Page 13 / 12 Page 7 / 8 Page 14 / 5 / 143 Page 14 of 14