Showing posts with label 14/15 SEM 2 BCS2233. Show all posts
Showing posts with label 14/15 SEM 2 BCS2233. Show all posts

5/15/2015

BCS2233 OOP: Solution for Assignment3 (Q2 and Q3)

Jawapan untuk Assignment 3.

Soalan 2 a) 

class time {
double secs, mins, hours;
time(){
secs=0; mins=0; hours=0;
}
public void showdata(){
System.out.Println(“Saat =” +secs);
System.out.Println(“Minit =” +mins);
System.out.Println(“Jam =” +hours);
}

Soalan 2 b)  

class rectangle {
double height,length;
date(){
height=0; length=0;
}
public void showdata(){
System.out.Println(“Tinggi =” +height);
System.out.Println(“Panjang =” + length);


Soalan 3

class point {
int x,y;

point(){
x=0;y=0;

double area(){
return 0;
}

double distance(int x1 ,int y1, int x2, int y2) {
return Math.sqrt((x2-x1)*(x2-x1)-(y2-y1)*(y2-y1));
}

}

class circle extends point {
int radius;

double area() {
return (3.14 * (radius* radius));
}

}
UML diagram  for the class Point and class Circle



5/06/2015

BCS2233 OOP: Array

Write program statements that will do the following to array X shown below: -

int[]  X= new int[20];
for(i=0;i<=19;i++)
X[i]=i;

i) Print all elements (use loop).

ii)  Replace third element with 5.

iii)  Copy the elements in the fifth location into the first one.

iv)  Increase the sixth element by 10.

v)  Print all elements in reverse (use loop).

vi) Sum All elements.

vii) Find the largest element.

5/03/2015

BCS2233 OOP: LAB WEEK 14

import java.util.Scanner;
class segitiga{
protected int tinggi;
protected int lebar;

segitiga(){
tinggi =0;
lebar =0;
}
public void inputData(){
Scanner input = new Scanner(System.in);
System.out.println("Sila masukkan tinggi dan lebar :");
try {

tinggi = input.nextInt();
lebar = input.nextInt();
}
catch(Exception ex) {
System.out.println("invalid data type"+ex);
}
}
 double kiraLuas(){
 return (tinggi* lebar)*0.5;
 }

private double kiraPerimeter(){
return ((tinggi+lebar)+ (Math.sqrt((tinggi*tinggi) + (lebar*lebar))));
}
public void cetakData(){
  System.out.println("Luas Segitiga="+kiraLuas());
  System.out.println("Perimeter Segitiga="+kiraPerimeter());
}

}
public class demoinheritance {
   
    public static void main(String[] args) {
   
    segitiga segi3Satu = new segitiga();
    segi3Satu.cetakData(); //boleh atau tidak
    }
}

4/26/2015

BCS2233 OOP: Assignment 3



1. Explain the following terms:-

a). Class
b). Object
c). Instances
d). Public
e). Private
f). Super Class
g). Inheritances.



2.  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.

a). A class named time that has integer data members named secs, mins, and hours.

b). A class named rectangle that has integer data members named height and length.

3. Create a base class named Point consisting of x and y data members representing point coordinates. From this class, derive a class named Circle with another data member named radius. For this derived class, the x and y data members represent a circle’s centre coordinates. The member method of the Point class should consist of a constructor that set the value for x and y to 0, an area() method that return 0, and distance() method that returns the distance between two points, (x1,y1) and (x2,y2), where


Additionally, the derived class should has an overided method named area() that return’s a circle area

Area = 3.14 x radius2.

Draw UML diagram that for the class Point and class Circle.


4/19/2015

BCS2233 OOP: LAB WEEK 12

Tuliskan semula  program java berikut dan 'run'. Tuliskan output yang terhasil. Yang manakah di katakan sebagai  'constructor' (dalam program java).

3/29/2015

BCS2233 OOP: Assignment 2

Write an algorithm and java program for each of the following:-


1. Write an algorithm (pseudocode or flowchart) for a program that read 10 integers. Find the maximum and minimum number among the 10 (hint: use selection statements together with looping statements).

2. (Counting positive and negative numbers and computing the average of numbers) Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values. Your program ends with the input 0. Display the average as a floating-point number. (For example, if you entered 1, 2, and 0, the average should be 1.5.)

3/25/2015

BCS2233 OOP: Contoh 'Test 1'



1.  Response to the following statements by circling either T (TRUE) or F (FALSE). [10M]

        I.            Java enables users to develop and deploy applications on the Internet for servers, desktop computers, and small hand-held devices.( T / F)

      II.            Java is one of language that support object oriented programming. ( T / F)

    III.            Object-oriented programming (OOP) is a popular programming approach that is replacing traditional procedural programming techniques. ( T / F)

    IV.            Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. ( T / F)

      V.            System.out.println is one of the pre-defined methods in Java. ( T / F)

    VI.            The main method looks like this: ( T / F)

public static void main(String[] args) {
  // Statements;
}

 
 









  VII.            An identifier is a sequence of characters that consist of letters, digits, underscores (_), and dollar signs ($).( T / F)

VIII.            An identifier must start with a letter, an underscore (_), or a dollar sign ($). It cannot start with a digit. ( T / F)

    IX.            An identifier in java can be of any length. ( T / F)

      X.            Logic Errors Produces incorrect result. ( T / F)


2. Match the following Statement / Name to its description. [7M]



No
Statements

Description
        I.             
x = 1;

Constants
      II.             
int x = 1;

Addition
    III.             
double radius;

Declaring and Initializing
    IV.             
final int SIZE = 3;

Multiplication
      V.             
+

Assignment Statements
    VI.             
*

Remainder
  VII.             
%

Declaring Variables

3. Give a brief explanation for the following questions.


         I.            What is debugging? [2 marks]
       II.            What is the difference between a constant and a variable? [2 marks]
     III.            Can Java run on any machine? What is needed to run Java on a computer? [4 marks]
     IV.            Explain the Java keywords. List any five Java keywords. [4 marks]

       V.            What is the Java source filename extension, and what is the Java bytecode filename extension?

4. Evaluate the following expressions: [3 marks]

                    I.            10 + 3 / 2
                  II.            3 * 3 + 3 % 2
                III.            3 + 2 / 2 + -2 * 4

5. Evaluate the following boolean expressions.
 [5 marks]

username=1001;
password = 234;

EXAMPLE  if(username==1001)                                 TRUE

                                 I.            if(password==234)
                               II.            if((username==1001) &&(password==234))
                             III.            if((username==1001)&&(password==789))
                             IV.            if((username==1001)||(password==789))
                               V.            if! (username==1001)

EXAMPLE   Write a for statement to print integer 1 to 20.

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


I.                    Write a for statement to print integer 50 to 60. (3 marks)




II.                  Write a for statement to print the following output. (3 marks)
2                   4            6              8              10



EXAMPLE   Write a while statement to add numbers 11 through 20.

int sum =0;
int counter = 11;
while (counter <=20)
{
sum = sum + counter;
counter++;
}

III.                Write a while statement to add ODD numbers 11 through 10. [5M]



IV.                Write a while statement to continuously read in integers and stop when a negative number is entered.  [5 marks]


8. (Counting positive) Write an algorithm (pseudocode or flowchart)  and java  program that reads an unspecified number of integers, determines how many positive have been. Your program ends with the input 0.

3/22/2015

BCS2233 OOP: Week 8 BCNS

Write a java program for the following flowchart. Use for and while (in desperate section) to demonstrates your understanding.


3/11/2015

BCS2233 OOP: Determine Count Control Loop or Sentinel Control Loop


I.    Write a java statement to print integer 50 to 60.


II.    Write a java statement to print integer 10 down to 0.


III.    Write a java statement to print the following output.
5    10    15    20    25    30


IV.    Write a java statement to add EVEN  integers  1through 10.


V.    Write a java  statement to continuously read in integers and stop when a negative number is entered.


VI.    Write a java statement to continuously read in integers and stop when a 100 is entered.   



3/08/2015

BCS2233 OOP: LAB WEEK 7

1. Consider the following flowchart. Identify:-
1.1 Selection
1.2 Repitition

2. Code the following flowchart (flowchart 1) in Java Program.

Flowchart 1
 
* the following java code can be used to generate random number in range of 0 to 100:-
int X = (int)(Math.random() * 101);
 
3. Consider the following flowchart. What is the difference ?
Flowchart 2
 
 4. Code the following flowchart (flowchart 2) in Java Program.
import java.util.Scanner;
 
public class guessNumber2 {
    
    public static void main(String[] args) {
    // Generate a random number to be guessed
    int X = (int)(Math.random() * 101);
    int jumlah_tekaan=0;
    Scanner input = new Scanner(System.in);
    System.out.println("Sila teka satu nombor antara 0 hingga 100");

    int teka = -1;
    while (teka != X) {
      // Prompt the user to guess the number
      System.out.print("\nMasukkan Nombor anda: ");
      teka = input.nextInt();
      jumlah_tekaan++;
      if (teka == X)
        System.out.println("Tahniah! Tekaan anda tepat--> " + teka);
      if (teka > X)
        System.out.println("Tekaan Anda Terlalu Besar");
      if (teka < X)
        System.out.println("Tekaan Anda Terlalu Rendah");
    } // End of loop 
    
    System.out.println("Jumlah Tekaan Anda ialah :" +jumlah_tekaan);
     
    }
}
 

3/01/2015

BCS2233 OOP: LAB (Selection)


  An electric supply company charges the following rates for its customers:-

No. of unit consumed                              Charges/unit (RM) 
1     - 200                                                           0.218 
201 - 300                                                           0.334                                                   
>= 301                                                               0.516

Read unit consumed and calculates the net amount of the bill for each consumer and print it.

2/22/2015

BCS2233 OOP: Assignment 1

Assignment 111

You are required to provide:-
(i)           Algorithm (Flowchart or Pseudo code) and
(ii)        Java program for each of the following problems.

1. 1 1.(Converting feet into meters) Write a program that reads a number in feet, converts it to meters, and displays the result. One foot is 0.305 meters.

1. 2 2.(Finding the largest) Write a program that input two integers and find the largest.

1. 3 3.SATU Terengganu charges the following rates for its customer:-
Penggunaan
Caj
Minima (RM)
Kuantiti M3
(Meter Padu)
Caj
Setiap M3
0 - 20.00
RM0.42
RM4.00 sebulan
20.1 - 40.00
RM0.65
40.1 - 60.00
RM0.90
60.1 ke atas
RM1.00

Input the amount of water used and calculate the net amount for a customer.


Due date :  9/3/2015 (2 Weeks)

2/12/2015

BCS2233 OOP: Markah Quiz 1


Berikut adalah markah quiz 1 yang di adakan pada 12/2/2015 Khamis.

No. Matric No. Course quiz 1 12/2/15 (16M)
1  13B07002  BCNS 16
2  13B07003  BCNS 16
3  13B07004  BCNS 16
4  13B07006  BCNS 16
5  13B07008  BCNS 16
6  13B07010  BCNS 14
7  13B07011  BCNS 14

2/08/2015

BCS2233 OOP: LAB WEEK 3


Programming Exercises


2.1 (Converting Fahrenheit to Celsius) Write a program that reads a Fahrenheit degree in double from an input dialog box, then converts it to Celsius and displays the result in a message dialog box. The formula for the conversion is as follows:
celsius = (5/9) * (fahrenheit - 32)

Hint


  In Java, 5 / 9 is 0, so you need to write 5.0 / 9 in the program to obtain the correct result.



2.2 (Computing the volume of a cylinder) Write a program that reads in the radius and length of a cylinder and computes its volume using the following formulas:

area = radius * radius * p
volume = area * length


2.3 (Converting feet into meters) Write a program that reads a number in feet, converts it to meters, and displays the result. One foot is 0.305 meters.

2.4 (Converting pounds into kilograms) Write a program that converts pounds into kilograms. The program prompts the user to enter a number in pounds, converts it to kilograms, and displays the result. One pound is 0.454 kilograms.

2.5* (Calculating tips) Write a program that reads the subtotal and the gratuity rate, and computes the gratuity and total. For example, if the user enters 10 for subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total.

2.6** (Summing the digits in an integer) Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer. For example, if an integer is 932, the sum of all its digits is 14.
Hint


  Use the % operator to extract digits, and use the / operator to remove the extracted digit. For instance, 932 % 10 = 2 and 932 / 10 = 93

2/04/2015

BCS2233 OOP Chapter 2 Exercise


1. Match the following Statement / Name to its description. [8M]



No
Statements

Description
        I.             
x = 1;

Increment
      II.             
int x = 1;

Addition
    III.             
double radius;

Declaring Variables
    IV.             
final int SIZE = 3;

Declaring and Initializing
      V.             
+

Assignment Statements
    VI.             
*

Remainder
  VII.             
%

Multiplication
VIII.             
++

Constants


2. Show an evaluation tree for the following expressions: [6 marks]


                    I.            10 + 2 - 4


                  II.            3 + 3 * 3 % 2



                III.            3 + 2 / 5 +2 * 4

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.  ...