Professional Documents
Culture Documents
MISY 2312:
Introductory Programming
for Information Systems
Dr. Washah
1
Chapter 2
Chapter 2
Problem Solving
Chapter 2
Computer Language Levels
4
Chapter 2
5
Chapter 2
6
Chapter 2
8
Chapter 2
9
Chapter 2
12
Chapter 2
1. corrective maintenance
2. enhancement maintenance
3. forced maintenance.
13
Chapter 2
Problem Abstraction
Abstraction provides for
generalization in problem solving by
allowing you to view a problem in
general terms, without worrying
about the details of the problem
solution.
14
Chapter 2
Stepwise Refinement
Stepwise refinement is the process of
gradually adding detail to a general
problem solution until it can be easily
coded in a computer language.
15
Chapter 2
Software development cycle
Problem
Develop a set of algorithms and class diagram to calculate
the gross pay for a for a student working part time (less
than 40 hours a week). Assume that the student will enter
his/her hourly rate of pay and number of hours worked in
a given week. Make sure that the report shows the student
name and date.
17
Chapter 2
18
Chapter 2
Initial Algorithm
main()
BEGIN
Read the rate, hours, name, and date from the user.
Calculate the gross pay.
Write the payroll report to the user.
END.
19
Chapter 2
First Level of Refinement
setData()
BEGIN
Write a user prompt to enter the student name.
Read name.
Write a user prompt to enter the date.
Read date.
Write a user prompt to enter the hourly rate of pay.
Read rate.
Write a prompt to enter the number of hours worked.
Read hours.
END.
20
Chapter 2
irst Level of Refinement (cont.)
calculatePay()
BEGIN
Set grossPay = rate * hours.
END.
getData()
BEGIN
Write name.
Write date.
Write rate of pay.
Write hours worked.
Write gross pay.
END.
21
Chapter 2
main()
A problem solution diagram for the sales tax problem shows the abstract analysis
and stepwise refinement required for solving complex problems.
22
Chapter 2
StudentPayroll
name
date
rate
hours
grosspay
setData()
calculatePay()
getData()
A class diagram for the SalesTax class shows the data and method members
that make up the class.
23
Chapter 2
24
Chapter 2
Fundamental Building Blocks of
Programs
• There are two basic aspects of
programming: data and instructions. To
work with data, you need to understand
variables and types; to work with
instructions, you need to understand
control structures and subroutines. You'll
spend a large part of the course becoming
familiar with these concepts.
25
Chapter 2
• A variable is just a memory location (or
several locations treated as a unit) that has
been given a name so that it can be easily
referred to and used in a program. The
programmer only has to worry about the
name; it is the compiler's responsibility to
keep track of the memory location. The
programmer does need to keep in mind that
the name refers to a kind of "box" in
memory that can hold data, even if the
programmer doesn't have to know where in
memory that box is located.
26
Chapter 2
27
Chapter 2
Programming languages always have
commands for getting data into and out of
variables and for doing computations with
data.
• interest = principal * 0.07;
28
Chapter 2
29
Chapter 2
30
Chapter 2
Objects and Object-oriented
Programming
• During the 1970s and into the 80s, the
primary software engineering methodology
was structured programming.
31
Chapter 2
32
Chapter 2
33
Chapter 2
34
Chapter 2
Objects and Methods
1-38
Chapter 2
System.out.println
40
Chapter 2
/*
* TestStudentPayroll.java
*
* Created on April 21, 2002, 8:51 AM
*/
/**
import StaugIO Class for GUI I/O
*
* @author Andrew C. Staugaard, Jr.
* @version 1.0
*/ StudentPayroll Class
import staugIO.StaugIO; //FOR IO
class StudentPayroll
{
String name = ""; //STUDENT NAME
String date = "mm/dd/yyyy"; //PAYROLL DATE
private double rate = 0.0; //HOURLY RATE Class Data
private double hours = 0.0; //WEEKLY HOURS
private double grossPay = 0.0; //WEEKLY GROSS PAY
private StaugIO io = new StaugIO(); //INPUT/OUTPUT OBJECT
//calculatePay() METHOD
public void calculatePay()
{
grossPay = rate * hours;
}//END calculatePay() Class Methods
//getData() METHOD
public void getData()
{
io.writeInfo("Student: " + name
+ "\nDate: " + date
+ "\nRate: $" + rate
+ "\nHours: " + hours
+ "\nGross Pay: $" + grossPay);
}//END getData()
}//END StudentPayroll CLASS
44