Sunday, 14 October 2018

Lab 2 Problem Solving Techniques

Today our class need to do our Lab 2 where we are required to trace a program, designing solution to a problem using Problem Analysis Chart (PAC) and Input Process Output (IPO) chart and run a simple program based on the IPO. I am very excited to do the first question at first until I get into Question 6. I am confused a bit for that question but I still manage to do it with the help from my classmates. So here we go ~..~

QUESTION 1
Trace the following programs and show their output:

a) Computer Area



b) Average



c) Fahrenheit To Celsius



d) Sales To Tax



QUESTION 2
Do you spot any error in the classes Average and/or FahrenheitToCelsius? Correct it.

a) Fahrenheit To Celsius
I fix the formula because the answer before is wrong due to wrong formula.



b) Average
I change the value 2 in double average formula to 2.0 so that I can get a precise answer which is in the decimal point.



QUESTION 3


I change the line 8 from (int) to (double) so that I can get an answer that rounded up to 3 decimal places.


QUESTION 4
Write a program that declares variables and assign values from a user for each data type available in Java and print them out.

I choose several classes which is Boolean, Character, Double and Float:
a) Boolean


b) Character



 c) Double



 d) Float



QUESTION 5
Develop a program that changes a given amount of money into smaller monetary units. The program lets the user enter an amount as double value representing an amount in RM and sen, and outputs a report listing the number of RM and sen.

a) PAC, IPO and Algorithm
       
PAC
Input
Process
Output
Amount
Convert amount entered to ringgit and sen
Display amount in ringgit and sen
IPO
Input
Process
Output
Amount = 11.56
Enter amount
double ringgit = (int)amount
double sen = amount – ringgit
Display amount in ringgit and sen
End
Display amount in ringgit and sen
ALGORITHM



b) Complete JAVA program and solve the problem.



QUESTION 6
Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and dividing, by the square of your height in meters. Write a program that prompts a user to enter a weight in pounds and height in inches and displays the BMI. 1 pound is 0.45359237 kilograms and one inch is 0.0254. 

a) PAC, IPO and Algorithm

PAC
Input
Process
Output
Weight;
Height
Convert weight in pounds to kilogram and height in inches to metres and calculate BMI
Display BMI
IPO
Input
Process
Output
Weight;
Height
Enter weight in pounds
Enter height in inches
double weight = pounds x 0.45359237
double height = inches x 0.0254
double BMI = weight / height / height
Display BMI
End
Display BMI
ALGORITHM
 

b) Complete JAVA program and solve the problem.





Alright folks. This is the end of my Lab 2 session. See you on my next session. 😼😼😼


Henny Abigailwillyen Sinjus
183640
SSK3100 (Group 15)

Next blog: nurnadhirahzulkepli.blogspot.com

No comments:

Post a Comment