Introduction to Computing
Introduction to Computing CSC 116
Popular in Course
Popular in ComputerScienence
This 13 page Class Notes was uploaded by Jaden Jakubowski on Thursday October 15, 2015. The Class Notes belongs to CSC 116 at North Carolina State University taught by Suzanne Balik in Fall. Since its upload, it has received 36 views. For similar materials see /class/223811/csc-116-north-carolina-state-university in ComputerScienence at North Carolina State University.
Reviews for Introduction to Computing
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/15/15
Boolean Variables Boolean ValuesExpressions Review quotExclusive or vs quotInclusive or De Morgan s Laws Short Circuit Evaluation Logical Operator Precedence Examples TaxCalculator Type boolean boolean A primitive type to represent logical values A boolean expression produces either true or false The ltconditiongts in if statements for loops are boolean Examples boolean minor age lt 21 boolean expensive iPhonePrice gt 50000 boolean iLoveCS true if minor SystemoutprintlnquotCan39t purchase quot quotalcoholquot You can create boolean variables pass boolean parameters return boolean values from methods mquot V Copyright 2006 by Pearson Education Logical operators ampamp II a Boolean expressions can use logical operators Copyright 2006 by Pearson Education Operator Description Example Result ampamp and 9 6 ampamp 2 lt 3 true II or 2 1 lt 5 true 1 not 7 gt 0 false Truth tables of each operator used with boolean values p and q p q p ampampq p H q p p true true true true true false true false false true false true false true false true false false false false quotExclusive or vs quotInclusive or We generally use quotexclusive or when speaking quotI ll do my homework or go to the party means I ll do one or the other but not both Programming uses quotinclusive or An expression is true if either or both conditions are true 2gt34lt5 F T T 2lt34lt5 TTT De Morgan s Laws pampampmunlm NXltWNvlt Xgtvvgtz Hxltyampampyltz De Morgan s Laws pm pampampq xltyampamp yltz Xgty ampamp ygtz Wltvvltz Short Circuit Evaluation Short Circuit Evaluation The property of the logical operators ampamp and I that prevents the second operand from being evaluated if the overall result is obvious from the value of the first operand Examples 2 gt 3 ampamp 4 lt 5 F ampamp F 2lt3 H 4gt5 TT Logical Operator Precedence Not Highest Precedence And ampamp Or Lowest Precedence Example 2lt3 4gt5 ampamp 6gt7 HINT When in doubt use parentheses if Statement Example if xlty true BAD Redundant if x lt y BETTER Method Example if x lt V OK return true else return false return x lt y COOLER Logical Operator Example ifxltY BAD ifylt Z if xltyampampyltz BETTER TaxCalculator Example public static void mainString args Scanner console new ScannerSystemin Systemoutprint Married yn String answer consolenext boolean isMarried false if answerstartsWith y answerstartsWith Y isMarried true Systemoutprint ncome int income consolenextnt double tax calculateTaxisMarried income Systemoutprintf Tax S2fn tax public static double calculateTaxbooean isMarried int income double tax 0 if isMarried else if income lt 16000 tax 10 income else if income lt 64000 tax 1600 15 income 16000 else tax 8800 25 income 64000 if income lt 8000 tax 10 income else if income lt 32000 tax 800 15 income 8000 else tax 4400 25 income 32000 return tax NOTE Class constants should be used instead of magic numbers
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'