Sunday, November 11, 2018

Lab5

Assalamualaikum, in this entry i would like to share about lab5 only. this week i only finish my lab5 . the entire three hours, i spend to finish my lab5 only. lab5 is about the switch statement, logical operator and conditional operator.

first, switch statement is something like the if-else statement, just the way to write it is different but the output is the same. switch statement also need to use scanner as we need to get the command from the keyboard. the example of switch statement is like this:


import java.util.Scanner ;
public class Month {
    public static void main(String[]args){
      Scanner input = new Scanner(System.in);

      System.out.print("Enter number 1 until 12 only :");
      int x = input.nextInt();

  
   switch(x) {
     case 1 : System.out.println("january");
                   break;
     case 2 : System.out.println("february");
                   break;
     case 3 : System.out.println("march");
                   break;
     case 4 : System.out.println("april");
                  break;
     case 5 : System.out.println("may");
                  break;
     case 6 : System.out.println("june");
                  break;
     case 7 : System.out.println("july");
                  break;
     case 8 : System.out.println("august");
                  break;
     case 9 : System.out.println("september");
                  break;
     case 10 : System.out.println("october");
                  break;
     case 11 : System.out.println("november");
                  break;
     case 12 : System.out.println("december");
                  break;
     default : System.out.println("error");
}

}
}

from the example, we need the command from the keyboard which is number 1 to 12, when the number is selected, it will print out the result based on the month assigned for the umber selected. if the number is out of the range, it will print out 'error'.

next is about conditional operator combine with Boolean expression. for example for this case is like:


ticketPrice = (ages >= 6) ? 20 : 10


from the example we can know rhat if the ages is more than or equal to 6 years old, the ticket price is RM 20 or else if ages is less than 6 years old, the ticket price will be RM 10.

that is all for this entry. thank you.


p/s: link to Atika`s blog
ssk3100.blogspot.com


Lab4 & Lab5

Assalamualaikum, in this entry I would like to share about the lab4 and lab5. In the lab4 there is only one question which is to create our own adventure game. In this lab we need to use multi way and nested selection. means that player need to choose between two option, then form the option, we need to create another scene consequences from the player answer. there need to be two endings.

Next is about lab5, in this lab we need to know how to use switch statement, logical operator combine with Boolean expression and conditional operator. switch statement is like the if - else statement, the difference is that switch does not use 'if ', the use 'break' to separate the command. for the conditional operator, it also same as the if-else statement, but the difference is that conditional operator combine the if and else result in the same statement. for example :

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

from this statement, we can figure out that    
 if (x > 10) 
score = 3*scale
else
score = 4*scale;

that is all i want to share for this entry. thank you.

Test one is being held in this same week. For test one basically is not too difficult but it become difficult because there is not enough time to properly look through the questions and I answer the questions hurriedly. For me, the time for the test should be extent 30 minutes approximately.


p/s: link to Atika`s blog
ssk3100.blogspot.com

Lab3 & Lab4

Assalamualaikum , in this entry I would like to share about lab3 and lab4. For lab3 , is just the same as lab2 but there is an addition in selection statement, declare and use a appropriate data types in program and write, compile and run a programcbased on flowchart.

Firstly, we are been asking to trace a program. Then compile the program and try to run the program. Also , there is some error in the question and we need to fix it before run the java program.

After that, the question is about how to write a java program which is require us to use to the math.pow and also scanner obviously.

for lab4, we learn how to use the multi way and nested selections. Multi way means that the output can be various and not only one possibility on output but there are more than two output .



p/s: link to Atika`s blog
ssk3100.blogspot.com