Monday 8 October 2018

Lab 2

For Lab 2

The Learning Outcome are:

1. Trace a program.
2. Designing solution to a problem using Problem Analysis Chart (PAC) and Input Process Output Chart (IPO).
3. To write, compile and run a simple computer program based on IPO.

So,For the first question,we need to trace a program line by line;
we need to trace the line number,variable and output.

Here is the example for one of the tracing program.



Trace 1 
1. public class ComputeArea {
2. public static void main(String[] args){
3. double radius;
4. double area;
5. radius = 20;
6.
7. area = radius * radius * 3.14159;
8.
9. System.out.println("Area of circle with radius " + radius + " is " + area);
10. }
11. }

LINE NUMBER
RADIUS
AREA
OUTPUT
5
20


7
20
1257

9
20
1257
Area of Circle with radius 20 is 1257

Then,we need to run program where we need to change value of money entered into ringgit and sen.
After a few times trying,i'm able to run the program,

The Source code:


when we run the program ;


it will display the money in ringgit and sen.


For the next question,we need to calculate BMI of a person when we enter the weight in pound and height in inches

The source code:

When we run the program,it will automatically calculate the BMI for a person.










No comments:

Post a Comment