Popular in Course
verified elite notetaker
Popular in Department
This 6 page One Day of Notes was uploaded by Wenbiao Feng on Wednesday September 10, 2014. The One Day of Notes belongs to a course at a university taught by a professor in Fall. Since its upload, it has received 106 views.
Reviews for IST256.pdf
Loved these! I'm a horrible notetaker so I'll be your #1 fan this semester
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: 09/10/14
1 1 Three structures in structured programming Name condition and decision sequences iteration Define conditions while something still going on while not going on Decision if then else if then that if statement Sequences everything go with sequences Iteration how many times you do something Variables Identify types integer double Boolean String int integer numbers 7 1 O 1 2 a 789 double decimal numbers 65 1998 1734 boolean the two values true and false String example values are Hello quotThis is a message Retweet hcr Declare variables int num double num String name int age numl num2 double gpa payAmount payRate String studentNa me boolean flag Assignments Writing statements always has equal variable value variable expression An actual value IQ 115 The value of another variable yourQ myQ The result of a computation yourQ myQ 40 int counter 0 double totaPrice 00 Counters a counter counts N Accumulators accumulates it always has a particular format total total 5 3 If statements When to use if this then else if ngt5 ese you want to make a decision based on the values of the variables and select different courses of action based on that Code if height gt 22 Systemoutprintn Ta Else Systemoutprintn Short double total total total is assigned a value or one from input if total gt 500 total total total 010 Interpret code Equal to Tf double Boolean Empcode O equab 4 String strequa1s abc Not equal to Number 0 Nested if statements if PayStatusequalsquotHourlyquot if hours gt 40 pay payrate40 15payratehours 40 else pay payratehours else pay payrate40 4 Loops Iteration or looping is used when the program needs to repeat the same operations a number of times When to use for when we know how many times we want to repeat the statements When to use while when you don39t know how many times also called an indeterminate loop because we don39t necessarily know how many times we are going to execute the loop Code for initialization termination increment some statements Supposethat we want to sum the numbers from 1 to 100 int sum O for int i 1 i lt 100 i sum sum i sums the odd numbers between 1 and 15 int oddsum O forinti1 ilt15ii2 oddsum oddsum i The index variables can be named anything for int index 1 index lt 10 index sum sum index while condition some statements Suppose that we want to see how many integers we have to sum in order to sum up to a 1000 int sum 0 int i 1 while sum lt 1000 sum sum i i I the value of i is the final number of those that were summed Interpret code 5 Scope a variable is local to a block if it is declared in that block and it is global to a block if it is declared outside that block How global or local it is Local inside of the for loops while loops or anything else Global after the first public class Interpret code Controlling Access to Class Variables and Methods In a class definition we sometimes want to make variables and methods accessible outside the normal scope of the class definition But this can be controlled by the scope keywords also called the access keywords 0 public the variable or method can be used by any other program outside the class 0 ltno keywordgt when the keyword is omitted this is packageprivate and the variable or method can be used anywhere inside this package except for subclasses 0 protected the variable or method can be used anywhere inside the package including subclasses 0 private the variable or method can only be used inside this class Variables Write a declaration statement to declare num1 and initialize to 32 double num1 32 counter n n also means nn1 accumulator totatota5 sequence int num1 num2 total num1 3num2 total num1 2 easier way to write numnum1 num Assignments given the follow identify the counter for int xO xlt33 x dogagedogage7 x if statements write a nested if statement where if height less than 64 it prints short height greater than 72 it prints short tall and anything in between is average if height gt72 Systemoutprintn ta else if loops explain what is happening with the following code cost300 items20 while costgt50 ampamp items gt12 for start stop increment for int i0 I lt 30 i 3 structures in programming sequence decision iteration Interation means for loops and while loops how many times you do something Decision Sequence
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'