1 An Example. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian Rules Football field, which.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Computer Programming Lab(7).
Program Design. Objectives Students should understand the basic steps in the programming process. Students should understand the need for good design.
Static Methods Chapter 4. Chapter Contents Objectives 4.1 Introductory Example: Old MacDonald Had a Farm … 4.2 Getting Started with Methods 4.3 Example:
Hand Crafting your own program By Eric Davis for CS103.
Scanner Pepper With credits to Dr. Siegfried. The Scanner Class Most programs will need some form of input. At the beginning, all of our input will come.
Classes, methods, and conditional statements We’re past the basics. These are the roots.
Computer Programming 1 Problem Solving and Software Engineering.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
Begin Java having used Alice Pepper - Some slides from Alice in Action with Java.
1 Algorithms and Problem Solving. 2 Outline  Problem Solving  Problem Solving Strategy  Algorithms  Sequential Statements  Examples.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
CS 117 Section 2 + KNET Computer accounts – ed to KNET students –Change password Homework 1 Lab Tutors –In lab for next 2 weeks –Will help you with.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
Chapter 1 Pseudocode & Flowcharts
Software Engineering 1 (Chap. 1) Object-Centered Design.
Computer Programming Lab(4).
JAVA Control Structures: Repetition. Objectives Be able to use a loop to implement a repetitive algorithm Practice, Practice, Practice... Reinforce the.
1 4.3 Example: Volume of a Sphere Given the radius r, what is the weight of a ball (sphere) of wound twine?Given the radius r, what is the weight of a.
1 Programming and Problem Solving — Software Engineering (Read Chap. 2)
Programming and Problem Solving — Software Engineering (Read Chap. 2) 1.
The Rectangle Method. Introduction Definite integral (High School material): A definite integral a ∫ b f(x) dx is the integral of a function f(x) with.
CSC 204 Programming I Loop I The while statement.
Copyright © Curt Hill Mathematics Functions An example of static methods.
Libraries Making Functions Globally Reusable (§ 6.4) 1.
1 Debugging. 2 A Lot of Time is Spent Debugging Programs Debugging. Cyclic process of editing, compiling, and fixing errors. n Always a logical explanation.
How to start Visual Studio 2008 or 2010 (command-line program)
1 Chapter-01 Introduction to Software Engineering.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Methods (a.k.a. Functions)
Libraries 1 Making Functions Globally Reusable (§ 4.6)
1 Simple Functions Writing Reuseable Formulas. In Math Suppose f (x) = 2 x 2 +5Suppose f (x) = 2 x 2 +5 f(5)=?f(5)=? f(5) = 2* =55f(5) = 2*
1 An Example. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian Rules Football field, which.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
Static Methods. 2 Objectives Look at how to build static (class) methods Study use of methods calling, parameters, returning values Contrast reference.
Even more problems.. Mean (average) I need a program that calculates the average of student test scores. I need a program that calculates the average.
1 Chapter-01 Introduction to Software Engineering.
1 Simple Methods Chap. 4 Study Sections 4.1 – 4.4 Writing Reusable Formulas.
COM S 207 Method Instructor: Ying Cai Department of Computer Science Iowa State University
UFCEKS-20-2Multimedia Authoring Times Table Quiz.
Software Engineering Object-Centered Design. Problem Solving Does anyone scuba dive? Let’s solve this scuba-diving problem: Write a program that, given.
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Java Variables, Types, and Math Getting Started Complete and Turn in Address/Poem.
The Math class Java provides certain math functions for us. The Math class contains methods and constants that can be very useful. The Math class is like.
Formatted Output (printf) CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Problem Session Working in pairs of two, solve the following problem...
1 Controlling Behavior Chap.5 Study Sections 5.1 – 5.3 The if and for Statements.
Simple Functions Writing Reuseable Formulas. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian.
1 Simple Methods Chap. 4 Study Sections 4.1 – 4.4 Writing Reusable Formulas.
UFCFY5-30-1Multimedia Studio Scripting for Interactive Media Times Table Quiz This will contribute towards your online portfolio for this module.
1 Chapter-01 Introduction to Software Engineering.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Parameter Passing in Java.
Libraries 1 Making Functions Globally Reusable (§ 6.4)
Invoking methods in the Java library. Jargon: method invocation Terminology: Invoking a method = executing a method Other phrases with exactly the same.
1 Project 4: Computing Distance. 222 Computing Distance Write a program to compute the distance between two points. Recall that the distance between the.
The if-else statement. Introducing the if-else statement Programming problem: Re-write the a,b,c-formula program to solve for complex number solutions.
Software Engineering (Chap. 1) Object-Centered Design When we prepare a program, the experience can be just like composing poetry or music … My claim is.
TOPIC 8 MORE ON WHILE LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
Arrays Chap. 9 Storing Collections of Values 1. Introductory Example Problem: Teachers need to be able to compute a variety of grading statistics for.
Introduction to Programmer-Defined Functions
Writing Reuseable Formulas
solve the following problem...
Something about Java Introduction to Problem Solving and Programming 1.
Multiplying and Dividing Powers
Introduction to Robots and the Mind - Methods -
Writing Methods.
Command Line Arguments
Subprograms Functions.
Object-Centered Design
Presentation transcript:

1 An Example

Problem Using OCD, design and implement a program that computes the area and circumference of an Australian Rules Football field, which is an ellipse that is (ideally) 165m x 135m

Problem Generalization Using OCD, design and implement a program that computes the area and circumference of an ellipse. a a bb 3

Behavior 4 Our program should display on the screen a prompt for the major axis and minor axis. It should then read the major axis and the minor axis from the keyboard. It should then compute and display the ellipse’s area and circumference along with a descriptive label.

Objects 5

Operations 6

7 Representing Objects Description Java Type Kind Name program new class -- ____________ screen Screen variabletheScreen prompt String constant--none-- major axis double variable ____________ minor axis double variable ____________ keyboard Keyboard variabletheKeyboard area double variablearea circumference double variablecircumference

Performing Operations Description Built-in/ClassName display a string Screen ______________ read a double Keyboard ______________ compute area compute circumference display doubles Screen ______________ 8

Algorithm 1. Ask theScreen to display a prompt for the length and width of an ellipse. 2. Ask theKeyboard to read majorAxis, minorAxis. 3. Compute area 4. Compute circumference. 5. Display area and circumference with descriptive labels ba circumference   abarea   a a bb

Representing Objects Description Java Type Kind Name program new class -- Ellipse screen Screen variabletheScreen prompt String constant--none-- major axis double variablemajorAxis minor axis double variableminorAxis keyboard Keyboard variabletheKeyboard area double variablearea circumference double variablecircumference π double _____________________ half major axis double _____________________ half minor axis double _____________________ 10

Performing Operations Description Built-in/ClassName display a string Screenprint() read a double KeyboardreadDouble() compute area – multiply doublesbuilt-in * compute circumference – multiply doublesbuilt-in * – add doublesbuilt-in + – divide doublesbuilt-in / – power__________ _____________ – square root__________ _____________ display doubles Screenprintln() 11

Algorithm 0. Ask theScreen to display a prompt for the length and width of an ellipse. 1. Ask theKeyboard to read majorAxis, minorAxis. 2. Compute semiMajor = majorAxis /2.0; semiMinor = minorAxis / Compute area ______________________________ 4. Compute circumference __________________ ____________________________________ 5. Display area and circumference with descriptive labels ba circumference   abarea   a a bb

Coding 13 /* Ellipse.java computes an ellipse's area and circumference. * Input: Ellipse's length and width * Output: Ellipse's area and circumference */ import ann.easyio.*; // Keyboard, Screen class Ellipse { public static void main(String [] args) { _______________________________________________________________ Keyboard theKeyboard = new Keyboard(); theScreen.print("To compute the area and circumference of an " + "ellipse,\n\tenter its major & minor axes: "); _______________________________________________________________ double minorAxis = theKeyboard.readDouble(); _______________________________________________________________ double semiMinor = minorAxis / 2.0; double area = ___________________________________________________ double circumference = 2.0 * Math.PI * Math.sqrt( ( Math.pow(semiMajor, 2) + Math.pow(semiMinor, 2) ) / 2.0 ) ; theScreen.println("\nThe area is " ______________________ "\nand the circumference is " __________________); }

Execution & Testing First execute it with some values for which the results are easy to check by hand: To compute the area and circumference of an ellipse, enter its major & minor axes: 2 2 enter its major & minor axes: 2 2 The area is and the circumference is To compute the area and circumference of an ellipse, enter its major & minor axes: 8 6 enter its major & minor axes: 8 6 The area is and the circumference is

When you are convinced of the program's correctness, execute it with the required inputs: To compute the area and circumference of an ellipse, enter its major & minor axes: enter its major & minor axes: The area is and the circumference is