Saturday, November 3, 2018

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, Hence, I decided to ask my friends to help me. I would like to thanks my classmate Nurazreen Mohd Nor and Nur Nadhirah Zulkepli for their helps in completing this lab task. So I don't want to waste the time, lets begin with the task. Below is the given task :

Question 1:
The question 1 is about to print out the output but in this case, the output is printed by using formula.


Question 2:
The question 2 is about comparison between string. The answer will be either true or false.

Answer:

Question 3:

The question 3 is about comparison between the string as well but in this case by using "compareTo". Usually this comparison will give a result in numbers instead of true or false.

Answer:


Question 4:
The question 4 is about print out random letter. By inserting the specific formula, the Java program will print out random result.

Answer:

Question 5:
The Question 5 is about to find out the ASCII code for specific letter. In this case as well, there is a specific formula to produce the output.

Answer:
`

Question 6:


From my point of view, I think among all the questions above, question 6 is the difficult one. I need to combine all the learning to produce the answer for this question.

Answer:

The outcome for this lab task are I need to be able read string and characters from console as well as declare and manipulate strings and characters using method provided by characters and string class.

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 )

Tuesday, October 23, 2018

Problem Solving (Lab 5)

Assalamualaikum and Hi ! Today I would like to share with all of you new knowledge pertaining to programming. Apart from create a game using programmer, you also can do other things. Let's learn together. Foremost, I will share the question and the solution to make you guys more clear.

For the first question, it is about comparison of two statement i by combining two statements using Boolean Expressions. This symbol "&&" is referring to "and" while the two straight line is referring to "or". In this situation if using "and" but there is one statement is false, it means that the whole statements are false. It is different with "or", if one statement is true meaning that all statements are true. Here I provided the solution to make it clear.

Answer:

1.    Assuming that x is 1, show the result of the following Boolean expressions:

BIL.
Boolean Expressions
Result
a.
( true ) && ( 3 > 4 )
False
b.
! ( x > 0 ) && ( x > 0 )
False
c.
( x > 0 ) || ( x < 0 )
True
d.
( x != 0 ) || ( x = = 0 )
True
e.
( x >= 0 ) || ( x < 0 )
False
f.
( x != 1 ) = = !( x = = 1 )
True

For second question, it is about how to switch the statement. So, let's say if the condition fulfill the given situation, then it will execute the situation.
  


Answer:

int x = 1, a  = 3;
Switch (a)
{
  case 1:System.out.println(“x is” + (x + = 5));
           break;
  case 2:System.out.println(“x is” +  (x + = 10));
           break;
  case 3:System.out.println(“x is” +   (x + = 16));
           break;
  case 4:System.out.println(“x is” + (x + = 34));
           break;
  default: System.out.println("Hi!");









int day = input.nextInt();
Switch (day)
{
case 0:System.out.println(“Sunday”);
                                    break;

case 1:System.out.println(“Monday”);
                                    break;

case 2: System.out.println(“Tuesday”);
                                      break;
                        case 3:System.out.println(“Wednesday”);
                                    break;
                        case 4: System.out.println(“Thursday”);
                                    break;
case 5: System.out.println(“Friday”);
                                    break;
default: System.out.println(“Saturday”);
                                    break;

                       
}










System.out.println ( ( age == 6)? “Ticket price is RM20” : “Ticket price is RM10”)














a.    score = ( x > 10 ) ? 3 * scale : 4 * scale;

if (x > 10)
{
     System.out.println(“score is” +(3 * scale));
}
else
{
     System.out.println(“score is” +(4 * scale));
}

b.    tax = ( income > 10000 ) ? income * 0.2 : income * 0.17 + 1000;

if ( income > 10000 )
{
     System.out.println(“tax is” +( income * 0.2));
}
else
{
     System.out.println(“tax is” +(: income * 0.17 + 1000));
}


c.    System.out.println( ( number % 3 == 0 ) ? i : j );

If ( number % 3 == 0 )
{
     System.out.println(“i);
}
else
{
     System.out.println(“j”);
}












So, the learning outcome for this task is I am able to use switch statement to specify alternative paths of program's execution. Not only that, after done this lab, I had learned how to use logical operators to combine Boolean expressions and know how to use conditional operators for concise and elegant code for decision making.

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 )

Friday, October 19, 2018

Problem Solving (Lab4)

Assalamualaikum and hi peeps!!

Today I'm gonna share the next task. This task I think really difficult in the world and I don't know how to describe the level of difficulty for this task. I never create game by using programming. This is my first time doing that. First time reading the question, I would like " ohhh it just want us to give the instruction, create the text, this and that". So, I am thinking that it is really easy peasy. Maybe Dr. understand that we have answering difficult task for every week so now he give simple assignment. But unfortunately, my assumption is totally wrong! The task is not only about give the direction, writing the text, but I need to write the full program for that game and the flow how to end the game and I was like wowww!!!!

Here you can see how the question is look like :



Here I post the example how the game is look like:


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 )

Thursday, October 11, 2018

Problem Solving (Lab3)

Assalamualaikum and hi guys! Here i come back with new problems, new solution and new knowledge. I hope that you guys still interesting to read my blog. So, here I would like to share the problem solving for Lab 3. So, of course for each problems for every week, there will be different learning outcome we will gain. At the end of this lab task, I would able to trace a program , designing solution to a problem using Problem Analysis Chart (PAC), Input Process Output (IPO) and flow chart. Apart from that, I able to declare, initialize and use appropriate data types in a program and use selection statements to specify alternative paths of program's execution. Not only that, I would able to write, compile and run a simple computer program based on the flowchart.

So lets start!


Question 1: 

This is the first sub-question for Question 1:



Here is the answer for that question:




The second sub-question is:


The solution is :

What I can trace for second sub-question is whenever we put the "/" in front of the coding, the program will not run or print out it. It just a comments.




The last sub-question is:



and the solution for above question is :

The error in typing the above coding is there is missing word of "else" because if we want to compare it is true or false and there will be two different statement, we should put"else".




Question 4:

The problem for question 4 is :



Here is the answer :

I found the error after the sentences "if moonlsYellow", the condition is incomplete. The second one is we no need to declare the "boolean" for two times.



Question 5:



The answer is :

The above question tested me on how to produce word before and after "g".




Question 6:




Answer :



Question 7:





The solution is :



Question 8:



The solution for question 8 is:




Based on my point of view, I feel that the task getting harder and difficult. The question is looking simple but the way to think the solution is really complicated and quite confusing. I don't even know how programming student's thought is look like because I am economic's student. The most tough question I think is Question 7 and Question 8. It is really challenging me!

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 )



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 )



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...