Programming Fundamentals I CS 110, Fall 2016, Central Washington University 9/21/2016 Today ... Syllabus Textbook Clickers Labs Final project Course Objective The Sandwich Algorithm 9/21/20161 Course Website http://www.cwu.edu/~harrisont/cs110 9/21/20162 Starting Out with Java: From Control Structures through Objects 5th Edition Author: Tony Gaddis Pearson Publishing ISBN: 0132989999 Note: available in the bookstore or online. We will cover chapters 1-7 of the textbook. We will not be using MyProgrammingLab 9/21/20163 Lab day is Thursday. Please go to your assigned lab room. Computer Accounts for CS110 will be distributed on Thursday in lab Save your Account number and password (in your phone?) 9/21/20164 CWU adapted a new learning management system (LMS) called Canvas. A learning management system is the platform used for delivering course content to students online. Please take a minute to go through the Canvas Student Orientation. To begin using Canvas for this course, please go to the Canvas login page: http://canvas.cwu.edu and request your password, by selecting the “Don't know your password" link. Enter your cwu email address, then select 'request password'. You will receive a link to set-up your password in your email. To login to Canvas return to the login page, enter your cwu username (ex. smithj) and the password you just created. *If you do not receive an email call the Canvas 24/7 help line 1-877-399-8897 and they can give you a temporary password. Bookmark this page so you can access it more quickly in the future. Use "What if" feature regularly. 9/21/20165 Text Tatianaharri141 to 37607 9/21/20166 Powered by PollEverywhere.com When you're done, reply LEAVE Poll test Question … you first question (it’s OK if some of you don’t have a texting phone) A. I am planning CS major B. I am planning CS minor C. My major is not CS Which of the following applies to you? 9/21/20167 Poll test Question … you second question (it’s OK if some of you don’t have a texting phone) A. I am an experienced programmer B. I had a medium exposure to programming C. I had very little experience with programming D. I have no experience with programming E. I have no computer experience at all Which of the following applies to you? (any computer language) 9/21/20168 Poll test Question … you second question (it’s OK if some of you don’t have a texting phone) A. I am an experienced programmer B. I had a medium exposure to programming C. I had very little experience with programming D. I have no experience with programming E. I have no computer experience at all Which of the following applies to you? (Java) 9/21/20169 Poll test Question … you second question (it’s OK if some of you don’t have a texting phone) A. I am an experienced programmer B. I had a medium exposure to programming C. I had very little experience with programming D. I have no experience with programming E. I have no computer experience at all Which of the following applies to you? (C++) 9/21/201610 9/21/201611 A non-trivial program, of your choice 9/21/201612 Students will be introduced to the basic concepts of problem solving using the Java programming language. Basic control structures, primitive types, classes, objects and methods, and algorithm development will be taught. Machine architecture and operating system concepts will be briefly discussed. Will you learn how to “code”? Is learning how to code the main objective? Will you learn how to solve problems using a computer program? Is learning how to write a computer program to solve a problem the main objective? 9/21/201613 How much should I study? 2 hours for each lecture hour is recommended. Is this course difficult or easy? 9/21/201614 9/21/201615 9/21/2016 16 9/21/201617 Sandwich Algorithm video The word comes from the name of the 9th century Persian Muslim mathematician Abu Abdullah Muhammad ibn Musa Al-Khwarizmi The word algorithm originally referred only to the rules of performing arithmetic using Hindu-Arabic numerals The use of the word evolved to include all definite procedures for solving problems or performing tasks. 9/21/2016 18 What is an algorithm these days? If you use a computer or any computer-based device (like a cell phone or iPod), you're using algorithms all the time. It is an ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time. That's a mouthful! But what does it mean? It will be easier to understand if we break it into four parts: An ordered sequence Unambiguous and well-defined instructions Performs some task Halts in finite time All computer programs, or applications (a.k.a. apps), are made using algorithms. OK, so what is an algorithm? 9/21/201619 Let's see what each step means, using a task that many of us perform - making a peanut butter and jelly sandwich. We will write an algorithm to make a sandwich, using the ingredients that we've been given. 9/21/201620 That's not so bad, is it? Dictionary.com defines a sequence as "the following of one thing after another". So, in our sequence, we follow steps to make a peanut butter and jelly sandwich, and follow one step with another step. The fact that our sequence is ordered just means that the steps must be followed in order. For example, when making a peanut butter and jelly sandwich, these steps must be completed in order: Take the lid off of the jar of peanut butter. Put your knife into the peanut butter … (If you do not complete those steps in order, you may find yourself trying to put your knife through the lid…. Not a good idea! You could ruin a good knife, and if you cut through the lid, your peanut butter will not stay fresh.) 9/21/201621 It is an ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time. So, unambiguous would mean that the step is NOT open to or having several meanings. In a computer program each step must have only one meaning, or the program will not work properly! Let's see what an ambiguous instruction might look like in our peanut butter and jelly example: • Take the lid off of the jar. This may be a good instruction if we were making a plain peanut butter sandwich, and there was only one jar involved. • But if you have a jar of peanut butter and a jar of jelly, which one would you open if you saw that step? You wouldn't know which one to open, would you? So, to make that step unambiguous, let's make it well-defined: • Take the lid off of the jar of peanut butter. Not hard at all - you just have to make sure to be clear when you write your steps, and provide enough information. To understand this, you need to know what unambiguous means. Dictionary.com defines ambiguous as "open to or having several possible meanings or interpretations". 9/21/201622 It is an ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time. 9/21/201623 In our example, the task is to make a peanut butter and jelly sandwich. This may seem obvious, but you must always know what task you want to perform before you can start making an algorithm. You may have heard the saying "begin with the end in mind". That is good advice when creating an algorithm. If you don't know that your task is to make a peanut butter and jelly sandwich, you could have all of the steps, but wouldn't know the correct order to put them in. 9/21/201624 It is an ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time. This simply means that you must decide when your algorithm halts (or ends). You may say that the algorithm halts when the peanut butter and jelly sandwich is ready, but it may not be that simple. For some people, the algorithm ends when the two slices of bread are put together. For other people, the algorithm ends when the sandwich is sliced into two halves. And will your algorithm end when the sandwich is done, or will it end after you have returned the peanut butter to the cupboard, the jelly to the refrigerator, the bread to the bread box, put the knife in the dishwasher, and cleaned the countertop? All of these answers are acceptable, but you must be able to define when the algorithm ends so you can include all of the necessary steps. 9/21/201625 It is an ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time. Algorithms: Have a starting point Have Input Process something Have output Have a stopping point We've now broken down the definition of an algorithm as "an ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time". As you create computer algorithms, you should know the characteristics of algorithms. Inputs Outputs 9/21/201626 Using our peanut butter and jelly sandwich example: A starting point - the peanut butter, jelly, bread, and knife are on the counter. Input - peanut butter, jelly, and bread. Processes something - puts peanut butter and jelly on bread and puts the two slices together. Has output - the sandwich. Has a stopping point - the sandwich is made, the peanut butter, jelly, and bread are put away, and the knife is in the dishwasher. 9/21/201627 9/21/201628 9/21/201629 Q. Was it “easy” to write the algorithm? To execute it? Q. Do you wish there had been a more precise “vocabulary” you could have used? Q. Did something go wrong? Now that we have a good idea of what an algorithm is, we will be making ones that will work on a computer. 9/21/201630 Tomorrow is our first lab ... Due day before the next lab, by 11:59pm 20% extra credit for submitting you labs during a lab hour in person Computer Accounts for CS110 will be distributed in lab Make sure that the two files (HelloWorld.java and hw1.txt) are saved in you CS110 account (for backup) and uploaded to Canvas jGRASP is available free-of-charge for download onto your computer. See the course website for a link to jGRASP and other IDEs. ( http://www.jgrasp.org ) You need the java compiler (which is part of the Java Development Kit (JDK)) installed on your computer in addition to java, to be able to compile code on your own computer. Details about JDK are also on the course website. 9/21/201631 You'll be using Canvas in this course to submit assignments. There, course announcements will also be posted. Each of you has a Canvas account. To Log in: 1.Go to the Canvas login page: http://canvas.cwu.edu 2.Select the “Don't know your password” link to request an initial password. 3.Enter your CWU email address 4.(studentExample@cwu.edu) and select “request password” 5.You'll receive an email with a link to set up your password. 9/21/201632 Why Program Computers are …Hardware AND Software A Program is … Elements of a Program Compiling, errors, etc. Programming Process 9/21/201633