Friday, 2 November 2018

Lab 3 Problem Solving, Data Types and Selection

We are having our fourth lab session today. Programming is quite interesting but the more I learn the harder it is to understand.   

QUESTION 1
Trace the programs and show their output.

Test 1




Test 2


Even or Odd Number







QUESTION 2
Uncomment the line of Test 2 in question 1, compile and run it again.






QUESTION 3
Fix the error in Even Or Odd Number class from question 1.



I put “else” so that it can choose only one of the choices.


QUESTION 4
Find and fix the errors in Test3 class.



Correction: 
I put a bracket for “cheeseIsYellow” and “moonIsYellow” for a proper language.




QUESTION 5
Write a program that prompts the user to enter a letter alphabets. The program then displays the letter as well as the letter before and after the specified letter.



I just know that the scanner class in Java has nextInt() and nextDouble() but there is no nextChar(). We need to use next().charAt(0) to read a character.


QUESTION 6
Write a program that prompts the user to enter two points (x1, y1) and (x2, y2) and displays their distance. Math.pow(a, 0.5) can be used to compute the square root formula.



The formula is the hardest to write and solve. I get errors every time I try to write a new formula. It took me a day to solve it until I finally ask my classmates how. Math.pow(double a, double b) is for two parameters where it is used to calculate a number raised to the power of the second number.



QUESTION 7

Write a program that prompts the user to enter the exchange rate from Malaysian Ringgit (RM) to US Dollar (USD). Prompt the user to enter 0 to convert from USD to RM and 1 to convert from RM to USD. Prompt the user to enter the amount in USD or RM to convert it to USD or RM respectively. 





"Break” statement is necessary to avoid passing through to the code under the next label.


QUESTION 8
Write a program that plays the popular rock-paper-scissor game. 






It is quite easy to do for this question.


Henny Abigailwillyen Sinjus
183640
SSK3100 (Group 15)


Next blog: nurnadhirahzulkepli.blogspot.com

1 comment:

  1. I understand this column. I realize You put a many of struggle to found this story. I admire your process. currency conversion

    ReplyDelete