You are on page 1of 4

MODULE 02

    DEBUG YOUR SKILLS

1. Distinguish the terms “Object” and “Class”.


    Answer:

A class serves as an object's template. Object behavior is also described by a class. A member or
"instance" of a class is an object.

Every property of an object has a state in which those values are either explicitly declared by
you or are determined by default settings.

2. Consider the scenario of buying flowers from a florist. Outline the objects in such a
transaction together with the messages exchanged.
Answer:
Maria as an object

attributes:
    name = Maria
    address = gundaway
    budget = 400
methods:
    purchase () {
        Flourist.takeOrder ( “maria”, “roses”, “gundaway”, “19  june”)
}
getBudget () { return budget}

Flourist
    attributes:
        name = flourist
    methods:
        takeOrder ( who, stock, address, date ) {
        check with flower shop on stock availability
        check with flower shop delivery schedule
        if ok then {
            instinct flower shop to deliver stock to address on date
        return ok
}    else return not ok
}

3. Given a class definition Rectangle below, describe the structure of any 3 instances of
Rectangle.
Answer:

Class Rectangle {
Attributes:
Length
Width
Methods:
getLength() { return length }
getWidth()  { return wirth }
draw()             { … }
}

With your own inbuilt variables directly dumping into the program. That means a user is    
required to submit the input values.

A method named getLength() that returns the length


    of this rectangle.
A method named getWidth() that returns the width
    of this rectangle.

4. How would you implement the concept of class and method in a non-object-oriented
programming language such as COBOL, Pascal or C?
Answer:
Because they lack the idea of inheritance, COBOL, Pascal, and C are not OOP (object oriented
programming) languages. Although we can use struts in COBOL, Pascal, and C, these languages lack
suitable classes and methods. Struts also lack the ability to have private and public members.
Polymorphism cannot be found in COBOL, Pascal, or C.
5. Define using the following structure a class definition for cars. A car generally has abilities to
start, move forward, and move backward, stop and off. A car can also return to its relative
location. The starting location is a value 0.

 Answer:

Class Car {
Attributes: 
Name    =    Car
Methods:
StartingLocation ()
Check the car keys and start
Move the car using accelerator and steering wheel
Turn off the car while your in the parking and leave
}

The car falls under a car category, which establishes limitations on things like the
range of permitted size, engine power, weight, and other factors. The values defined by the
car model settings must not be in contradiction with the limitations imposed by the
automobile category. For instance, turn the wheel left, turn the wheel right, and then press
the throttle.
6.Distinguish between a client and a server

Answer:

The primary distinction between a client and a server is that a client is a device or
program that makes service requests via the internet, whereas a server is a device or
program that fulfils such requests for clients.

7. A client communicates with a server by sending a _______ to the server. The ___________ is
a call on a _____________ of the server. 
Answer:
 Request
    
  
8.          Using the figure below, create a program using any JAVA programming text editor (Sublime
Text,Atom, Notepad++, Textpad, gEdit) or an IDE (such as Eclipse or NetBeans).

Programs

Circle.java

public class Circle { // save as "Circle.java"

// private instance variable, not accessible from outside this class

private double radius;

private String color;

// 1st constructor, which sets both radius and color to default

public Circle() {

radius = 1.0;

color = "red";

// 2nd constructor with given radius, but color default

public Circle(double r) {

radius = r;

color = "red";

}
// A public method for retrieving the radius

public double getRadius() {

return radius;

// A public method for computing the area of circle

public double getArea() {

return radius*radius*Math.PI;

Testcircle.java

public class TestCircle { // save as "TestCircle.java"

public static void main(String[] args) {

// Declare and allocate an instance of class Circle called c1

// with default radius and color

Circle c1 = new Circle();

// Use the dot operator to invoke methods of instance c1.

System.out.println("The circle has radius of "

+ c1.getRadius() + " and area of " + c1.getArea());

// Declare and allocate an instance of class circle called c2

// with the given radius and default color

Circle c2 = new Circle(2.0);

// Use the dot operator to invoke methods of instance c2.

System.out.println("The circle has radius of "

+ c2.getRadius() + " and area of " + c2.getArea());

You might also like