CSCI 1226 FALL 2015 MIDTERM #1 REVIEWS.  Types of computers:  Personal computers  Embedded systems  Servers  Hardware:  I/O devices: mice, keyboards,

Slides:



Advertisements
Similar presentations
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
Advertisements

Logic & program control part 2: Simple selection structures.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
Loops – While, Do, For Repetition Statements Introduction to Arrays
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
COMP 110 Introduction to Programming Mr. Joshua Stough September 10, 2007.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
Repeating Actions The “while” and “for” Controls Sections 4.1 & 4.2 (Also: Special Assignment Operators and Constants)
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.
CSCI 1226 Fall 2014 Reviews Section B. Computers  Types of computers:  Personal computers  Embedded systems  Servers  Hardware:  I/O devices: mice,
1 Course Lectures Available on line:
CIS Computer Programming Logic
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Input, Output, and Processing
Repeating Actions The “while” and “for” Controls Sections 4.1 & 4.2 (Also: Special Assignment Operators, Constants, and Switching int and double)
Introduction to Computer Systems and the Java Programming Language.
S2008Final_part1.ppt CS11 Introduction to Programming Final Exam Part 1 S A computer is a mechanical or electrical device which stores, retrieves,
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 Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
F27SA1 Software Development 1 3. Java Programming 2 Greg Michaelson.
Making Choices The “if” Control Sections 3.1 & 3.2.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
1 Chapter 3 Selections. 2 Outline 1. Flow of Control 2. Conditional Statements 3. The if Statement 4. The if-else Statement 5. The Conditional operator.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
COMP Flow of Control: Branching 1 Yi Hong May 19, 2015.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Basic Programming The Program Class, the main Method, Variables, Output, and Input Chapters 1 and 2.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Debugging, Escape Command, More Math. It’s your birthday!  Write a program that asks the user for their name and their age.  Figure out what their birth.
BOOLEAN OPERATIONS AND CONDITIONALS CHAPTER 20 1.
Chapter 2: Fundamental Programming Structures in Java Adapted from MIT AITI Slides Control Structures.
Primitive Data Types int is a primitive data type A primitive data type is one that stores only a single piece of data. TypeStorageDescription int 4 bytes+ve.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Control Statements: Part1  if, if…else, switch 1.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Fundamentals 2 1. Programs and Data Most programs require the temporary storage of data. The data to be processed is stored in a temporary storage in.
Nested Structures Chapters 3 & 4. Outline n Conditionals inside loops n Conditionals inside conditionals n If-else-if controls n Loops inside loops n.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
CompSci 230 S Programming Techniques
Topics Designing a Program Input, Processing, and Output
Chapter 2 Basic Computation
Chapter 2 More on Math More on Input
Java for Beginners University Greenwich Computing At School DASCO
Primitive Data, Variables, Loops (Maybe)
Variables, Expressions, and IO
Repeating Actions The "while" and "for" Controls Sections 4.1 & 4.2
Java Programming: From Problem Analysis to Program Design, 4e
SELECTION STATEMENTS (1)
IDENTIFIERS CSC 111.
Chapter 3 Selections Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1.
Fundamentals 2.
The “if” Control Sections 3.1 & 3.2
Building Java Programs
Chapter 2 Programming Basics.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Primitive Types and Expressions
Unit 3: Variables in Java
Building Java Programs
Announcements Lab 3 was due today Assignment 2 due next Wednesday
COMPUTING.
Presentation transcript:

CSCI 1226 FALL 2015 MIDTERM #1 REVIEWS

 Types of computers:  Personal computers  Embedded systems  Servers  Hardware:  I/O devices: mice, keyboards, monitors, etc  CPU (Central Processing Unit)  Memory, Main/Primary vs secondary COMPUTERS Exam tip! Examples of each type? Exam tip! Examples of each type? Exam tip! What are the differences? Exam tip! What are the differences? Exam tip! Examples of each type? Exam tip! Examples of each type?

 Software:  Data & instructions  Algorithm  Pseudo-code  Data hierarchy:  8 bits  byte  1 or more bytes  data value (field)  1 or more data values/objects  object (record)  data may be stored on secondary memory (file) …COMPUTERS Exam tip! What are the differences? Exam tip! What are the differences? Exam tip! An object can contain other objects! Exam tip! An object can contain other objects!

 IDE: Integrated Development Environment  Algorithms, pseudo-code  Variables:  Data types: int/double/String/boolean/char  Declaration e.g.) int a; String name = “name”;  Naming rules and conventions  Math and special assignment operators  +, -, *, /, %  +=, -=, *=, /=. %=  ++, -- JAVA PROGRAMMING BASICS Exam tip! Declare variables given description: e.g.) the number of words entered by the user whether the user is 65 or older Exam tip! Declare variables given description: e.g.) the number of words entered by the user whether the user is 65 or older

 Output:  System.out.println() and System.out.print()  Print spaces  With or without quotes  Concatenation (using +, with math expressions, etc)  User input:  Scanner class: instantiation, import, etc  next(), nextLine(), nextInt(), nextDouble(), etc  Use nextLine() to  flush the input buffer …JAVA PROGRAMMING BASICS Exam tip! How to pause a program using nextLine()? Exam tip! How to pause a program using nextLine()? Exam tip! Print all values in one line or each value in one line Exam tip! Print all values in one line or each value in one line Exam tip! Write code to read 2 Strings and a number and ignore the rest: Jimmy Smith 45 ignore me e.g.) review A01 Exam tip! Write code to read 2 Strings and a number and ignore the rest: Jimmy Smith 45 ignore me e.g.) review A01

SYNTAX ERROR: NETBEANS  NetBeans notices syntax errors right away  look for red squiggle and in margin  mouse over the to see the explanation

LOGIC ERROR  Compiler will not notice! System.out.println("A length by width" + "rectangle has an area of area.");  Program just does the wrong thing  hopefully you can tell from the output!

MATH EXPRESSIONS Exam tip! Translate regular math expressions into Java math expressions. Exam tip! Translate regular math expressions into Java math expressions.

 Syntax:  if, if-else, if-else if, if-else if … else  Comparison operators  ==, !=,, =  Logical operators  && (AND), || (OR), ! (NOT) CONDITIONALS Exam tip! Less/larger than or equal to always have “=“ after “ ” Exam tip! Less/larger than or equal to always have “=“ after “ ”

 Sequential and nested if-else:  Convert one to the other  What’s the output?:  What’s the code?  Possible outcomes:  outcome #1: A, B, C, E, F  outcome #2: A, D, E, F … CONDITIONALS System.out.print(“A”); if (...) { System.out.print(“B”); } if (...) { System.out.print(“C”); if (...) { System.out.print(“D”); } else { System.out.print(“E”); }

 Can save the answer to a comparison  use a boolean variable boolean workedOvertime = (hours > 40);  you don’t need parentheses, but it’s easier to read  E.g.) Write Boolean expressions for whether…  x is greater than 0 and y is less than 5  x is greater than zero or y is equal to z  it’s not the case that x is greater than the product of y and z boolean VARIABLES Exam tip! “whether”  boolean Exam tip! “whether”  boolean

 Break complex expressions down boolean failedMidterm = (midtermGrade < 50); boolean failedFinal = (finalGrade < 50); boolean failedBothTests = failedMidterm && failedFinal;  String comparisons (all return boolean values)  oneString.equals(anotherString)  oneString.equalsIgnoreCase(anotherString)  oneString.startsWith(anotherString)  oneString.endsWith(anotherString) … boolean VARIABLES Exam tip! boolean a = true, b = false, c = false; !a a && b (a || c) && (!b && !c) (a && !b) || c Exam tip! boolean a = true, b = false, c = false; !a a && b (a || c) && (!b && !c) (a && !b) || c

STRING.TOUPPERCASE/TOLOWERCASE  Ask a string for upper/lower case version System.out.println(“Do you want fries?”); String answer = kbd.next(); kbd.nextLine(); String upperAnswer = answer.toUpperCase(); if (upperAnswer.startsWith(“Y”)) …  now accepts “Yes”, “yes”, “Yeah, “yup”, …  upperAnswer is “YES”, “YES”, “YEAH”, “YUP”  answer is still “Yes”, “yes”, “Yeah”, “yup”

 for and while loops  Convert between them  Loop structure  Initialize, test/condition, update, process LOOPS for (initialize; test; update) { process; } initialize; while (test) { process; update; } Exam tip! When asked for an algorithm, make sure to include all these 4 steps! Exam tip! When asked for an algorithm, make sure to include all these 4 steps!

 Write loops to:  Calculate sum, average, max, min, of numbers  When to stop?  Negative number  Yes/no  Track the variable’s values:  What’s the output of the program? … LOOPS a = 1; a++; b = a + 6; b--; c = b * 5; c += a; a *= 10; b /= 2; c %= 4; a *= b + c; S.O.Pln(a + “:” + b + “:” + c); Exam tip! Write the loops to find these values! Exam tip! Write the loops to find these values! Exam tip! Be able to write a loop that stops for these! Exam tip! Be able to write a loop that stops for these!

 public static final data-type CONST_NAME = value  Naming conventions  variableNameConvention  CONSTANT_NAME_CONVENTION NAMED CONSTANTS

DIVIDING INTEGERS & DOUBLES  Java uses / for both int and double division  15 / 2 is 7because 15 and 2 are both int  15.0 / 2.0 is 7.5because 15.0 & 2.0 are doubles  “Mixed” expressions use double division  15.0 / 2 is 7.5; 15 / 2.0 is 7.5  (double) says use the double version of this  (double)15 / 2 is 7.5; 15 / (double)2 is 7.5  If sum is 17, then (double)sum is 17.0  but sum is still an int (17);it doesn’t change!

CHANGING DOUBLES TO INTS  Can also change the other way  use (int) in front of a double value/variable double price = 15.99; int dollars = (int)price; int cents = (int)(100 * (price – dollars)); System.out.println(dollars + " dollars and " + cents + " cents.");  NOTE: it doesn’t round off; it truncates! 15 dollars and 99 cents. To Round off, use: int approxDollars = (int)Math.round(price);

 Loops with Conditionals while (num >= 0) { // say whether num is divisible by 5 if (num % 5 == 0) { System.out.println(num + “ is divisible by 5.”); } else { System.out.println(num + “ is not divisible by 5.”); } // get next number num = kbd.nextInt(); } NESTED STRUCTURES

 if inside if: System.out.println(“A”); if (condition1) { System.out.println(“B”); if (condition2) { System.out.println(“C”); } … NESTED STRUCTURES possible output: A AB ABC pattern: always A sometimes B when B, sometimes C

 Rewrite sequential-if to cascading-if … NESTED STRUCTURES if (age < 18) { System.out.print(“Child”); } if (age >= 18 && age < 65) { System.out.print(“Adult”); } if (age >= 65) { System.out.print(“Senior”); } if (age < 18) { System.out.print(“Child”); } else if (age < 65) { System.out.print(“Adult”); } else { System.out.print(“Senior”); }

 Loops inside loops:  Draw a rectangle:  Get w, h, and char from user  Conditionals inside loops:  Repeated menu with switch … NESTED STRUCTURES

 Inside loops  Inside if-else  Inside method (variables and parameters)  Inside class (instance and class variables) SCOPES OF A VARIABLE/PARAMETER