Tuesday 13 November 2018

Lab5

Topics:
Switch statement, Logical Operators and Conditional Operator

Learning Outcome:
At the end of this lab, student should be able:
1. Use switch statement to specify alternative paths of program’s execution.
2. Use logical operators to combine Boolean expressions.
3. Use conditional operators for concise and elegant code for decision making.

For this Lab, we need to use switch statement, logical operators and conditional operators depends on the question.


For certain question, we need to use switch statement to determine days, and also months.This is example of using switch statement to determine months,








Conditional operators can be used when we wanted to combine two Boolean expression;




It gives us 3 options,other than number 0,1 and 2 it will give us error message.
It is important to use the correct notation,such as the bracket () for the Boolean expressions,: for else if, and also the ?.

Lab4

Topics:
Multi-way and nested selections


Learning Outcome:
At the end of this lab, student should be able:
1. Use multi-way and nested selection statement to specify alternative paths of program’s execution

So for the 4th lab,we need to design an adventure game,where it game tells story through passage of text revealed to a player in response to typed instructions. The game starts with the player inside a “room” with textual description. The player can move from one room to another by typing in commands.
As for the command we can determine on our own.we also need to add some character that the player needs to interact with during game.Our task is to make at least 10 rooms for the player to explore during the game.


For this lab, we need to use nested selections,where there is selections in selection,that is why it is called nested.The 10 room that we need to have,is based on the nested selection we build in the coding.
This is the example of  my games ;



It shows you the introduction to the adventure game and also  selections for room1 and room2.

Lab3


For Lab 3,the topics are Problem Solving, Data Types, Selection and the learning outcome are:
1. Trace a program.
2. Designing solution to a problem using Problem Analysis Chart (PAC), Input Process Output Chart (IPO) and Flowchart.
3. Declare, initialize and use appropriate data types in a program.
4. Use selection statement to specify alternative paths of program’s execution.
5. To write, compile and run a simple computer program based on the flowchart.
For the first part if the lab,we were given few questions on source code and we need to trace the program to identify the input,variable,and also the expected output.Throughout the lab we are able to do the tracing part because we are used to the to the tracing program problems.



Line
variable
output
5
Int number

7
Int number
Number is even
8
Int number
Number is odd

The Table above shows one of the tracing that have been done in the Lab


Designing solution to a problem using Problem Analysis Chart (PAC), Input Process Output Chart (IPO) and Flowchart is when we are given the question to run a program.We need to follow the procedure in order for us to be able to write or run a java program.First we need to do the Problem Analysis Chart,then Input Process Output Chart and also flowchart where there will be algorithm found in order for us to build the source code for the program.
Declare, initialize and use appropriate data types in a program
There are actually many data types that are avaible that is,int,float,double ,long ,short,byte,Boolean,char.We declared it in order for the program to easy to generate the output.

Use selection statement to specify alternative paths of program’s execution,we in this case use the if else statement,where the program will ask for the input from the user,and it will follow certain condition that have been assigned to the number.



To write, compile and run a simple computer program based on the flowchart.Lastly, we were given problems where we need to solve the problem and write the program in java.



\


Problem where we need to exchange from rm to usd and usd to rm.

Monday 8 October 2018

Lab 2

For Lab 2

The Learning Outcome are:

1. Trace a program.
2. Designing solution to a problem using Problem Analysis Chart (PAC) and Input Process Output Chart (IPO).
3. To write, compile and run a simple computer program based on IPO.

So,For the first question,we need to trace a program line by line;
we need to trace the line number,variable and output.

Here is the example for one of the tracing program.



Trace 1 
1. public class ComputeArea {
2. public static void main(String[] args){
3. double radius;
4. double area;
5. radius = 20;
6.
7. area = radius * radius * 3.14159;
8.
9. System.out.println("Area of circle with radius " + radius + " is " + area);
10. }
11. }

LINE NUMBER
RADIUS
AREA
OUTPUT
5
20


7
20
1257

9
20
1257
Area of Circle with radius 20 is 1257

Then,we need to run program where we need to change value of money entered into ringgit and sen.
After a few times trying,i'm able to run the program,

The Source code:


when we run the program ;


it will display the money in ringgit and sen.


For the next question,we need to calculate BMI of a person when we enter the weight in pound and height in inches

The source code:

When we run the program,it will automatically calculate the BMI for a person.










Monday 1 October 2018

Lab1


For Lab1,we were supposed to;

1.Identify common errors and programming pitfalls.


2.Designing solution to a problem using Program Analysis Chart.


3.To write,compile,run a simple computer program based on Program Analysis Chart.


Into The Lab

For this Lab1,for the first part we were given class to be separated in java class and we need to the errors.Below are few examples of class of java that we need to fix the error.
One of the problem when I tried to run the java program for test 4.The java run smoothly but the answer to the question is not correct.The value of 5 divided by 2 is supposed to be 2.5 but it display only 2.This is because we use integer,so what we fix  to get the value 2.5 is by replacing the integer with the double so,it can give the greatest value of divider.






Test4.





The other error that I found is in Test9 that is the logic error.Where the question we were asked to solve were 1 divided by zero.It is obviously a logic error where 1 divided by zero is 0.


Test 9






For the Program Analysis Chart,there were few steps need to be taken to solve the problem:











Below are the example from the lab1 for Problem Analysis Chart:


From this Lab1,we are able to find the common error,solve problem using Problem Analysis Chart and we able to write,compile,run a simple computer program based on Program Analysis Chart.

Link to Dinie;s blog;

Thursday 20 September 2018


Lab0


PART1-REFLECTION

For the first programming lab which is my very first programming class ,I find it was quite exciting since it was outside our comfort zone which is Physics.It is a subject which need you to compile,run a program and many more.So,it takes much more effort and skills in order to excel in this course.

Basically the first lab is about the introduction to computer program.The purpose of the first lab to familiarise ourself with lab and the programming environment.Other than that,it's suppose to make us to write,compile and run simple computer program written in java.

For the first part of the lab,we are instructed to open the command prompt to familiarise ourself with the command prompt.From there I learn on how to create a folder just by giving command and without manually making the folder.All we need to do is give the command in the command prompt,and it will be automatically appear.In order to make a directory,we command 'mkdir_name of directory',then we make a folder by the name of Lab0 and by command 'notepad' in the cmd,we need to save it into the file Lab0.After commanding in the cmd,we need to check wether the file does exist in the computer.I find it a little bit difficult to understand for the first time,after few times trying,finally i get what we need to actually do.

So,this is what i get from it,


FIGURE 1


After completed for the first part,we proceed to second task that is running and compiling simple program.For this part there are some mistakes that I make, that causes some error when I wanted to run the program.Few mistakes that occur during the lab;
1)I do not named the file correctly,where i dont put '.java' behind the file,so it cant be recognised by the system.
2)When I tried to change the settings for the path of the computer,i dont use the correct notations,causing it to be not recognised when i try to run the program.

After fixing all the mistakes above,i get the below result;
Figure 2



After we run the java program,there are still some error occur as you can see at the above figure since there are some part of the program execution was not accurately typed.This is because,we need to follow certains method to make sure that the program is working properly.We need to make sure the main method,execute statement,and the tracing execution is accurately used.If we miss even one single notations,wether it is the sensitive case of the alphabet,or the notations such as commas,semicolon,there will be error occur when we try to run the java.After few mistakes,at last i can run the java.For the proper trace of program execution



figure 3




PART2-HOW DOES COMPUTER STORE IMAGE AND MUSIC

The computer will store them by converting the human language into the computer language.It was by converting them into binary by using some process of encoding and decoding.It will turn into
8-bits,12-bits depending on how large the file was.For image,the colors will be represented by JPEG,PNG and GIF. Represent color of each pixel. Use run-length encoding to compress size.For Music,sample less frequently  use fewer bits to represent the sample.




Link to the next person:
dnflzhe.blogspot.com