Wednesday, October 3, 2018

Problem Solving (Lab 2)

Assalamualaikum and Hi guys ! This is my third lab task where I need to trace a given program, designing solution to a problem using Problem Analysis Chart (PAC) and Input Process Output Chart (IPO) and to write, compile and run a simple computer program based on IPO.

So, Let's Start !!

This is the first question for this Lab 2 task where I need to type all this source code in the windows prompt, compile the code and run it. For each problems, it has different types of error where I need to trace and fix it. Below are the given problems:

Question 1: Problem 1:


There is no error found in the above problem. Here is the answer for the first problem;


Problem 2:

For Problem 2, what I found is the printed result is wrong where the answer should be 1.5 but the printed result is 1.0. So, the traced error here is the data type using in the problem 2 is not suitable. The proper data type should be used is "double" for "number 1" and "number 2" , hence it can store large memory.

Answer:



Problem 3:

The error in the above problem is about the formula inserted in the command prompt. The formula used is wrong and it produced the wrong result. Below is the correct answer for the Problem 3:

Answer:


Problem 4:












The error for problem 4 is also about the data type that had been used. The "int" in front of "tax" in line 6 should be replaced with "double".

Answer:













Question 2:




Average :

I spot that there is a logic error in the coding for average class. Number1 and Number2  should be in the correct numerical data type, so that the memory can read the value. The answer for average class should be 1.5 but the result produced by the programmer is 1.0.

FahrenheitToCelsius:

I spot logic error for Fahrenheit class where the result produced by programmer is doesn’t same as what we command. From my observation, I found that maybe there is mistake in writing the formula. So after I correct the formula, I get the exact answer.

Question 3:







For question 3, I try solve the problem by using "Math.round" to round up the values. Below is the answer for question 3:



Question 4:








Question 4 is about how I try to develop the program by myself for each data type available in Java. Below is one of the data types available in Java program.

Answer :

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
MODULE
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.       Convert the amount into Ringgit and Sen by using the following formula:

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


3.       Display 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
MODULE
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


For each Lab task, there is different problem and level of tough. So stay tuned with me :)

Nursaidatul Sakinah Binti Saharuddin
184881




Enjoy reading my blog!
Feel free to share any fruitful knowledge with me as I am eager to learn something new and we can learn together!

Thank you :)

This is my friend's blog. Check him out!
hongjing96.blogspot.com (lLim Hong Jing )



1 comment:

  1. Such a well-researched article! It’s clear you put a lot of effort into this. I’ll be bookmarking this for future reference. Thanks for sharing!

    Andaman and Nicobar Package for Family
    Best Time to Visit the Andaman
    Flora and Fauna of Andaman and Nicobar Islands

    ReplyDelete

Problem Solving (Lab6)

Assalamualaikum and hi guys ! Here I come back to share new problems with new solution. Honestly, I do not really understand with questions...