Computer Programming Learning Objectives and Concepts Explained

introduction to computer science n.w
1 / 22
Embed
Share

Explore the world of computer programming through this comprehensive material developed by Oregon Health & Science University. Understand the purpose of programming languages, learn basic and advanced programming concepts, and delve into programming constructs such as variables, data types, and Java specifics. Enhance your knowledge of programming with clear explanations and engaging visuals.

  • Computer Programming
  • Learning Objectives
  • Data Types
  • Java
  • Programming Constructs

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Introduction to Computer Science Computer Programming Lecture c This material (Comp 4 Unit 4) was developed by Oregon Health & Science University, funded by the Department of Health and Human Services, Office of the National Coordinator for Health Information Technology under Award Number 90WT0001. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.

  2. Computer Programming Learning Objectives - 1 Define the purpose of programming languages (Lecture a) Differentiate between the different types of programming languages and list commonly used ones (Lecture a) Explain the compiling and interpreting process for computer programs (Lecture b) 2

  3. Computer Programming Learning Objectives - 2 Learn basic programming concepts including variable declarations, assignment statements, expressions, conditional statements and loops (Lectures c, d) Describe advanced programming concepts including objects and modularity (Lecture e) 3

  4. Programming Constructs Declarations (variables/constants) Assignment Statements Expressions Input and Output (I/O) Statements Control Structures Data Structures Modules Procedures Methods Objects 4

  5. Variables Variables store data Referred to by unique names Point to memory locations Data stored by a variable is its value Value is stored in the memory location Its value can be changed (i.e., variable) Similar construct for constants (value cannot change) 5

  6. Data Type Every variable and constant belongs to some data type Knows how much memory to use Knows how to handle data Common data types Integer Floating point Character Boolean 6

  7. Java Data Types Java is a strongly typed language All variables must be declared and their types specified before they can be used Java data types Primitive o int, double, float, char, boolean Class o String o Other user/library defined types 7

  8. Declaration Statements in Java Variable declarations specifies name and type; variable must be declared before use int age; Java examples double bmi; char gender; boolean completed; Note: Most Java statements end with a semicolon 8

  9. Assignment Statements An assignment statement is used to assign a value to a variable age = 42; The equal sign is the assignment operator 9

  10. Values and Expressions Values can be specified by literals such as 18 2.5 'a' Values can be specified by expressions such as weight/2 5 + age 3 + 2/5 * 15 n*m 10

  11. Arithmetic Expressions Arithmetic expressions contain operators and evaluate to a value +, -, *, / Order of evaluation is determined by precedence 1. Expressions in parentheses evaluated first 2. Then *,/ 3. Then +, - 4. Same order of precedence evaluated left to right 11

  12. Expression Examples bmi = weight / (height * height); age = age + 1; tricky = 3 + 5 * 2; What is the value of tricky after the assignment? 12

  13. Input and Output All programming languages support data input Keyboard Files All programming languages support data output Screen Files 13

  14. Screen Output in Java Output can be written using System.out.println() prints the specified string and moves the cursor to a new line System.out.print() prints the specified string and does not move cursor to a new line Code examples System.out.println("Hello World!"); System.out.print("My name is "); System.out.println(name); System.out.println(gender); 14

  15. Keyboard Input in Java Keyboard input is more complicated One way is to include packagejava.util Must create object of the Scanner class Scanner keyboard =new Scanner(System.in); Use methods in Scanner class next(); nextLine(); nextDouble(); nextInt(); Example age = keyboard.nextInt(); 15

  16. Example Write a Java program that calculates BMI (body mass index) Read in weight (kg) Read in height (m) Calculate BMI Output BMI (tom, 2009, PD-US) 16

  17. Program Design Prompt user for weight (kg) Read in weight Prompt user for height in m Read in height Calculate BMI using the formula BMI = weight/(height * height) Output BMI 17

  18. Example Java Program 18

  19. Sample Output Welcome to the BMI calculator Enter weight in kg 68 Enter height in m 1.72 BMI is 22.985397512168742 Note: Values in purple are entered by the user 19

  20. Computer Programming Summary Lecture c There are constructs common for most programming languages Variables store data and have a data type Variables can be assigned values or expressions Java provides variable declaration, assignment, and expression statements Java has input and output statements and classes 20

  21. Computer Programming References Lecture c References Eck, D. (2011). Introduction to Programming Using Java (6th ed.). Retrieved from http://math.hws.edu/javanotes/ Morley, D., & Parker, C.S. (2010). Chapter 13: Program Development and Programming Languages. In Understanding Computers Today and Tomorrow, 12th Edition introductory. Boston: Course Technology. Parsons, J.J., & Oja, D. (2010). Chapter 12: Computer Programming. In New Perspectives on Computer Concepts 2011: Comprehensive (13th ed.). Boston: Course Technology. The Java Language: An Overview. (2007, December). Retrieved March 21, 2011, from http://java.sun.com/docs/overviews/java/java-overview-1.html Sierra, K., & Bates, B. (2009). Head First Java (2nd Ed.). O Reilly Media. Images Slide 16: Bathroom scale. [image on the Internet]. User: tom. (2009, April 1). Retrieved November 12, 2011, from https://openclipart.org/detail/23591/bathroom-scale. This file has been released into the Public Domain. 21

  22. Introduction to Computer Science Computer Programming Lecture c This material was developed by Oregon Health & Science University, funded by the Department of Health and Human Services, Office of the National Coordinator for Health Information Technology under Award Number 90WT0001. 22

More Related Content