Digesting a big problem ONE BYTE AT A TIME. Quiz YOU WILL WORK WITH YOUR PARTNER (LAB PARTNER NOT FULL TEAM). FOR SOLOISTS OR THOSE WHOSE PARTNER IS NOT.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Intro to CS – Honors I Control Flow: Loops GEORGIOS PORTOKALIDIS
BBS514 Structured Programming (Yapısal Programlama)1 Functions and Structured Programming.
Lecture 2 Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Chapter 4 - Control Structures: Part 1 Outline 4.4Control Structures 4.5The if Selection Structure 4.6The if/else Selection Structure 4.7The while Repetition.
Introduction to Computers and Programming More Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Basic Input/Output and Variables Ethan Cerami New York
Topic 4 – Programmer- Defined Functions. CISC 105 – Topic 4 Functions So far, we have only seen programs with one function, main. These programs begin.
Using Java's Math & Scanner class. Java's Mathematical functions (methods) (1)
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
General Programming Introduction to Computing Science and Programming I.
Java Programming: From the Ground Up
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
1 Special Programming Workshop CSIT-120 Fall 2000 Workshop Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Variables, Arithmetic, etc.)
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
Program #2 Algorithm for Parking at PSU. Understanding the Assignment You will be writing a program to find out how much someone at PSU might be spending.
Catie Welsh February 7,  Grades ◦ Lab 2, Project 1 Grades are now on Blackboard 2.
1 Romelia Plesa, Alan Williams, Sylvia Boyd, Daniel Amyot, Diana Inkpen, Gilbert Arbez, Mohamad Eid ITI 1120 Lab #3.
1 Chapter 2: Java Fundamentals cont’d Spring Lory Al Moakar.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
 2003 Prentice Hall, Inc. All rights reserved. 1 Will not cover 4.14, Thinking About Objects: Identifying Class Attributes Chapter 4 - Control Structures.
Midterm 2 Review. Stars and why we use nested loops  Matrix problems (stars)  Other problems involving multiple dimensions  Loops within a process.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Beginning C For Engineers Fall 2005 Lecture 3: While loops, For loops, Nested loops, and Multiple Selection Section 2 – 9/14/05 Section 4 – 9/15/05 Bettina.
1 Project 4: Computing Distance. 222 Computing Distance Write a program to compute the distance between two points. Recall that the distance between the.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Lecture 5: Layers of Control. Nested while Loops Problem Multiplying two numbers and outputting the result only if they are both less than 5. (i.e. Start.
IT CS 200: R EPEATATION Lect. Napat Amphaiphan. T HE ABILITY TO DO THE SAME TASK AGAIN BY AGAIN UNTIL THE CONDITION IS MET LOOP 2.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
1 float Data Type Data type that can hold numbers with decimal values – e.g. 3.14, 98.6 Floats can be used to represent many values: –Money (but see warning.
As you come in Take a whiteboard, markers, folder, name tags to your section area. Leave the folders closed.
User-Written Functions
MATLAB – More Script Files
Chapter 2 More on Math More on Input
Chapter 2 Assignment and Interactive Input
Variables, Expressions, and IO
Number and String Operations
Programming Funamental slides
CSCE 206 Lab Structured Programming in C
Programming Funamental slides
MSIS 655 Advanced Business Applications Programming
Chapter 4 Loops While loop The for loop do… while break and continue
Seating “chart” Front Back 4 rows 5 rows 5 rows 4 rows 2 rows 2 rows
Unit 3: Variables in Java
Chapter 2: Java Fundamentals cont’d
CSCE 206 Lab Structured Programming in C
Introduction to C Programming
CHAPTER 6 Testing and Debugging.
Presentation transcript:

Digesting a big problem ONE BYTE AT A TIME

Quiz YOU WILL WORK WITH YOUR PARTNER (LAB PARTNER NOT FULL TEAM). FOR SOLOISTS OR THOSE WHOSE PARTNER IS NOT HERE, PICK ON OTHER PERSON OR FEEL FREE TO WORK ALONE. YOU WILL HAVE 20 MINUTES.

Quiz Grading Pass your quiz to another team in a different section than you. As we go over each question, grade it based on the points and result.

Question 1 Which of the following is not a valid assignment statement, assuming all variables have been declared and initialized with an appropriate data type? ◦total = sum + next; ◦keyboard.nextInt() = value; ◦count = count + flag; ◦rate = 10.2;

Question 2

Question 3 WhichCar.java:44: possible loss of precision found : double required: int cost = totalCost; On what line number in the source file does this error occur? ◦Line 0 ◦Line 15 ◦Line 44 ◦It is impossible to tell from the error message provided

Question 4

Question 5 Declare a String variable named state. Then initialize the variable so it references an object with the string “Virginia”. String state; state = “Virginia”; ◦OR state = new String (“Virginia”);

Question 6 Do the following statements compute the average of double variables a, b, and c? Why or why not? Explain double average; average = a + b + c / 3.0; 1pt – NO 1pt – The c will be divided by 3 first and then that result will be added to a + b.

Question 7 Which of the following assignments are valid, given that the following variables are declared: int cost, double taxRate, float interestRate, long count a.interestRate = taxRate; b.cost = taxRate; c.count = cost; d.cost = count;

Question 8 Enclosing a group of statements inside a set of braces creates a a.block of statements b.boolean expression c.loop d.Nothing, it is just for readability

Practice - Solve a problem in pieces. In your teams, work on the following problem: The distance between any two points, (x 1 y 1 and x 2 y 2 ) can be computed by the formula: Write a program to read in from the user the point values and then compute and print the distance in the form of: The distance between (x 1 y 1 ) and (x 2 y 2 ) is XXXX.XX.

Think about this problem as a problem in 3 parts. Part 1 – Reading in the input. 1.Think about the variables you will need. (At least one variable for each individual component of the points and a Scanner) and declare them. 2.Think about how you will prompt the user. 3.Perform the read operations to load the variables. Note: if you are writing the program, you could stop here and test by “echoing” the input via a temporary println to show that the variables hold the correct values.

Part 2 Calculating the result 1.Think about any additional variables you will need and declare them up top. 2.Create the calculation. Note that while this is a single formula, you might do better by breaking it down. Two Math class methods that might be useful are Math.pow() and Math.sqrt. 3.At this point you can test to see that the calculation is working correctly. If you are using sub calculations, you can also test them by putting in additional print statements.

Part 3 – Making the format pretty Now that you have the program producing the correct result, add in print statements to display the result. Use the DecimalFormat class (another variable) if you wish or printf. If this is working correctly, you can then remove all of the unnecessary print statements that you used for testing.

Homework Finish up the work on this algorithm. You will be writing this program as one part of the work of Tuesday’s lab. There will be a weekly quiz and the focus will be on arithmetic operations.