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
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.
Henny Abigailwillyen Sinjus
183640
SSK3100 (Group 15)
No comments:
Post a Comment