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

Tuesday, 9 October 2018

Lab 1 Problem Solving using Java (20/09/18)

Hi guys~~
Today is my second lab session for the programming class. We are given task which is solving the problem using JAVA program. There are 3 questions that I need to solve and you can see it as in below. The objective of this lesson is to learn how to identify and fix the errors, construct the Problem Analysis Chart (PAC) and write Java code.

QUESTION 1
Write each of the classes below in separate Java files. Compile, identify and fix the errors.

Test 1
a) Write the code in notepad and compile it by typing "javac PublicClassTest1.java" in cmd.

 


b) Error! Cannot find the public class. Why?
Take note that our filename must be the same as in our notepad (public class). Therefore, we change our filename from "PublicClassTest1" to "Test1". Then, we compile it again and there will be several errors need to be fixed in the notepad.


c) Fix the errors.
Row 3: We should put "static".
Row 9: Careful with the " sign.


c) After we fix the errors, we try to compile it again and run it.
The answer would be "J is 52.0 and K is 51.0".


d) Done for Test 1.


Test 2
a) Write the code and compile it.


b) Fix Errors.
We need to define what is " int k " in order for us to find " int i ". So, I put int k as number 3 (int k = 3).
 We can show the answer specifically by writing "value is:" +i. This means that the answer would be "value is: 5" instead of "5".


c) Compile and run the code again.


d) Finish for Test2.


Test 3
a) Write the code and compile it.


b) Fix errors.
 Line 2: Public must be in the small letter. Take note!
I define one by one for the method and put it in an equation.


c) Compile and run it again.


d) Finish for Test3.


Test 4
a) Write the code and compile it.



b) The answer is correct but we need to show it properly by writing " System.out.println("value is:" +amount/2) " in the notepad. It means that the answer would be " value is: 2 " instead of " 2 ".



c) Finish for Test4.


Test 5
a) Write the code and compile it.


b) Fix errors.
The terms must be the same including capital or small letter. Here I change the "interestrate" term to "interestRate". The R should be in capital letter.


c) Compile and run it again.


d) Finish for Test5.


Test 6
a) Write the code and compile it.



b) Fix errors.
Change the value 7 to 6.


c) Compile and run it again.


d) Finish for Test6.


Test 7
a) Write the code and compile it.



b) Fix errors.
Change the " - " into " + ".


c) Compile and run it again.


d) Finish for Test7.


Test 8
a) Write the code and compile it.



 b) Fix errors.


c) Compile and run it again.


d) Finish for Test8.


CelsiusToFahrenheit
a) Write the code and compile it.



b) Fix errors.
 Change the formula.


c) Compile and run it again.


d) Finish for CelsiusToFahrenheit.


Welcome
a) Write the code and compile it.



 b) Fix errors.
Be careful with the notations ( eg. "" and ; ).


c) Compile and run it again.


d) Finish for Welcome.



QUESTION 2
Analyse the following problems using Problem Analysis Chart (PAC).

(a) One acre of land is equivalent to 43,560 square feet. Calculate the number of acres in a tract of land with 389,767 square feet.

Data
Processing
Output
Number of square feet per one acre of land
Calculate the number of acres of land

Number of acres of land


(b) Calculate the average of three test scores and display all of them.

Data
Processing
Output
Three test scores


Calculate the average of 3 test scores

Average of three test scores



(c) An electronics company sells circuit boards at 40 percent profit. If you know the retail price of a circuit board, you can calculate its profit with the following formula :
Profit = Retail price x 0.4 
Calculate the amount of profit earned for that product based on the retail price and display the results.

Data
Processing
Output
Percentage of profit and retail price of a circuit board

Calculate the profit

Amount of profit earned



QUESTION 3
Choose one from the following problems and analyze it using PAC. Then write a complete Java program to solve it.

If you know the balance and the annual percentage interest rate, you can compute the interest on the next monthly payment using the following formula: 
Interest = balance X ( annualInterestRate/1200 ) 
Write a program that displays the interest for the next month if the balance is RM1000 and interest rate of 3.5%.

a) Write the PAC analysis.

Data
Processing
Output
Balance = b
Annual percentage interest rate = i
Calculate the interest for next monthly payment

Interest  =  balance x (annual interest rate/1200)
Interest for next month
b) Write the code in notepad.


b) Compile and run the code.


c) Done.




Henny Abigailwillyen Sinjus
183640
SSK3100 (Group 15)

Next blog: nurnadhirahzulkepli.blogspot.com