Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 CSCI 1226 FALL 2015 MIDTERM #1 REVIEWS

2  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?

3  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!

4  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

5  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

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

7 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!

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

9  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 “ ”

10  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”); }

11  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

12  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

13 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”

14  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!

15  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!

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

17 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!

18 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);

19  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

20  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

21  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”); }

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

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


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

Similar presentations


Ads by Google