Sunteți pe pagina 1din 7

ASSIGNMENT

ON
Modern Programming
Tools & Techniques I

Submitted to – Submitted by-


Satinder Saini Surendra
MCA 4th sem
D3804A15
10806601
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 :
___surendra__________

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 :

According to me the abstraction is the way to simplify the complex problem. If


the problem is very complex then the abstraction makes it very easy. For
example the tv remote is very complex internally but it is easy to use. So it is
the live example of the abstraction.Abstraction refers to the ability to make a
class abstract in OOP. An abstract class is one that cannot be instantiated. All
other functionality of the class still exists, and its fields, methods, and
constructors are all accessed in the same manner. You just cannot create an
instance of the abstract class.

Encapsulation: encapsulation makes the . the public adata can access by the
other class.data and fields private. We can not access this data only in public
class. The private data can access only with in the class. Encapsulation is also
called the data hiding.

Inheritance is a compile-time mechanism in Java that allows you to extend a


class (called the baseclass or superclass) with another class (called the derived
class or subclass). In Java,inheritance is used for two purposes:

• Class inheritance
• Interface inheritance

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: in the card game black jack sketch we need the following:

• We can use the public class


• We can use the overriding
• A method that will tke the value is needed..
• The card vlue is needed
• we can use the Card, Hand

The rule will be:


The value of a hand is obtained by adding up the values of the cards in
the hand. The value of a numeric card such as a three or a ten is its
numerical value. The value of a Jack, Queen, or King is 10. The value of
an Ace can be either 1 or 11. An Ace should be counted as 11 unless
doing so would put the total value of the hand over 21.

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. For sketching the system to controlling the soda dispensing machine we
need the many parts of object oriented programming. that are following:

• For getting the price of the soda we can use the public method of type
void.

• Then we have to give the name to the getting price method.

private int soda_price;

• The method will be used for main method.

• The main method is:

public static void main(String[] args)

[.............................]

• Despansing the soda:

public void dispensesoda()

Body[....................]
}

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.

• We can give the example of real world is that the bird will fly as their
parents. The bird is the class and the child bird is the subclass. this
subclass is inherithing the bird calss. All the attributes it can use of the
bird class.

• class Person {}

class Employee extends Person {

• class Bicycle {

class MountainBike extends Bicycle {

• the another example of real world the bank account. The bank account
class can b inherited by the current account, saving account..
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. According to java the System.out.print() is used to print the string in one
line. In this method we can display the one line . but in the println the line
break automatically. In which line we used the prinln method the line
break automatically..

If we use like this:

System.out.println("gaurav" );
System.out.println("kakkar " );
System.out.println("saurabh " );
System.out.println("tohana " );

The output will be:


Gaurav
Kakkar
Saurabh
tohana

Class speed

Public static void main (String arg[])

double d, s, di,slite=299790000, d=100;

System.out.print (“days:”+d);

S= d*24*60*60;

d=slite*sec;

System.out.print (“travel light”+di);

}
}

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.

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

• Variable: stdin, n

• Class: test

• Methods: System.out.print(), nextDouble()

• Parameters: arg, System.in

• Keywords: Import, public, class, static, void, main, String, Scanner,


System.in, double, new

S-ar putea să vă placă și