COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
|
|
- Gabriel Taylor
- 6 years ago
- Views:
Transcription
1 COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
2 COSC 236 Web Site You will always find the course material at: or or From this site you can click on the COSC-236 tab to download the PowerPoint lectures, the Quiz solutions and the Laboratory assignments. 2
3 3
4 Review of Quiz 12 Quiz 12: You are to write a method that calculates the arithmetic mean (i.e.: average = sum of data items divided by the number of items) and the geometric mean (i.e.: the n-th root of the product of the data items where n is the number of data items). The key points being tested in Quiz 12 are your ability to use cumulative techniques introduced in Lecture 11 to find the sum and product of a series of data items. Fill in the missing code below, place the entire program (class) into DrJava, compile and run the code and show your result to Prof. Soderstrand: import java.util.*; // for Scanner public class Quiz12 { public static void main(string[] args) { Scanner console = new Scanner(System.in); System.out.print("How many data items to you wish to process? "); int number = console.nextint(); System.out.println(); processdata(console, number); public static void processdata(scanner console, int number) { System.out.print("Enter " + number); System.out.print(" data items (double or integer) "); System.out.print("separated by spaces: "); double temp; double sum = 0; double product = 1; Place your code here! double arithmeticmean = sum/number; double geometricmean = Math.pow(product, 1.0/number); System.out.print("The arithmetic mean is " + arithmeticmean); System.out.println(" and the geometric mean is " + geometricmean); 4
5 Review of Quiz 12 The key points to understand from Quiz 12 are as follows: 1. Reading Scanner object input from the console in a for loop: console.nextdouble() 2. Algorithm for finding the sum of a set of data points: double sum = 0; for (i = 1; i <= number; i++) { temp = console.nextdouble(); sum = sum + temp; 3. Algorithm for finding the product of a set of data points: double product = 1; for (i = 1; i <= number; i++) { temp = console.nextdouble(); product = product * temp; 5
6 Review of Quiz 12 The key points to understand from Quiz 12 are as follows: 4. Combining the two loops into a single loop: double sum = 0; double product = 1; for (i = 1; i <= number; i++) { temp = console.nextdouble(); sum = sum + temp; product = product * temp; 6
7 Review of Quiz 12 7
8 Review of Quiz 02 8
9 Review of Quiz 02 9
10 Review of Quiz 02 10
11 Review of Quiz 02 11
12 Review of Quiz 02 PROBLEM: The tab character \t in output moves the cursor to the next tab stop on the output console. The default setting for tab stops on the DrJava console is 8 spaces. Two tab characters are required after the Gold Ring 12
13 Review What is the output of the following println statements? System.out.println("\ta\tb\tc"); a b c System.out.println("\\\\"); \\ System.out.println("'"); ' System.out.println("\"\"\""); """ System.out.println("C:\nin\the downward spiral"); C: in he downward spiral 13
14 Review Write a println statement to produce the line of output: / \ // \\ /// \\\ System.out.println("/ \\ // \\\\ /// \\\\\\"); 14
15 Review What println statements will generate this output? This program prints a quote from the Gettysburg Address. "Four score and seven years ago, our 'fore fathers' brought forth on this continent a new nation. System.out.println("This program prints a"); System.out.println("quote from the Gettysburg Address."); System.out.println(); System.out.println("\"Four score and seven years ago,"); System.out.println("our 'fore fathers' brought forth on"); System.out.println("this continent a new nation.\""); 15
16 Review What println statements will generate this output? A "quoted" String is 'much' better if you learn the rules of "escape sequences." Also, "" represents an empty String. Don't forget: use \" instead of "! '' is not the same as System.out.println("A \"quoted\" String is"); System.out.println("'much' better if you learn"); System.out.println("the rules of \"escape sequences.\""); System.out.println(); System.out.println("Also, \"\" represents an empty String."); System.out.println("Don't forget: use \\\" instead of \"!"); System.out.println("'' is not the same as \""); 16
17 Review Where to place comments: at the top of each file (a "comment header") at the start of every method (seen in today s lecture) to explain complex pieces of code Comments are useful for: Understanding larger, more complex programs. Multiple programmers working together, who must understand each other's code. 17
18 Review Example of a wellcommented program: /* Suzy Student, CS 101, Fall 2019 This program prints lyrics about... something. */ public class BaWitDaBa { public static void main(string[] args) { // first verse System.out.println("Bawitdaba"); System.out.println("da bang a dang diggy diggy"); System.out.println(); // second verse System.out.println("diggy said the boogy"); System.out.println("said up jump the boogy"); 18
19 Review of Quiz 3 19
20 Review of Quiz 3 20
21 Review of Quiz 4 Horizontal redundancy cannot be eliminated cones(); squares(); us(); 21
22 Review of Quiz 4 cones(); squares(); us(); squares(); cones(); 22
23 Review of Quiz 5 The following is the class Quiz5, the program that calls the five methods that solve the five problems: 23
24 Review of Quiz 5 Problem 1 Write a Java method problem1 that prints out on the console (8 characters per line each separated by a space) the Unicode special characters for HEX 20 through HEX 47. Method problem1 should initialize the char variable x to a space (i.e.: char x = ) and then print five lines to the console containing the special characters (Hint: use the ++ operator no loops are allowed!). The point of this problem was to demonstrate use of the x++ in a print statement and the location of the Unicode characters. 24
25 Review of Quiz 5 Problem 1 OUTPUT: The point of this problem was to demonstrate use of the x++ in a print statement and the location of the Unicode characters. 25
26 Review of Quiz 5 Problem 2 The mod function, %, for integers is fairly easy to understand. It is the remainder when the numerator n is divided by the denominator d. As noted in class, the general form of the mod function, %, is: n%d = (n/d (int)(n/d))*d. In a single println statement, calculate 128 % 33 as integers and compare it to the definition (128.0/33-128/33)*33. In a single println statement, calculate 12.8 % 3.3 and compare it to the definition. In a single println statement, calculate 11.4 % 3 and compare it to the definition. NOTE: The first two lines of your code should print out as follows: n = 128, d = 33, n % d = 29( ) n = 12.8, d = 3.3, n % d = ( ) Why is there a difference between n % d and the definition? The point of this problem was to demonstrate use of the mod function % and the problem with exact numbers in type double. 26
27 Review of Quiz 5 Problem 2 Solution: The simplest solution is to use values, not variables, in the arithmetic operations directly in the print statement. This way you do not need to define any variables or do anything complicated. The point of this problem was to demonstrate use of the mod function % and the problem with exact numbers in type double. 27
28 Review of Quiz 5 Problem 2 Solution: The point of this problem was to demonstrate use of the mod function % and the problem with exact numbers in type double. 28
29 Review of Quiz 5 Problem 3 The point of this problem was to demonstrate use of the pre-increment (++x) and post increment (x++). 29
30 Review of Quiz 5 Problem 4 Write a single println statement that prints the following line (no loops allowed): 3, 9, 27, 81, 243 The point of this problem was to demonstrate use of the *= operator. 30
31 Review of Quiz 5 Problem 5 Set an integer x equal to (int x = 12345;) and then use a single println statement to print each digit out in order with a space in between them ( ). The point of this problem was to demonstrate use of the integer divide by powers of 10 combined with the mod 10 (% 10) operators to isolate individual digits from a decimal integer. 31
32 Review of Loops First standard technique to design a for loop that executes ntimes: for (int i = 1; i <= ntimes; i++) { statements here execute ntimes; { Second standard technique to design a for loop that executes ntimes: for (int i = 0; i < ntimes; i++) { statements here execute ntimes; { 32
33 Review of Loops First nested for loop that prints nlines and ncolumns : for (int i = 1; i <= nlines; i++) { for (int j = 1; j <= ncolumns; j++) { System.out.print("*"); System.out.println(); *********** In this example, *********** *********** nlines = 3 and ncolumns = 10 33
34 Review of Loops Second nested for loop that prints nlines and ncolumns : for (int i = 0; i < nlines; i++) { for (int j = 0; j < ncolumns; j++) { System.out.print("*"); System.out.println(); *********** In this example, *********** *********** nlines = 3 and ncolumns = 10 34
35 Review of Loops First nested for loop that prints nlines triangle: for (int i = 1; i <= nlines; i++) { for (int j = 1; j <= i; j++) { System.out.print("*"); System.out.println(); * In this example, ** *** nlines = 3 35
36 Review of Loops Second nested for loop that prints nlines triangle: for (int i = 0; i < nlines; i++) { for (int j = 0; j <= i; j++) { System.out.print("*"); System.out.println(); * In this example, ** *** nlines = 3 36
37 Review of Loops First nested for loop that prints nlines triangle * extended to square using!: for (int i = 1; i <= nlines; i++) { for (int j = 1; j <= i; j++) { System.out.print("*"); for (int j = i+1; j <= nlines; j++) { System.out.print("!"); System.out.println(); *!! In this example, **! *** nlines = 3 37
38 Review of Loops Second nested for loop that prints nlines triangle * extended to square using!: for (int i = 0; i < nlines; i++) { for (int j = 0; j <= i; j++) { System.out.print("*"); for (int j = i+1; j < nlines; j++) { System.out.print("!"); System.out.println(); *!! In this example, **! *** nlines = 3 38
39 Review of Loops We can double the width of any of these figures by printing two character: for (int i = 0; i < nlines; i++) { for (int j = 0; j <= i; j++) { System.out.print("**"); for (int j = i+1; j < nlines; j++) { System.out.print("!!"); System.out.println(); **!!!! In this example, ****!! ****** nlines = 3 39
40 Review of Quiz 6 40
41 Review of Quiz 6 Line "\\\\ i "!!" 11 2*i "//" i exclamation = a i + b 11 = a 0 + b => b = 11 9 = a 1 + b => a = 9 b = 9 11 = 2 exclamation = 11 2 i 41
42 Review of Quiz 6 Line "\\\\ i "!!" 11 2*i "//" i
43 Review of Quiz 6 43
44 Review of Quiz 7 44
45 Review of Quiz 7 45
46 Review of Quiz 7 46
47 Review of Quiz 7 (Solution for drawline();) public static void drawline() { // Prints top and bottom line System.out.print("#"); for (int i = 1; i <= 4*SIZE; i++) { System.out.print("="); System.out.println("#"); 47
48 Review of Quiz 7 (Solution for bottomhalf();) public static void bottomhalf() { // Prints the contracting pattern of <> for the top half of the figure for (int line = SIZE; line >= 1; line--) { System.out.print(" "); for (int space = 1; space <= (-2 * line + 2*SIZE); space++) { System.out.print(" "); System.out.print("<>"); for (int dot = 1; dot <= (4 * line - 4); dot++) { System.out.print("."); System.out.print("<>"); for (int space = 1; space <= (-2 * line + 2*SIZE); space++) { System.out.print(" "); System.out.println(" "); 48
49 Review of Quiz 8 49
50 Review of Quiz 8 Key items you need to know from this quiz: How to pass parameters from the calling program to the called program How to set up a for loop to count the rows How to set up a for loop to count the columns Where to put the three print statements: System.out.print( ) to print the matrix elements System.out.println() to create new line after each row System.out.println() to create new line after each matrix 50
51 Review of Quiz 8 Main method calls the method matrix with the actual parameters to specify each of the three matrices: public class Quiz8 { public static void main (String[] args){ matrix('a', 3, 4); //Print 3x4 a matrix matrix('b', 5, 5); //Print 5x5 b matrix matrix('c', 4, 3); //Print 4x3 c matrix public static void matrix(char sym, int row, int col) 51
52 Review of Quiz 8 Main method calls the method matrix with the actual parameters to specify each of the three matrices: public class Quiz8 { public static void main (String[] args){ matrix('a', 3, 4); //Print 3x4 a matrix matrix('b', 5, 5); //Print 5x5 b matrix matrix('c', 4, 3); //Print 4x3 c matrix public static void matrix(char sym, int row, int col) 52
53 Review of Quiz 8 Main method calls the method matrix with the actual parameters to specify each of the three matrices: public class Quiz8 { public static void main (String[] args){ matrix('a', 3, 4); //Print 3x4 a matrix matrix('b', 5, 5); //Print 5x5 b matrix matrix('c', 4, 3); //Print 4x3 c matrix public static void matrix(char sym, int row, int col) 53
54 Review of Quiz 8 Main method calls the method matrix with the actual parameters to specify each of the three matrices: Actual Parameters public class Quiz8 { public static void main (String[] args){ matrix('a', 3, 4); //Print 3x4 a matrix matrix('b', 5, 5); //Print 5x5 b matrix matrix('c', 4, 3); //Print 4x3 c matrix Formal Parameters public static void matrix(char sym, int row, int col) 54
55 Review of Quiz 8 The method matrix copies the values of the actual parameters into its formal paramenters: sym, row and col matrix('a', 3, 4); a 3 4 public static void matrix(char sym, int row, int col) { for (int i = 1; i <= row; i++) { //i counts the rows for (int j = 1; j <= col; j++) { //j counts the columns System.out.print(sym + "(" + i + ", " + j + ") "); //NOTE: this ends the printing of one row System.out.println(); //New line after each row //NOTE: this ends the printing of the entire matrix System.out.println(); //New line after each matrix 55
56 Review of Quiz 8 (The entire program) 56
57 Review of Quiz 8 (The printout) 57
58 Quiz 8 (Solution) 58
59 Review of Quiz 9 59
60 Review of Quiz 9 Key items you need to know from this quiz: How to use the Math class objects Math.round(x) Math.pow(y, m) The rest was done for you in the Quiz problem setup Write the method round1(d, n) such that the double d is rounded to n decimal places Use Math.pow(10, n) to multiply d by 10 n bringing the n th decimal digit to the one s place Use Math.round() to round to the one s place Divide by 10 n to restore the n th decimal digit to its right place 60
61 Review of Quiz 9 The key to moving the decimal point to the correct place for rounding and then returning it after rounding: The ability to move the decimal point to the right by multiplying 10 n and to the left by dividing by 10 n. Math.pow(10, n) generates the value 10 n we must multiply d by before we round and then divide the result by to get our final answer. 61
62 Review of Quiz 9 The TWO lines we need to add to the given code are: double scalingfactor = Math.pow(10, n); return Math.round(scalingFactor*d)/scalingFactor; public static double round1(double d, int n) { double scalingfactor = Math.pow(10, n); return Math.round(scalingFactor*d)/scalingFactor; 62
63 Review of Quiz 9 The entire program: public class RoundTest { public static void main(string[] args) { double x = ; System.out.print("x = " + x + ", round(x,0) = " + round1(x,0) + ", round(x,1) = " + round1(x,1)); System.out.print(", round(x,2) = " + round1(x,2) + ", round(x,3) = " + round1(x,3)); System.out.println(", round(x,-1) = " + round1(x,-1) + ", round(x,-2) = " + round1(x,-2)); public static double round1(double d, int n) { double scalingfactor = Math.pow(10, n); return Math.round(scalingFactor*d)/scalingFactor; 63
64 Review of Quiz 9 The entire program including printout: 64
65 Review of Quiz 9 The entire program including printout: The concept of moving the decimal point through multiplication by powers of 10 is a very useful concept and has many applications in computer programming: Recall that in Quiz 5 Problem 5 we were able to select single digits from an integer by the combination of scaling by a power of 10 and using the mod 10 operator (x % 10) to extract the units digit. This is another use of the important concept of moving the decimal point through multiplication by a power of 10. You should review Quiz 5 Problem 5 along with this Quiz in order to fully understand this important concept. 65
66 Review of Quiz 10 66
67 Review of Quiz 10 The key points to understand from Quiz 10 are as follows: 1. The actual parameter in the calling program is a string that will be the prompt printed in the method getinput. 2. The actual parameter from the calling method is copied into the formal parameter (String prompt) in the called method. 3. Thus to print the prompt, the first of the two lines we need is the statement System.out.print(prompt); 4. The statement Scanner console = new Scanner(sytem.in); creates the console object which inherits all the Scanner object method including nextdouble(); 5. Hence, the double value typed by the user on the console can be returned to the calling program with the second statement that we need to provide: 6. The return statement copies the value after the return (in this case the number typed by the user) to a storage location in the computer with the same name as the method: getinput 67
68 Review of Quiz 10 68
69 Review of Quiz 10 69
70 Review of Quiz 11 70
71 Review of Quiz 11 The key points to understand from Quiz 11 are as follows: 1. The actual parameter in the calling program is a string that contains the Scanner input entered by the user. 2. The actual parameter from the calling method is copied into the formal parameter in the called method (this is the text to be reversed). 3. The three key concepts tested in Quiz 11: a. Using String Method.toUpperCase() to convert the text to upper case b. Setting up a for loop to count down from the last character (text.length()-1) to the first character in the string c. Using String Method.charAt(i) or.substring(i, i+1) to access a single character in text and print it out using System.out.print(text.charAt(i)); 71
72 Review of Quiz 11 (using text.charat(i)) 72
73 Review of Quiz 11 (using text.substing(i, i+1)) 73
74 Review of Quiz 11 74
75 Assignments for this week 1. Laboratory for Chapter 4 due today (Monday 10/20) IMPORTANT: When you me your laboratory Word Document, be sure it is all in one file 2. Midterm will be on Monday, 10/13/2014 in class. 3. Complete the take-home portion of the exam before class on Monday 10/13/ your completed take-home to Prof. Soderstrand in ONE Word document (similar to labs) by the beginning of class Monday 10/13/ Be sure to complete Quiz 13 before leaving class tonight This is another program to write You must demonstrate the program to me before you leave lab 75
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us From this site you can click on the COSC-236
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site I hope to have a course web site up on Blackboard soon However, I am using the following site all semester to allow
More informationBuilding Java Programs. Chapter 1: Introduction to Java Programming
Building Java Programs Chapter 1: Introduction to Java Programming Lecture outline Introduction Syllabus and policies What is computer science Programs and programming languages Basic Java programs Output
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com
More informationBuilding Java Programs
Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: 1.1-1.3 self-check: #1-14 exercises: #1-4 What is CSE? Computer Science Study of computation (information processing)
More informationBuilding Java Programs Chapter 1
Building Java Programs Chapter 1 Introduction to Java Programming Copyright (c) Pearson 2013. All rights reserved. What is computer science? Computer Science The study of theoretical foundations of information
More informationIntroduction to Computer Programming
Introduction to Computer Programming Getting Started: An Introduction to Programming in Java What Is Programming? Computers cannot do all the wonderful things that we expect without instructions telling
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us From this site you can click on the COSC-236
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com
More informationCSE 142. Lecture 1 Course Introduction; Basic Java. Portions Copyright 2008 by Pearson Education
CSE 142 Lecture 1 Course Introduction; Basic Java Welcome Today: Course mechanics A little about computer science & engineering (CSE) And how this course relates Java programs that print text 2 Handouts
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us From this site you can click on the COSC-236
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site I have decided to keep this site for the whole semester I still hope to have blackboard up and running, but you
More informationBuilding Java Programs Chapter 1
Building Java Programs Chapter 1 Introduction to Java Programming Copyright (c) Pearson 2013. All rights reserved. The CS job market 160,000 140,000 120,000 100,000 80,000 60,000 PhD Master's Bachelor's
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us From this site you can click on the COSC-236
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com
More informationBuilding Java Programs
Comments Building Java Programs Chapter 1 Lecture 1-2: Static Methods reading: 1.4-1.5 comment: A note written in source code by the programmer to describe or clarify the code. Comments are not executed
More informationWelcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs
Welcome to CSE 142! Zorah Fung University of Washington, Spring 2015 Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs reading: 1.1-1.3 1 What is computer science? computers?
More informationLecture 1: Basic Java Syntax
Lecture 1: Basic Java Syntax Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson 2013. All rights reserved. Java Terminology class: (a) A module or program
More informationCS 112 Introduction to Programming
CS 112 Introduction to Programming Lecture #2: Java Program Structure Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu 2 1 Outline q Admin.
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com
More informationWelcome to CSE 142! Whitaker Brand. University of Washington, Winter 2018
Welcome to CSE 142! Whitaker Brand University of Washington, Winter 2018 1 What is computer science? computers? science? programming? late lonely nights in front of the computer? ALGORITHMIC THINKING al
More informationTopic 3 static Methods and Structured Programming
Topic 3 static Methods and Structured Programming "The cleaner and nicer the program, the faster it's going to run. And if it doesn't, it'll be easy to make it fast." -Joshua Bloch Based on slides by Marty
More informationJava Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2
Java Foundations Introduction to Program Design and Data Structures 4th Edition Lewis TEST BANK Full download at : https://testbankreal.com/download/java-foundations-introduction-toprogram-design-and-data-structures-4th-edition-lewis-test-bank/
More informationAP Computer Science Unit 1. Programs
AP Computer Science Unit 1. Programs Open DrJava. Under the File menu click on New Java Class and the window to the right should appear. Fill in the information as shown and click OK. This code is generated
More informationBuilding Java Programs
Building Java Programs Chapter 5 Lecture 5-1: while Loops, Fencepost Loops, and Sentinel Loops reading: 4.1, 5.1 self-check: Ch. 4 #2; Ch. 5 # 1-10 exercises: Ch. 4 #2, 4, 5, 8; Ch. 5 # 1-2 Copyright 2009
More informationCS111: PROGRAMMING LANGUAGE II
1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1: Introduction Lecture Contents 2 Course info Why programming?? Why Java?? Write once, run anywhere!! Java basics Input/output Variables
More informationTopic 12 more if/else, cumulative algorithms, printf
Topic 12 more if/else, cumulative algorithms, printf "We flew down weekly to meet with IBM, but they thought the way to measure software was the amount of code we wrote, when really the better the software,
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com
More informationTopic 12 more if/else, cumulative algorithms, printf
Topic 12 more if/else, cumulative algorithms, printf "We flew down weekly to meet with IBM, but they thought the way to measure software was the amount of code we wrote, when really the better the software,
More informationdouble float char In a method: final typename variablename = expression ;
Chapter 4 Fundamental Data Types The Plan For Today Return Chapter 3 Assignment/Exam Corrections Chapter 4 4.4: Arithmetic Operations and Mathematical Functions 4.5: Calling Static Methods 4.6: Strings
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationOct Decision Structures cont d
Oct. 29 - Decision Structures cont d Programming Style and the if Statement Even though an if statement usually spans more than one line, it is really one statement. For instance, the following if statements
More informationCOMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements
COMP-202 Unit 4: Programming With Iterations CONTENTS: The while and for statements Introduction (1) Suppose we want to write a program to be used in cash registers in stores to compute the amount of money
More informationImportant Java terminology
1 Important Java terminology The information we manage in a Java program is either represented as primitive data or as objects. Primitive data פרימיטיביים) (נתונים include common, fundamental values as
More informationBuilding Java Programs
Building Java Programs Chapter 4 Lecture 4-2: Advanced if/else; Cumulative sum; reading: 4.2, 4.4-4.5 2 Advanced if/else reading: 4.4-4.5 Factoring if/else code factoring: Extracting common/redundant code.
More informationCOMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015 Announcements Midterm Exams on 4 th of June (12:35 14:35) Room allocation will be announced soon
More informationCS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam
Seat Number Name CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam This is a closed book exam. Answer all of the questions on the question paper in the space provided. If
More informationM105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014
M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014 Question One: Choose the correct answer and write it on the external answer booklet. 1. Java is. a. case
More informationBuilding Java Programs
Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs with Scanner 1 Lecture outline console input with Scanner objects input tokens Scanner as a parameter to a method cumulative
More informationMethods CSC 121 Spring 2017 Howard Rosenthal
Methods CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Understand what a method is in Java Understand Java s Math Class and how to use it Learn the syntax of method construction Learn both void methods
More informationDepartment of Computer Science Purdue University, West Lafayette
Department of Computer Science Purdue University, West Lafayette Fall 2011: CS 180 Problem Solving and OO Programming Exam 1 Solutions Q 1 Answer the questions below assuming that binary integers are represented
More informationTerm 1 Unit 1 Week 1 Worksheet: Output Solution
4 Term 1 Unit 1 Week 1 Worksheet: Output Solution Consider the following what is output? 1. System.out.println("hot"); System.out.println("dog"); Output hot dog 2. System.out.print("hot\n\t\t"); System.out.println("dog");
More informationCheck 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.
Chapter 4 Lab Loops and Files Lab Objectives Be able to convert an algorithm using control structures into Java Be able to write a while loop Be able to write an do-while loop Be able to write a for loop
More informationWeek 2: Data and Output
CS 170 Java Programming 1 Week 2: Data and Output Learning to speak Java Types, Values and Variables Output Objects and Methods What s the Plan? Topic I: A little review IPO, hardware, software and Java
More informationAP Computer Science. Return values, Math, and double. Copyright 2010 by Pearson Education
AP Computer Science Return values, Math, and double Distance between points Write a method that given x and y coordinates for two points prints the distance between them If you can t do all of it, pseudocode?
More informationBuilding Java Programs
Building Java Programs Chapter 1: Introduction to Java Programming These lecture notes are copyright (C) Marty Stepp and Stuart Reges, 2007. They may not be rehosted, sold, or modified without expressed
More informationQuestion: Total Points: Score:
CS 170 Exam 1 Section 001 Fall 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than
More informationMidterm Examination (MTA)
M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and
More informationFaculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination Tuesday, November 4, 2008 Examiners: Mathieu Petitpas [Section 1] 18:30
More informationReview Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013
Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections 2.1 2.5 Instructor:
More informationJava Coding 3. Over & over again!
Java Coding 3 Over & over again! Repetition Java repetition statements while (condition) statement; do statement; while (condition); where for ( init; condition; update) statement; statement is any Java
More informationAP CS Unit 3: Control Structures Notes
AP CS Unit 3: Control Structures Notes The if and if-else Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts
More informationCS 101 Spring 2007 Midterm 2 Name: ID:
You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure
More informationChapter 3. Selections
Chapter 3 Selections 1 Outline 1. Flow of Control 2. Conditional Statements 3. The if Statement 4. The if-else Statement 5. The Conditional operator 6. The Switch Statement 7. Useful Hints 2 1. Flow of
More informationLecture 8 " INPUT " Instructor: Craig Duckett
Lecture 8 " INPUT " Instructor: Craig Duckett Assignments Assignment 2 Due TONIGHT Lecture 8 Assignment 1 Revision due Lecture 10 Assignment 2 Revision Due Lecture 12 We'll Have a closer look at Assignment
More informationWhat did we talk about last time? Examples switch statements
Week 4 - Friday What did we talk about last time? Examples switch statements History of computers Hardware Software development Basic Java syntax Output with System.out.print() Mechanical Calculation
More informationProgramming Exercise 7: Static Methods
Programming Exercise 7: Static Methods Due date for section 001: Monday, February 29 by 10 am Due date for section 002: Wednesday, March 2 by 10 am Purpose: Introduction to writing methods and code re-use.
More informationProgramming with Java
Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules
More informationAP Computer Science Unit 1. Writing Programs Using BlueJ
AP Computer Science Unit 1. Writing Programs Using BlueJ 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save
More information1 Short Answer (10 Points Each)
1 Short Answer (10 Points Each) 1. Write a for loop that will calculate a factorial. Assume that the value n has been input by the user and have the loop create n! and store it in the variable fact. Recall
More informationBuilding Java Programs
Building Java Programs Chapter 5 Lecture 5-4: do/while loops, assertions reading: 5.1, 5.5 1 The do/while loop do/while loop: Performs its test at the end of each repetition. Guarantees that the loop's
More informationGetting started with Java
Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving
More informationEntry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process
Entry Point of Execution: the main Method Elementary Programming EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG For now, all your programming exercises will
More informationUsing Java Classes Fall 2018 Margaret Reid-Miller
Using Java Classes 15-121 Fall 2018 Margaret Reid-Miller Today Strings I/O (using Scanner) Loops, Conditionals, Scope Math Class (random) Fall 2018 15-121 (Reid-Miller) 2 The Math Class The Math class
More informationwww.thestudycampus.com Methods Let s imagine an automobile factory. When an automobile is manufactured, it is not made from basic raw materials; it is put together from previously manufactured parts. Some
More informationIntroduction to Java Unit 1. Using BlueJ to Write Programs
Introduction to Java Unit 1. Using BlueJ to Write Programs 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save
More informationComputer Science 210 Data Structures Siena College Fall Topic Notes: Methods
Computer Science 210 Data Structures Siena College Fall 2017 Topic Notes: Methods As programmers, we often find ourselves writing the same or similar code over and over. We learned that we can place code
More informationCOMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz
COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz The in-class quiz is intended to give you a taste of the midterm, give you some early feedback about
More informationConditional Execution
Unit 3, Part 3 Conditional Execution Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Simple Conditional Execution in Java if () { else {
More informationFull file at
Chapter 2 Console Input and Output Multiple Choice 1) Valid arguments to the System.out object s println method include: (a) Anything with double quotes (b) String variables (c) Variables of type int (d)
More informationAP Computer Science Summer Work Mrs. Kaelin
AP Computer Science Summer Work 2018-2019 Mrs. Kaelin jkaelin@pasco.k12.fl.us Welcome future 2018 2019 AP Computer Science Students! I am so excited that you have decided to embark on this journey with
More informationFaculty of Science COMP-202A - Foundations of Computing (Fall 2012) - All Sections Midterm Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Foundations of Computing (Fall 2012) - All Sections Midterm Examination November 7th, 2012 Examiners: Daniel Pomerantz [Sections
More informationMethods CSC 121 Fall 2016 Howard Rosenthal
Methods CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand what a method is in Java Understand Java s Math Class and how to use it Learn the syntax of method construction Learn both void methods
More informationBuilding Java Programs Chapter 2
Building Java Programs Chapter 2 Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. Data types type: A category or set of data values. Constrains the operations that can
More informationWeek 6 CS 302. Jim Williams, PhD
Week 6 CS 302 Jim Williams, PhD This Week Lab: Multi-dimensional Arrays Exam 1: Thursday Lecture: Methods Review Midterm Exam 1 What is the location of the exam? 3650 Humanities 125 Ag Hall 272 Bascom
More informationChapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics
Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional
More informationBuilding Java Programs
Building Java Programs Chapter 5 Lecture 5-4: do/while loops, assertions reading: 5.1, 5.5 1 The do/while loop do/while loop: Performs its test at the end of each repetition. Guarantees that the loop's
More informationint: integers, no fractional part double: floating-point numbers (double precision) 1, -4, 0 0.5, , 4.3E24, 1E-14
int: integers, no fractional part 1, -4, 0 double: floating-point numbers (double precision) 0.5, -3.11111, 4.3E24, 1E-14 A numeric computation overflows if the result falls outside the range for the number
More informationCSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI
CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are
More informationFull file at
Chapter 1 1. a. False; b. False; c. True; d. False; e. False; f; True; g. True; h. False; i. False; j. True; k. False; l. True. 2. Keyboard and mouse. 3. Monitor and printer. 4. Because programs and data
More informationCS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG
CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG 1 Notice Assignments Reading Assignment: Chapter 3: Introduction to Parameters and Objects The Class 10 Exercise
More informationCEN 414 Java Programming
CEN 414 Java Programming Instructor: H. Esin ÜNAL SPRING 2017 Slides are modified from original slides of Y. Daniel Liang WEEK 2 ELEMENTARY PROGRAMMING 2 Computing the Area of a Circle public class ComputeArea
More informationPlease answer the following questions. Do not re-code the enclosed codes if you have already completed them.
Dec. 9 Loops Please answer the following questions. Do not re-code the enclosed codes if you have already completed them. What is a loop? What are the three loops in Java? What do control structures do?
More informationCONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2
CONTENTS: Compilation Data and Expressions COMP 202 More on Chapter 2 Programming Language Levels There are many programming language levels: machine language assembly language high-level language Java,
More informationCSEN 202 Introduction to Computer Programming
CSEN 202 Introduction to Computer Programming Lecture 4: Iterations Prof. Dr. Slim Abdennadher and Dr Mohammed Abdel Megeed Salem, slim.abdennadher@guc.edu.eg German University Cairo, Department of Media
More information! definite loop: A loop that executes a known number of times. " The for loops we have seen so far are definite loops. ! We often use language like
Indefinite loops while loop! indefinite loop: A loop where it is not obvious in advance how many times it will execute.! We often use language like " "Keep looping as long as or while this condition is
More informationCS 112 Introduction to Programming
CS 112 Introduction to Programming Program Analysis Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu Admin q PS5 Walkthrough Thursday
More informationFull file at
Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional
More informationAdvanced if/else & Cumulative Sum
Advanced if/else & Cumulative Sum Subset of the Supplement Lesson slides from: Building Java Programs, Chapter 4 by Stuart Reges and Marty Stepp (http://www.buildingjavaprograms.com/ ) Questions to consider
More informationTester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time
Tester vs. Controller Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG For effective illustrations, code examples will mostly be written in the form of a tester
More informationArrays. Weather Problem Array Declaration Accessing Elements Arrays and for Loops Array length field Quick Array Initialization Array Traversals
Arrays Weather Problem Array Declaration Accessing Elements Arrays and for Loops Array length field Quick Array Initialization Array Traversals Can we solve this problem? Consider the following program
More informationChapter 2: Basic Elements of Java
Chapter 2: Basic Elements of Java TRUE/FALSE 1. The pair of characters // is used for single line comments. ANS: T PTS: 1 REF: 29 2. The == characters are a special symbol in Java. ANS: T PTS: 1 REF: 30
More informationElementary Programming
Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG Learning Outcomes Learn ingredients of elementary programming: data types [numbers, characters, strings] literal
More informationCS 121 Intro to Programming:Java - Lecture 7 Professor Robert Moll (+ TAs) CS BLDG 276-545-4315 moll@cs.umass.edu course web page below http://twiki-edlab.cs.umass.edu/bin/view/moll121/webhome Announcements
More informationUniversità degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M
Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M tutor Isam M. Al Jawarneh, PhD student isam.aljawarneh3@unibo.it Mobile Middleware
More informationBasic Computation. Chapter 2
Basic Computation Chapter 2 Outline Variables and Expressions The Class String Keyboard and Screen I/O Documentation and Style Variables Variables store data such as numbers and letters. Think of them
More information