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.