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.










Monday 1 October 2018

Lab1


For Lab1,we were supposed to;

1.Identify common errors and programming pitfalls.


2.Designing solution to a problem using Program Analysis Chart.


3.To write,compile,run a simple computer program based on Program Analysis Chart.


Into The Lab

For this Lab1,for the first part we were given class to be separated in java class and we need to the errors.Below are few examples of class of java that we need to fix the error.
One of the problem when I tried to run the java program for test 4.The java run smoothly but the answer to the question is not correct.The value of 5 divided by 2 is supposed to be 2.5 but it display only 2.This is because we use integer,so what we fix  to get the value 2.5 is by replacing the integer with the double so,it can give the greatest value of divider.






Test4.





The other error that I found is in Test9 that is the logic error.Where the question we were asked to solve were 1 divided by zero.It is obviously a logic error where 1 divided by zero is 0.


Test 9






For the Program Analysis Chart,there were few steps need to be taken to solve the problem:











Below are the example from the lab1 for Problem Analysis Chart:


From this Lab1,we are able to find the common error,solve problem using Problem Analysis Chart and we able to write,compile,run a simple computer program based on Program Analysis Chart.

Link to Dinie;s blog;