Vous êtes sur la page 1sur 4

Homework Title / No.

: __1_________________________Course Code : CAP310_________

Course Instructor : Lect. Balraj Kumar____________ Course Tutor (if applicable) : ____________

Date of Allotment : _____________________ Date of submission : __22nd Feb_____________

Student’s Roll No._RTb805A02_______ Section No. : _TB805________________________

Declaration:
I declare that this assignment is my individual work. I have not copied from any other student’s work
or from any other source except where due acknowledgment is made explicitly in the text, nor has any
part been written for me by another person.

Student’s Signature : _Rajat Singha____

Evaluator’s comments:
_____________________________________________________________________

Marks obtained : ___________ out of ______________________

Content of Homework should start from this page only:

PART A

Q:1 Define abstraction, encapsulation, modularity and hierarchy in your own terms.

Ans: Abstraction: Abstraction refers to the act of representing the essential features of a
program or system without including the basic details related to that program. In other
words in abstraction only the function the program or system performs is highlighted ,
what and how it happens in the background is hidden.
E.g. consider the case of a car or a software performing the addition of two
numbers .People only drive the car without considering what goes under the body of
the car to move. Similarly user enters two numbers without thinking what happens
behind the interface in adding those two numbers. Thus abstraction hides the basic
details in performing a particular function.

Encapsulation: Encapsulation is the process of wrapping up data members and


functions into a single unit called class. This is done to protect the data members and
functions from unauthorised access and misuse. The encapsulated data members and
functions in the class can be accessed by using the objects declared for that class.
E.g. Skin encapsulates all the human organs and protects them from environmental
pollution and bacteria.

Modularity: Modularity is the process of dividing a program into modules or small


segments or parts which makes the program easily understandable, easy to make and
easy to modify. Using modularity technique the program can be easily managed.
Hierarchy : It is the concept of arranging the data items and functions in a program in
a top-down order. Arranging various items in the hierarchical order supports
abstraction in a good way. E.g .Consider the example of the car. From the outside car
is a single object, once inside one can see various parts arranged together to work in a
co-ordinated manner to run the car. We can say that various parts of the car are
arranged in a hierarchical manner to form a car.

Q:2 Sketch the object-oriented design or the Card game Black-Jack. What are the
key objects? What are the properties and behaviours of these objects? How does
the object interact?

Ans:

Q:3 Sketch the object-oriented design of a system to control a Soda dispensing


machine. What are the key objects? What are the properties and behaviours of
these objects? How does the object interact?

Ans:

PART B

Q:4 In an object oriented inheritance hierarchy, the objects at each level are more
specialized than the objects at the higher levels. Give three real world examples
of a hierarchy with this property.

Ans: Examples of object oriented inheritance hierarchy in which the object at each level are
more specialized than other are:

1) Maruti 800 is the part of the classification car, which in turn is part of class
ground transport, which is under the larger class transport.

2) LIM is the part of the classification LPU, which in turn is part of class University,
which is under the broader and larger class Education.

3) Sea is the part of the classification Earth, which in turn is the part of Planet class,
which comes under the larger class Universe.

Q:5 How do methods System.out.print() and System.out.println() differ? Define a


java constant equal to 2.9979 X 108 that approximates the speed of light in
meters per second.

Ans: System.out.print() method prints the items or elements as output in a single line
whereas System.out.println() prints the output in the next line. Println() works as ‘\n’
used in C ,C++. E.g. If the numbers from 1 to 5 are to be printed then using
System.out.print() method all five numbers will be printed in a single line like 12345
whereas in case of System.out.println() all five numbers would appear in separate
lines like 1
2

3...

Declaration of a java constant:-

Class constant

public static final double s=2.9979E8;

Q:6 Write a code segment that defines a Scanner variable stdin that is associated with
System.in. The code segment should than define to int variables a and b, such
that they are initialized with the next two input values from the standard input
stream.

Ans: import java.util.Scanner;

class add

public static void main(String[] args)

Scanner stdin= new Scanner(System.in);

int a,b,c;

System.out.println(“Enter the first no”);

a=stdin.nextInt();

System.out.println(“Enter the second no”);

b= stdin.nextInt();

c=a+b;

System.out.println(“the sum is”+c);

Q:7 Separately identify the keywords, variables, classes, methods and parameters in
the following definition:
import java.util.*;
public class test
{
public static void main(String[] args)
{
Scanner stdin = new Scanner(System.in);
System.out.print(“Number:”);
double n = stdin.nextDouble();
System.out.println(n + “ * “ + n + “ = “ + n * n);
}
}

Ans: Keywords: import, public, class, static, void, new, double

Variables: stdin, n

Classes: Scanner, test

Method: public static void main(), System.out.print(), System.out.println().

Parameters: String[] args , system.in

Vous aimerez peut-être aussi