Archive

Archive for 2013

DCT 1093 - Lab 4 - Loops (Lab 4.1)


Example Lab 4.1

[1] Question :

(Conversion from miles to kilometers)
Write a program that displays the following table (note that 1 mile is 1.609 kilometers):


[2] Example Code :

------------------------------------------------------------------------------------------------------------------------
  
    // Step 1 : Use while loop
    int miles = 1;
    while (miles <= ___________)
    {
          // Step 2 : Calculation
          _________________________________

           // Step 3 : Display Result
          System.out.println(________________);
       
           miles++;
    }
  
 -------------------------------------------------------------------------------------------------------------------------


DCT 1093 - Lab 3 - Selections (Lab 3.3)


Example Lab 3.3

[1] Question :

One million is 106 and 1 billion is 109. Write a program that reads a power of 10 (6, 9, 12, etc.) and displays how big the number is (Million, Billion, etc.).
Display an appropriate message for the input value that has no corresponding word.


[2] Example Code :

------------------------------------------------------------------------------------------------------------------------

     // Step 1 : Prompt the input
     Scanner input = new Scanner(System.in);
  
    // Step 2 : Enter an power of 10
     System.out.print("_____________________");
     int number = input.nextInt();
  
    // Step 3 : Selection statement + Display Result
    switch (power)
    {
          case 6 :
                    System.out.print("Milion" );
                    break;
          case _ :
                    System.out.print("______________________" );
                    break;
     }

 -------------------------------------------------------------------------------------------------------------------------



DCT 1093 - Lab 3 - Selections (Lab 3.1)


Example Lab 3.1

[1] Question :

(Checking whether a number is odd)
Write a program that reads an integer and checks whether it is odd.

[2] Example Code :

------------------------------------------------------------------------------------------------------------------------

     // Step 1 : Prompt the input
     Scanner input = new Scanner(System.in);
  
    // Step 2 : Enter an integer
     System.out.print("Enter an integer: ");
     int number = input.nextInt();
  
    // Step 3 : Selection statement + Display Result
    if (___________________ )
        System.out.println("_____________________________");
    else
        System.out.println("_____________________________");


 -------------------------------------------------------------------------------------------------------------------------

[3] Answer :

--------------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
public class Lab3_1 {
   
  public static void main(String[] args) {
  
                  // Step 1 : Prompt the input
                 Scanner input = new Scanner(System.in);
   
                  // Step 2 : Enter an integer
                 System.out.print("Enter an integer: ");
                 int number = input.nextInt();   
                 // Step 3 : Selection statement + Display Result
                 if (number % 2 != 0 )
                        System.out.println("Is "+ number + " an odd number? True");
                 else
                        System.out.println("Is "+ number + " an odd number? False");  }
}

-------------------------------------------------------------------------------------------------------------------------

[4] Output :  

Enter an integer: 17
Is 17 an odd number? True

Enter an integer: 500
Is 500 an odd number? false


DCT 1093 - Lab 2 - Elementary Programming



Example Lab 2.2

[1] Question :

(Converting Celsius to Fahrenheit)
Write a program that reads a Celsius degree in double from the console, then converts it to Fahrenheit and displays the result.

The formula for the conversion is as follows:
                                              
                                                fahrenheit = (9 / 5) * celsius + 32

[2] Answer :

-------------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
public class Lab2_2 {
   
  public static void main(String[] args) {
  
                  // Step 1 : Prompt the input
                 Scanner input = new Scanner(System.in);
   
                  // Step 2 : Enter a degree in Celsius
                 System.out.print("Enter a degree in Celsius: ");
                 double celsius = input.nextDouble();
   
                 // Step 3 : Calculation
                 double fahranheit = ((9.0/5)* celsius) + 32;
   
                 // Step 4 : Display Celsius in Fahrenheit
                 System.out.println( (int) celsius + " Celsius is " + fahranheit + " Fahranheit" );
  }
}

--------------------------------------------------------------------------------------------------------------------------

[3] Output :  

Enter a degree in Celsius: 43
43 Celsius is 109.4 Fahrenheit


DCT 1013 - Group Assignment 1


Group Assignment 1 - DCT 1013

As attached is a group assignment 1 for subject DCT1013.
------> GROUP ASSIGNMENT 1

Please check the selected key term for your group. For name labeling with red colors, make sure your choose other key term for your group and inform me before 15-01-2013