Class 22 - Flow Control in Java 1 Goals for Today n n Learn...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Flow Control in Java 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Goals for Today n Learn how to use the if statement n Learn how to use the switch statement 2 MGMT 29000
Background image of page 2
Flow Control In Java n Purpose of using selective and repetitive execution ¨ Implement methods that produce complex behaviors n Selective flow control statements: if and switch n Repetitive flow control statements: while , for , do 3 MGMT 29000
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introductory Example: pH n Background for the use of pH values ¨ pH: measures the acidity of a solution ¨ pH scale of values: 0 – 14 ¨ Labels for ranges in pH scale: acidic, neutral, alkaline n Main elements in a user story built around pH values ¨ pH values of water samples have been recorded ¨ Given pH values of samples, provide correct labels n Divide the problem into two subproblems ¨ Build a class to model pH values and operations ¨ Write a program that uses the class to label samples 4 MGMT 29000
Background image of page 4
Subproblem 1: A PH Class n The PH class needs a private instance variable ¨ double type variable is named myValue ¨ myValue will be initialized by a constructor n PH constructor ¨ Takes an argument that sets myValue ¨ If pH argument is invalid, an error message displays ¨ Otherwise, pH argument is assigned to myValue n The label() method ¨ Returns error message if value is outside range ¨ Otherwise, returns one of three labels 5 MGMT 29000
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Subproblem 1: A PH Class (continued) 6 MGMT 29000
Background image of page 6
Subproblem 2: Processing Multiple pH Values n
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/04/2012 for the course MGMT 290 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 23

Class 22 - Flow Control in Java 1 Goals for Today n n Learn...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online