Slide 1

Slide 1 text

CSE110 Principles of Programming with Java Lecture 11: Review Javier Gonzalez-Sanchez [email protected] javiergs.engineering.asu.edu | javiergs.com Office Hours: By appointment

Slide 2

Slide 2 text

Note about Strings

Slide 3

Slide 3 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 3 Comparing Strings • Remember that a character string in Java is not a primitive data type. • We cannot use the relational operators to compare strings • Do NOT do this String str1 = "apple"; String str2 = "banana"; if (str1 == str2){//we are not supposed to do this }

Slide 4

Slide 4 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 4 Comparing Strings String str1 = "apple"; String str2 = "banana"; //do NOT do this if (str1 == str2){ } // Instead we need to do: if (str1.equals(str2)){ }

Slide 5

Slide 5 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 5 Comparing Strings • The following does not also compare two strings: String str1 = "apple"; String str2 = "banana"; //do NOT do this if (str1 < str2){ } // Instead we need to do: if (str1.compareTo(str2) < 0){ }

Slide 6

Slide 6 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 6 Example int result = str1.compareTo(str2); if (result < 0) { //if str1 is smaller than str2 } else if (result > 0){ //if str1 is larger than str2 } else if (result == 0) //if str1 is identical to str2 }

Slide 7

Slide 7 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 7 Comparing Strings • Comparing strings is based on a character set, it is called a lexicographic ordering • It uses Unicode of each character in strings. • Also, short strings come before longer strings with the same prefix (lexicographically) Therefore "book" comes before "bookcase"

Slide 8

Slide 8 text

Midterm Exam 1

Slide 9

Slide 9 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 9 Lectures

Slide 10

Slide 10 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 10 Disclaimer The previous questions are just examples. They are NOT a comprehensive list of topics Review All the Slides for a full list of topics The exam is NOT limited to the topics covered in the previous questions. For instance printf() was not in the previous examples; but could be part of your exam

Slide 11

Slide 11 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 11 Day 2 1. What is a compiler? 2. What is Java byte code? 3. Give an example of a lexical error in Java 4. Give an example of a syntactic error in Java 5. Give an example of a semantic error in Java

Slide 12

Slide 12 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 12 Day 3 1. What is a variable? 2. What is a method? 3. What is a class? 4. Create a program that prints “This is my exam”. Including the code for creating a class and main method. 5. Write 3 reserved words in Java

Slide 13

Slide 13 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 13 Day 4 1. Write a multi-line comment with your name and ASUID 2. Mention the 8 primitive types defined in Java 3. Is the following statement correct? char = ' ' '; 4. Is the following statement correct? boolean result = 5 + 2 > 5 - 1 ; 5. What is the result of (-20 % 3 -2)

Slide 14

Slide 14 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 14 Day 5, 6 1. What is the result of 1 % 2 - 3 / 4 * 5 / 6 + 7 2. Is the following correct? If so, What is the result? 1 % 2 - 3 / 4 * 5 / 6 + 7 + “Hello” 3. Is the following correct? If so, What is the result? ”Hello” + 1 % 2 - 3 / 4 * 5 / 6 + 7 4. Is the following correct? If so, What is the result? float f = 2.5f + 2.5f; System.out.println(f); 5. Is the following correct? If so, What is the result? System.out.println( Math.pow(5.0,2.0) );

Slide 15

Slide 15 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 15 Solution

Slide 16

Slide 16 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 16 Day 7 1. What is a package? 2. What is the next instruction for? JOptionPane.showInputDialog(“this is a message”); 3. What is the next instruction for? Integer.parseInt(“12345”); 4. What is JOptionPane? 5. What is showInputDialog?

Slide 17

Slide 17 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 17 Day 8, 9 int x = 75; y = 95; z = 1; if (x < y && x < z) { if (y < z) System.out.println( x + " " + y + " " + z ); else System.out.println( x + " " + z + " " + y ); } else if (x > y && x > z) { if (y < z) System.out.println( y + " " + z + " " + x ); else System.out.println( z + " " + y + " " + x ); } else { if (y < z) System.out.println( y + " " + x + " " + z); else System.out.println( z + " " + x + " " + y); }

Slide 18

Slide 18 text

Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 18 Day 10 public class Example { public static void main(String args[]) { int age = 18; switch (age) { case 16: System.out.println("You are under 18."); break; case (18): System.out.println("You are eligible for vote."); break; case (65): System.out.println("You are senior citizen."); break; default: System.out.println("Please give the valid age."); break; } } }

Slide 19

Slide 19 text

CSE110 - Principles of Programming Javier Gonzalez-Sanchez [email protected] Summer 2020 Disclaimer. These slides can only be used as study material for the class CSE110 at ASU. They cannot be distributed or used for another purpose.