Call Now: (800) 537-1660

 Depdendent Variable

 Dependent Variable

 Number of inequalities to solve: 23456789
 Ineq. #1:
 Ineq. #2:

 Ineq. #3:

 Ineq. #4:

 Ineq. #5:

 Ineq. #6:

 Ineq. #7:

 Ineq. #8:

 Ineq. #9:

 Solve for:

December 10th

December 10th

# PROBLEM SOLVING USING ALGORITHMS and FLOWCHART

An ALGORITHM is a step-by- step process for solving a problem. Using your
internal knowledge and acquiring external knowledge solves a problem. There
are many different ways of solving a problem. Look around. Your friends have
different way of earning their income, driving a car, scheduling his/her classes,
and etc. Therefore, we all have our own Algorithm to earn income or drive a car.

ALGORITHM DEVELOPMENT

When developing an algorithm, it’s important to analyze all of the requirements
involved with that part of the problem. This ensures that the algorithm takes into
account all aspects of the problem. The de sign of a program is often revised
many times before it is finalized.

Implementation is the process of writing the source code that will solve the
problem. This is the act of making the design to work.

Testing a program includes running it and making sure that it works. There are
two types of errors, programming language error and the logical error that is
an error on the logic of the algorithm. The first error is normally handled through
the compiler of the language. After running the program, a list of errors and their
description is given. The correctness of the logic of the program requires to
running multiple times with various input data and carefully examining the
results. Testing might include hand-tracing program code, in which the developer
mentally plays the role of the computer to see where the program logic goes for a
given set of input data. If the result matches with expected result then the logic is
correct, otherwise; there are logical errors.

For example, to give direction to your new friend to come to your house, there are
many algorithms. One is to drive from your friend’s house to your house and
write done the name of streets and the mileage to create a step-by-step procedure
for driving from one location to another. Another algorithm might be to look at
the map and develop such step-by-step procedure. Another algorithm might be to
all, if your friend won’t find your house, the algorithm has logical error. If your

Practice a:

Evaluate the following Algorithm whether it is correct. Find programming
language error and the logical error.

Direction from Bob’s house on rout 45to White Hall:

1. Make left from the parking lot.
2. Come to the first steppppsign.
3. Make left to rout 45.
4. Drive 1.2 mile on rout 45.
5. Make right to rout 480.
6. Drive .3 miles.
7. Make right to Higggg street.
8. Drive on High street for .5 miles.
9. White Hall is on your left hand side.

AUTOMATION PHASES

We use computer programs to do our job or to solve a problem. The user of the
computer runs a computer program, which is called Software. A Software
Engineer is the person that develops the software and is also known as computer
to understand and develop a good design. After the design process is completed
then the programmer writes the program in a programming language following a
set of syntax rules that represents the grammar of the language. The writing of
computer instructions is called coding and the written program is known as
source code or simply code.

Programming development consists of four phases:

I. Specification: Collecting the requirements.
II. Design: Developing the design using flowchart.
III. Algorithm: Writing the step-be-step instructions.
IV. Tracing: Testing the logic of the program.

I. Specification
Requirements often address the input data, output data, standards, formulas,
formatting, and graphical interface. Normally these requirements are stored in a
database called Dictionary. Following is how we can store variable specification .

 Variable Name Description Type Range/Value

For example, suppose we are writing a program to read employee’s information
and to print a list of labels. The dictionary information is as follows:

 Variable Name Description Type Range/Value name employee’s name Text 50 char street Street name Text 20 char zipCode Zip Code int 0-99999 state state Text 2 char

II. Design, using Flowchart

Any system without a design has no guarantee of success. A civil engineer would
never consider building a bridge without designing it first. Developing an
automated system is no exception. Every automated system implements many
programs. A program is consists of one or more algorithms. A good programmer
spends time thinking about the algorithms involved before writing a code.
An algorithm is often described using flow charting symbols .

What is Flowchart: Flowchart shows the step-by-step process using pre-defined
symbols. Flowchart provides enough structure to show how the code will operate
without getting involved with any program languages.

A list of Flow Chart Symbols is as follows:

A terminal symbol is always the first and the last symbol in any flowchart. As
the first symbol it contains the name of a module and as last contains the word
‘End’.

A processing symbol is used for equations.

III. Algorithm

As we discussed in chapter 3, every language has a list of built-in methods and a
list of user-developed methods. We learned about System and JoptionPane
class. These two classes have many methods to talk to user. Followings are two
more classes, Format and String classes.

FORMATTING

By default, the Java displays the variables in the format that matches the data
type. Integer values , for example, are normally displayed in decimal form. To
change the display format, we can use the methods in NumberFormat class .

This class provides generic formatting for numbers. The principal methods of this
class are getPercentInstance and getCurrencyInstance. Rather
than instantiating an instance using the new operator, one calls a method of the
class.

 Libraryimport java.text.NumberFormat;

NumberFormat getPercentInstance returns a NumberFormat object
that represents a percentage format for the current locale.

NumberFormat getCurrencyInstance returns a NumberFormat object
that represents a currency format for the current locale.

 Example Codedouble cost=10.55, discount = .10; NumberFormat money = NumberFormat.getCurrencyInstance(); System.out.println(“Cost = “+ money.cost); NumberFormat percent = NumberFormat.getPercentInstance(); System.out.println(“Discount = “+percent.discount);

Practice a.

Mary Roman bought a new car. Write a program to ask Mary the style, color,
price, and amount of down payment. Calculate what percent of the total price was
down payment. Call this variable percentDownPayment. Display the information
including percentDownPayment in JoptionPane window.

DECIMAL FORMAT

This class formats numeric outputs in defined patterns. It is instantiated using the
new operator. Examples of the methods in this class are:

 Libraryimport java.text.DecimalFormat;

DecimalFormat (String pattern) – this methods constructs a new decimal
format. For example, “0.###” would instruct the program to return a number with
three significant digits and at least a 0 to the left of the decimal.

 Example Codedouble area=10.55656554; DecimalFormat twoDecimal = new DecimalFormat(“0.##”); // display the area with two decimal digits. System.out.println(“Area = “+ twoDecimal.format(area));

Practice b.

Write a program to read two decimal numbers. Calculate the quotient of two
numbers (divide the two numbers.) Display the numbers and the quotient both
on System and JoptionPane window. Make the display message user friendly
such as follow:

First number =
Second number =
Quotient =

III. Tracing

To test the program and validate the result, we need to trace the logic using real
numbers. Suppose a program reads the radius of a circle and calculates the area
and circumference. Following is the three phases:

I. Specification: Read the radius of a circle. Calculate the area and
circumference. Variable descriptions are as follow:

 Variable Name Description Type Range/Value radius radius of circle double positive area area of circle double positive circumference perimeter double positive

II. Design:

III. Algorithm

 circleDemoimport javax.swing.*; import java.text.DecimalFormat; import java.math.*; public class circleDemo { double raduis, area, circumference; DecimalFormat twoDecimal = new DecimalFormat("0.##"); public circleDemo() { String textRaduis = JOptionPane.showInputDialog("Please enter a number for raduis"); raduis = Double.parseDouble(textRaduis); area = Math.PI * Math.pow(raduis,2); circumference = 2 * Math.PI * raduis; // build result String result = "Raduis= "+raduis +"\nArea = "+twoDecimal.format(area) +"\nCircumference= "+twoDecimal.format(circumference); // display the informtion in System window System.out.println("\n\t"+result); // display the information in JOptionPane window JOptionPane.showMessageDialog(null,result); } public static void main(String[] args) { circleDemo application = new circleDemo(); } }

IV. Tracing

When we run the program, for radius of 4 the area and circumference must
be these numbers.

QUESTIONS AND PROJECTS

KEYWORDS
• Four phases of automation
• NumberFormat
• DecimalFormat

QUESTIONS
1. How can we truncate a decimal number to three decimal digits?

Project1: Jessica Kinzer has a designer clothing store called “Jessica Kinzer
Designer Clothing.” She keep the sales by sales person name and their first,
second, third, and fourth quarter sales. She is interested in an automation system
that can ask for sales person name and their sales for each quarter. She is also
would like to see the total sale for that person. Develop the system and show the
four phases of the automation.

An example of data:

Salesperson 1st Qtr 2nd Qtr 3rd Qtr 4th Qtr
Simon 50000 78000 99000 95000

Total for Simon= 322000

I. Specification

 Variable Name Description Type Range/Value

II. Design:

IV. Algorithm

IV. Tracing

 Prev Next