Presentation is loading. Please wait.

Presentation is loading. Please wait.

Selection and Testing Shirley Moore CS 1401 Spring 2013 February 21 and 26, 2013 1.

Similar presentations


Presentation on theme: "Selection and Testing Shirley Moore CS 1401 Spring 2013 February 21 and 26, 2013 1."— Presentation transcript:

1 Selection and Testing Shirley Moore CS 1401 Spring 2013 February 21 and 26, 2013 1

2 Agenda Feb 21 – Announcements (5-10 min) – Concepts of if statements and Boolean expressions (20 min) – Checkpoint questions (30 min) – Test plans (15 min) – Wrapup (5 min) Feb 26 – Announcements (5 min) – Quiz 3 (15 min) – Programming exercises 3.1, 3.8 (20 min) – Switch statement (10 min) – Testing video clips and discussion (20 min) – Research projects ( 5 min) – Wrapup, assignment for next time (5 min) 2

3 Announcements Seminar today at 1:30: Eduard Dragut, CyberShare Viz Lab, Classroom Building 4 th floor Exam 1 IPO Algorithm/Programming retest Unit 2 Outcomes and Schedule New due dates for Lab 3 and Lab 4 3

4 Checking for Valid Program Input Why should you do it? What is the logic? – Example: Program to input base radius and length of a cylinder and compute the volume How can we implement the logic? – If statement condition(s) to test – relational operators, =, ==, != – logical operators &&, ||, ! actions to take depending on value of condition 4

5 Boolean Data Type and Expressions Can have values true and false Examples (can type in Dr Java Interactions)  3 < 5  -3 < -5  ‘a’ < ‘b’  (3 10)  double radius = -0.5;  radius >= 0.0  boolean checkRadius = (radius >= 0.0);  checkRadius 5

6 If Statement Syntax if (boolean-expression) { statement(s) } if (boolean-expression) { statements(s) // for the true case } else { statement(s) // for the false case } Can be nested Class exercise: Use if-else to add input checking to cylinder problem 6

7 CheckPoint Questions p. 92, 3.8 if ( x > 2 ) { if (y > 2) { z = x + y; System.out.println(“z is “ + z); } } else { System.out.println(“x is “ + x); } Test inputs o x = 3, y = 2 o x = 3, y = 4 o x = 2, y = 2 7

8 Checkpoint Questions (cont.) p. 92, 3.9 if (x > 2) if (y > 2) { z = x + y; System.out.println(“z is “ + z); } else System.out.println(“x is “ + x); Test inputs o x = 2, y = 3 o x = 3, y = 2 o x = 3, y = 3 8

9 Checkpoint Questions (cont.) p. 92, 3.10 if (score >= 60.0) grade = ‘D’; else if (score >= 70.0) grade = ‘C’; else if (score >= 80.0) grade = ‘B’; else if (score >= 90.0) grade = ‘A’; else grade = ‘F’; What do you think was the intent of the above code? Does it accomplish this intent? If not, how can you fix it? 9

10 Programming Exercises p. 121, 3.1 Write a program that inputs real values a, b, and c for the coefficients of a quadratic equation and outputs the result based on the discriminant. If the discriminant is positive, output two roots. If the discriminant is 0, output one root. If the discriminant is negative, output that the equation has no real roots. 10

11 Programming Exercises (cont.) p. 123, exercise 3.8 Write a program that inputs three integers into variables num1, num2, num3 and outputs the integers sorted from least to greatest. 11

12 Switch Statement Syntax: switch (expression) { case constant-1: statements-1 break; case constant-2: statements-2 break;.. // (more cases). case constant-N: statements-N break; default: // optional default case statements-(N+1) } // end of switch statement Discuss semantics 12

13 In-class Exercise The commission rate for a sale at a shop varies depending on the sales class of the item, as given in the table below. Any other sales class besides those listed has zero commission. Write a program that inputs a price and sales class for an item and outputs the commission that the sales person will earn for selling that item. Use a switch statement to select the commission rate. Write a step-by-step algorithm before writing the ajava code. 13 Sales Class Commission Rate 12 % 23.5% 25% 46%

14 Testing Your Program Developing a test plan Video clips – The Machine That Changed the World, Part 5 42:00-52:00 – Tacoma Bridge disaster http://science.howstuffworks.com/engineering/civil/bri dge10.htm 14

15 Research mini-Projects History of computing Using programming to teach math Software reliability More topics to come (feel free to suggest topics in which you are interested!) 15

16 Assignment for Thursday, Feb 28 Do Chapter 3 end-of-chapter programming exercises 3.19, 3.20, 3.22, 3.29. Follow steps discussed in class. Hand-write neatly or print out to turn in and/or discuss at beginning of class. Read Chapter 4 sections 4.1-4.7. Write down any questions you have. Write answers to CheckPoint questions. 16


Download ppt "Selection and Testing Shirley Moore CS 1401 Spring 2013 February 21 and 26, 2013 1."

Similar presentations


Ads by Google