03 - CS133 Developing Programming Principles Lecture 3...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS133: Developing Programming Principles Lecture 3 Programming Style, Boolean Expressions, If Statements 2 CS133 Course Notes Lecture 3, Slide 2 Documentation and style Make sure you use meaningful variable names. – classes, variables: noun phrases – methods: verb phrases Add comments to make your code easier to understand (i.e., use English) Add comments to your program to identify who wrote it, what it does, etc.
Image of page 1

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

View Full Document Right Arrow Icon
3 CS133 Course Notes Lecture 3, Slide 3 Commented example import java.util.*; /** Hello program * @author Student McStudentson * @version 2 * Get the name of the user and output it along with a greeting. */ public class Example { public static void main (String[] args) { // Set up keyboard input Scanner myScanner = new Scanner(System.in); // Input name System.out.println("Enter your first name: "); String name = myScanner.nextLine(); System.out.println("Hello, " + name + "!"); } } 4 CS133 Course Notes Lecture 3, Slide 4 Programming style tips { and } should line up in the same column – DrJava does this for you! (<tab> key) Place one instruction per line. Use whitespace to separate code blocks – Briefly comment each code block Comment and format code as you program
Image of page 2
5 CS133 Course Notes Lecture 3, Slide 5 if - else statements Formal definition: A statement which allows a program to choose an action depending on the value of a boolean expression. Example in plain English: If the temperature is greater than zero it will rain. Otherwise, it will snow.
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern