4/24/2016

BCS2233 OOP: Test 1

Date:  28 April 2016
Time : 11:00-12:30

1. Which of the following are invalid identifiers, why?
I.    DCIT
II.    DCIT   Students
III.    $matric
IV.    matric_number
V.    1stJAVAProgram


2. Show ‘Evaluation Tree’ for the following expressions:
I.    8 + 2 / 4
II.    6 * 2 + 3 % 2
III.    3 + 2 / 5 + -2 * 4
IV.    2 * (1 + -(3/4) / 2) * (2 - 6 % 3)

3. Write a java fragment for the following problems.


0.    Write a for statement to print integer 1 to 20. [example]

int I;
For (i=1; i<=20; i++)
System.out.Println(i);


I.    Write a for statement to print integer 1 to 10.



II.    Write a while statement to print integer 1 to 10.




4.    Write a an algorithm and a java program that displays the following table:-
 (note that 1 kilogram is 2.2 pounds):

    Kilograms     Pounds  
    1             2.2     
    3             6.6     
    ...
    100           220  

4/23/2016

BCS2233 OOP: Assignment 3.


 Assignment 3

(The MyPoint class) Design a class named MyPoint to represent a point with x and y-coordinates. The class contains:
            I.     Two data fields x and y that represent the coordinates.
          II.     A no-arg constructor that creates a point (0, 0).
        III.     A constructor that constructs a point with specified coordinates.
          IV.     Two get methods for data fields x and y, respectively.
            V.     A method named distance that returns the distance from this point to another point of the MyPoint type.
          VI.     A method named distance that returns the distance from this point to another point with specified x and y-coordinates.
Draw the UML diagram for the class. Implement the class. Write a test program that creates two points (0, 0) and (10, 30.5) and displays the distance between them.


Due date:  8 Mei 2016

BCS2233 OOP: Thinking in Objects

Berikut adalah program untuk mengira BMI dan menyatakan status yang sepadan. Tukarkan kepada kaedah OOP.

import java.util.Scanner;

public class ComputeAndInterpretBMI {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    
    // Prompt the user to enter weight in pounds
    System.out.print("Enter weight in pounds: ");
    double weight = input.nextDouble();
    
    // Prompt the user to enter height in inches
    System.out.print("Enter height in inches: ");
    double height = input.nextDouble();
    
    final double KILOGRAMS_PER_POUND = 0.45359237; // Constant
    final double METERS_PER_INCH = 0.0254; // Constant 
    
    // Compute BMI
    double weightInKilograms = weight * KILOGRAMS_PER_POUND; 
    double heightInMeters = height * METERS_PER_INCH; 
    double bmi = weightInKilograms / 
      (heightInMeters * heightInMeters);

    // Display result
    System.out.println("BMI is " + bmi);
    if (bmi < 18.5)
      System.out.println("Underweight");
    else if (bmi < 25)
      System.out.println("Normal");
    else if (bmi < 30)
      System.out.println("Overweight");
    else
      System.out.println("Obese");
  }
}
 
--------------------------Cara 1----------------------------------------
import java.util.Scanner;
class BMI{
double weight,height;

void getinput(){
 Scanner input = new Scanner(System.in);
    
    // Prompt the user to enter weight in pounds
    System.out.print("Enter weight in pounds: ");
     weight = input.nextDouble();
    
    // Prompt the user to enter height in inches
    System.out.print("Enter height in inches: ");
     height = input.nextDouble();
    
}

 double tukarpoundtokilo(){
final double KILOGRAMS_PER_POUND = 0.45359237; // Constant
return ( weight * KILOGRAMS_PER_POUND);
}

 double tukarinchtometer(){
 final double METERS_PER_INCH = 0.0254; // Constant 
 
return (height * METERS_PER_INCH); 
}

 void printoutput(){
 double bmi;
 bmi= tukarpoundtokilo() / (tukarinchtometer() * tukarinchtometer());

    // Display result
    System.out.println("BMI is " + bmi);
    if (bmi < 18.5)
      System.out.println("Underweight");
    else if (bmi < 25)
      System.out.println("Normal");
    else if (bmi < 30)
      System.out.println("Overweight");
    else
      System.out.println("Obese");
}

}
 
public class carapertama {
    
    public static void main(String[] args) {
     
     BMI yourBMI = new BMI();
     yourBMI.getinput();
     yourBMI.printoutput();
     
    }
}
 

4/17/2016

BCS2233 OOP: Exercise Class


Write a class for each of the following specifications. In each case, include a constructor that set each member values to 0 and a member method named showdata() that can be used to display member values.


i) A class named rectangle that has double data members named width, height, and color.       
                      
ii) A class named time that has integer data members named hour, minute and second.


BCS2233 OOP. Procedural vs. Object-Oriented Programming (OOP)

The difference between the two styles of programming 

//Procedural
 
import java.util.Scanner;
public class calculateAreadanPerimeterofBox {
   
    public static void main(String[] args) {
                Scanner input= new Scanner(System.in);
                System.out.println("Sila Masukkan nilai tinggi dan lebar segiempat!");
        int tinggi = input.nextInt();
        int lebar =input.nextInt();
       
        int luasSegiempat=tinggi*lebar;
        int perimeterSegiEmpat = 2*(tinggi+lebar);
       
        System.out.println("Luas Segi Empat=" +luasSegiempat );
        System.out.println("Perimeter Segi Empat=" +perimeterSegiEmpat );

    }
}



// Object-Oriented Programming (OOP)

import java.util.Scanner;
 class segi4{
 int tinggi;
   int lebar;
  
   void getInput(){
                               Scanner input= new Scanner(System.in);
                               System.out.println("Sila Masukkan nilai tinggi dan lebar segiempat!");
                               tinggi = input.nextInt();
                               lebar =input.nextInt();
   }
  
   int kiraLuasSegiempat(){
                               return tinggi* lebar;
   }
  
   int kiraPerimeterSegiempat(){
                return 2*(tinggi+ lebar);
   }
  
   void printOutput(){
        System.out.println("Luas Segi Empat=" +kiraLuasSegiempat() );
        System.out.println("Perimeter Segi Empat=" +kiraPerimeterSegiempat() );
   }
 }
public class calculateAreadanPerimeterofBox2 {
  
    public static void main(String[] args) {
               
                segi4 segiEmpat1 = new segi4();
                segiEmpat1.getInput();
                segiEmpat1.printOutput();
    }
}
 

4/09/2016

BCS2233 OOP: Exercise -Passing arrays to methods

 Write the following method that returns true if the list is already sorted in increasing order.

public static boolean isSorted(int[] list)

Write a test program that prompts the user to enter a list and displays whether the list is sorted or not. Here is a sample run. Note that the first number in the input indicates the number of the elements in the list.


Enter list: 8 10 1 5 16 61 9 11 1
The list is not sorted



Enter list: 10 1 1 3 4 4 5 7 9 11 21
The list is already sorted



Cara download Installer windows 10 dalam format ISO

1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan.  ...