Vous êtes sur la page 1sur 10

c

Q a1:

Explain the concept of class and object in object-oriented design. In your answer, do also
differentiate class and instance variables and give examples where you might use either of them

—c In object-oriented programming, a a  is a construct that is used as a blueprint (or


template) to create objects of that class. A a   is a field declared using the
keyword static within a class declaration, or with or without the keyword static within
an interface declaration. A class variable is created when its class or interface is prepared
and is initialized to a default value. The class variable effectively ceases to exist when its
class or interface is unloaded. An  
 a  is a field declared within a class
declaration without using the keyword static . If a class Ô has a field  that is an instance
variable, then a new instance variable  is created and initialized to a default value as part
of each newly created object of class Ô or of any class that is a subclass of Ô. The instance
variable effectively ceases to exist when the object of which it is a field is no longer
referenced, after any necessary finalization of the object has been completed.

Q a2:

Explain the meaning of encapsulation in object-oriented design and desired two benefits that come
with it. How do you implement encapsulation in java?

—c The term  a  
 is used to describe the hiding of the implementation details. The process, or
mechanism, by which you combine code and the data it manipulates into a single
unit, is commonly referred to as  a  
 . Encapsulation provides a layer of security around
manipulated data, protecting it from external interference and misuse. In Java, this is supported by
a and a
.The advantages of encapsulation are information hiding and implementation
independence

Q a3:

Explain how polymorphism can promote extensibility. Give an example to support your explanation

—c uy using polymorphism, we can add as many type to the system with or without any
modification to the general portions of the program, as long as the new class are part of the
inheritance hierarchy that the program generically. For example, if we extend class Animal
to create class Rabbit, we need to write only Rabbit class and the part of the stimulation that
instantiates a Rabbit object.

Q b1:

A) Develop a use case diagram based on the following narrative.

The EyesHaveIt.com uook Exchange is a type of euusiness exchange that does business entirely on
the Internet. The company acts as a clearing exchange for both buyers and sellers of used books.

In order for a person to offer books for sale, she/he must register with EyesHaveIt. The person must
provide a current physical address and telephone number as well as current email address. The
system will then maintain an account for this person. Acces to the system as a seller is through a
secure, authenticated portal.

A seller can list books on the system through a special Internet form. Information required includes
all of the pertinent information about the book, its category, its general condition, and the asking
price. A seller may list as many books as desired. The system maintains an index of all books in the
system so that buyers can use the search engine to search for books. The serach engine allows
searches by title, author, category and keyword.

People desiring to buy books come to sight and search for books they want, when they decide to
buy, they must open an account with a credit card to pay for the books. The system maintains all of
this information on secure servers.e

When a request to purchase is made, along with the payment, TheEyeshaveIt.com sends an email
notice to the seller of the book that was chosen. It also marks the book as sold. The system
maintains this as an open order, until it receives notice that the books have been shipped. Once the
seller receives notice that a listed book has been sold, then she must notify the buyer, via email
within 48 hours that the purchase is noted. Shipment of the order must be made within 24 hours
after the seller sends the notification email. The seller sends a notification to both the buyer and
TheEyeHaveIt.com when the shipment is made.

After receiving notice of shipment, TheEyesHaveIt.com maintains the order in a shipped statuse. At
the end of each month, a check is mailed to each seller for all of those book orders that are have
been in a shipped statuse for thirty days. The thirty-day wait is to allow the buyer to notify
TheEyesHaveIt.com if for some reason the shipment does not arrive, or if the book is not in the same
condition as advertised.

The buyers can, if they desire, enter a service code for the seller. The service code is an indication of
how well the sller is servicing book purchase. Some sellers are very active and use
TheEyesHaveIt.com as a major outlet for selling books. So a service code is an important indicator to
potential buyers.

b) Differentiate between a use case and a scenario.

Q b2

For the given case study, code the solution in java using classes and objects.

Creat a class called uookcollection. This class must have member inner classes called Author and
uook. The uook class must have an inner class called Chapter that represents a single piece of
chapter within a uook object. A uookCollection object must have an array of author objects and an
array of book objects. uook objects must have a single Author object, for simplicity, and an array of
Chapter objects. Add a main method to uookCollection that tests the creation of all of these objects.

Q b3

Given the codes below, answer the questions that follow:

Public abstract class personalLan

Protected String type;

Protected double cost;

Public PersonalLoan(String loanType)

Type = loanType;

Public String getType()

Return type;

Public double getCost()

Return cost;

Public abstract void setcost();

Public abstract String toString();

Important javax.swing.*;

Public class HomeLoan extends PersonalLoan

Public HomeLoad()
{

Super(͞Home͟);

setCost();

Public void setCost()

String input = JOptionPane. ShowInputDialog (null, ͞How many square feet is the house?͟);

Int sqft = Integer.parseInt(input);

If (sqft > 2000)

Cost = 500;

Else

Cost = 350;

Public String toString()

String output = ͞A͟ + type+ ͞ loan costs $͟ + cost +͟ per month͟;

Import javax.swing.*;

Public class CarLoan extends PersonalLoan

Public CarLoan()

Super(͞Car͟);

setCost();

Public void setCost()


{

String input = JOptionPane.showInputDialog(null, ͞How many years old is the car?͟);

Int age = Integer. parseInt(input);

If(age>3)

Cost = 180;

Else

Cost = 295;

Public String toString()

String output = ͞A͟+ type+͟ loan costs $͟ + cost+͟per month͟;

Return output;

c

c c
 c c c c  c c  c

 c 
   c

c
c  
 ccc
c  
 c !cc
c  
 c !c
 c
c c
c 
c 
   "#c

c c
c c c
c $c
c 
c 
   "cc !cc !c
#c
c c

c c c%cc
c c c%cc
c c
 c%c
c
c c c
c $c
c c
c 
c  c   !"#c
c c
c c  & &"'( c)cc'c*c#c
c c  & &"'( cc'c*c#c

c c  & &"'( c  c'c*c


 #c
c $c
$c
c

 c+ 
!c, c 
   c
c
c c !c c
c c
c 
c+ 
!"#c
c c
c c c
c $c

c 
c+ 
!" !cccc !cc !c
# c
c c
c c "cc
#c
c c  c%cc
c $c
c 
c  c   !"#c

c c
c c &   !"#c
c c  & &"'- c'*c #c
c $c
$c
c

 c  c, c 


   c

c
c c !c !c
c c !c 
c
c c !c!!c
c c
c 
c  " !c c !cc !cccc !cc !c
# c
c c
c c "cc
#c
c c !c%c c
c c  
c%cc
c c !!c%cc c

c $c
c 
c  c   !"#c
c c

c c &   !"#c


c c  & &"' !c'c* !#c
c c  & &"'+ 
c'c* 
#c
c c  & &"'.!!c'c*!!#c
c $c
$c
c

c c

 c 
   c
c
c 
c 
c  c" !c/0! #c
c c

c c  
   cc
c c c
c c c%cc+ 
!"' 'c1223c' 'c'  '#c
c c &   !"#c
c c c
c c c%cc  "'4 c5'c'c('c'6! 'c7338c
'9:c)  'c'4 c5'#c
c c &   !"#c
c $c
$c

&c 9 c;c<=
c< c

 c c c c  c & c
&c ; c>-)c(?6@66c c c =
c< c

c  c  c c
 c c c
 !c !c!c c,c c

c
> c c cc
c c c 
c c
 c  cc c
 c6,cc c(<c"7#c 
 cc c 
c c c
 c
 
   cc c c c ,c
c
Ac
c cc c  c c 
 cc 
c
  c c
 "  c
,c c  c #&c

º 

a cc i c
a ccc 
c  c  ccc i c c c 
c cc
cc c c c   cc cc c
c c c  c
c
 c c
c c c c c  c c c c c c  c
c
a cc c 
c c i c c c c
c

c c
c cc cc  c ci c cc c
 c
  ccc

  c cc   c
r   
 c
i c
c cc cc c c
  ccc c
c c c
c
 cc c c  c 
 cc
c cc cc
c
c
c
c

Vous aimerez peut-être aussi