Thursday, 4 October 2018

Lab 2

Hi everyone! Today is our programming class. Lets begin!
For today task is for problem solving in java program. For today lesson, we will be able to trace a program, designing solution to a problem using Problem Analysis Chart(PAC) and Input Process Output Chart (IPO). Besides, we also can write, compile and run a simple computer program based on IPO.

For the first question, I need to trace the following programs and show their output.

Question 1(a) :


Answer :

Question 1(b) :


Answer : 


Question 1(c) :


Answer : 


Question 1(d) :


Answer :




For the question 2, i spot any error in the classes Average and/or FahrenheitToCelsius and i already correct it and here is the answer.

Classes Average :

Classess FahrenheitToCelsius :


Next for the question 3, I need to round up the code in line 6 to two decimal places. The answer is , 


Next, for the question 4, I need to write a program that declares variables and assign values from a user for each data type available in Java and print them out. 
Here is the data type that I choose,

i) Boolean

ii) Byte


iii) Char

iv) Double


Question 5 :


Answer :

PAC
Data
Processing
Output
Amount of money
Ringgit = (int) amount;
Sen = (Amount – Ringgit) * 100
Amount of money in Ringgit

Amount of money in Sen

IPO
Data
Processing
Output
Amount of money
Get amount from user input.

Ringgit = (int) amount;
Sen = (Amount – Ringgit) * 100
Amount of money in Ringgit

Amount of money in Sen

Algorithm :

1. Get the amount from user

2. Covert the amount into Ringgit and Sen by using the following formula:

Ringgit = (int) amount;
Sen = (amount – Ringgit) * 100

3Display the amount in Ringgit and Sen


Java program :



Question 6 : 

Answer :

PAC

DATA

PROCESSING
OUTPUT
Weight in pounds
Height in inches
Convert weight in pounds to weight in kilograms

Convert height in inches to height in meters

Weight = weight in pounds * 0.45359237 kg
Height = height in inches * 0.0254 meter

Compute BMI

BMI = weight / height2
Display BMI
IPO

DATA

PROCESSING
OUTPUT
Weight in pounds
Height in inches
Get value of weight and height from user input.

Convert weight in pounds to weight in kilograms

Convert height in inches to height in meters

Weight = weight in pounds * 0.45359237 kg
Height = height in inches * 0.0254 meter

Compute BMI

BMI = weight / height2

Display BMI


ALGORITHM:
1.       Get value of weight and height from user input.

2.       Convert weight in pounds to weight in kilograms  by using the following formula:

                Weight = weight in pounds * 0.45359237 kg

3.       Convert height in inches to height in meters by using the following formula:

               Height = height in inches * 0.0254 meter

4.       Display the BMI.


Java program :


That's all for Lab 2. This questions is quite challenging for me and it makes me feel excited to learn more. 

Bye! Thank you for reading my blog.


No comments:

Post a Comment

Lab 10

Hello everyone! Now is our Lab 10 exercise. For this topic, we learn  Multi-Dimensional Array and having lab for this sub-topic. We learn ho...