Sunteți pe pagina 1din 5

MSCS 236

Assignment 02
(You can do in a group of 2-3 members)
Total: 20 points
Due on Monday, February 15, 2016 at the beginning of class
How to submit the assignment?
Submission: -Soft copy of the Program using digital drop box of D2L

Objective
Upon completion of the following assignment, students will have very good knowledge
on:

Objects vs. components

Interface

In depth Broad range of fundamental concepts of components.

Hands on experience back ground of materials of Components (Super class,


subclass, inheritance, polymorphism, abstract class, abstract method)

Code reuse

Professional practice of writing code

1) Written part: (12 points)


a) Compare and contrast the characteristics of Objects and Components. (4 points)
Bothcomponentsandobjects
haveencapsulationproperties
areaccessedviawelldefinedinterfaces

areconsideredtoimprovethereuseofsoftware
areconsideredtoalleviatethesoftwareevolutionphase
arethoughtofbeingnaturalabstractionsofrealworldentities
arealworldentitycanbemodelled/implementedusingeithernotion
Objects
describe/implementrealworldentities(andtheirhierarchies)
mathematicalmodellingapproachtosoftware
partitionthestatespace
Components
describe/implementservicesofrealworldentities
engineeringapproachtosoftware
partitiontheservicespace

b) Mention differences between direct interface and indirect interface? How they can be
unified? (2+2=4 points)
Direct(procedural)interfaces:
+provideddirectlybyacomponentcorrespondingtointerfacesoftraditionallibraries.
+Definition&implementationbelongtoonecomponent.
Indirect(object)interfaces:
+providedbyobjectsimplementedbyacomponent,correspondingtoobjectinterfaces.
+Definition&implementationmightsitindifferentcomponents.
DirectandIndirectinterfacescanbeunifiedbymeansofstaticobjectsincomponents.

c) i) Discuss the issues, which were discussed in the class, for the evolution of versions
of a component (2 points)
ii) Discuss question 1 c-i) with your own knowledge and experience for additional
issues which are in addition to the issues discussed in the class. ( 2 points)

Interface changes should be minimal when the component evolves. There should be
minimal changes to external dependencies and non-functional (performance, reliability)
requirements for the component. If any of the above changes, then appropriate migration
strategy should be provided to the customer.

2) Programming Part (8 points)

Problem Description
Design a Java Program based on the following specifications:

Write a superclass Account and subclass SavingsAccount and CheckingAccount.

Every Acount has an account number and an interest rate.

Write a method computeInterest(int amount) that computes the yearly interest of


any account.

A SavingAccount gets interest the yearly with the same interest rate for at most
$1000. If the balance is more than $1000, the excess amount will have double
interest rate.

The CheckingAccount will have same interest rate for any balance, no matter
what the actual balance is.

Write a static method that uses polymorphism to compute the interest of any
Account. Supply a test program that tests classes and methods.

[Please use professional practices for writing the java code]

Skeleton

Optional. You can use your own driver if you want to .

Formula used for calculating interest:


Interest= (amount*rate)/100
public class Part2 {
public static void main(String[] args) {
SavingsAccount s = new SavingsAccount("3333", 4);
//4 is interest rate
CheckingAccount h = new CheckingAccount("5555", 5); //5 is interest rate
System.out.println(computeInterest(s, 300)); //amount=300
System.out.println(computeInterest(h, 300));
System.out.println(computeInterest(s, 5000));//amount =5000
System.out.println(computeInterest(h, 5000));
}
public static double computeInterest(Account w, int amount) {
return w.computeInterest(amount);

/* polymorphism implemented over here.....depending on the subclass account ( savings


or checking ) that is passed in the argument Account , the corresponding method in that
class is called */
}
}
abstract class Account {
//private data of the class which can be accesed only through the methods
private String accountNumber;
private double rate;
public Account(String n, double r) { //write code here
accountNumber = n;
rate = r;
}
public double getRate() { //write code here
return r;
}
public abstract double computeInterest(int amount);
/* note that this is declared as abstract since here it doesn't have any meaning but has a
meaning in the savings or checking account class... */
}
class SavingsAccount extends Account {
public SavingsAccount(String n, double r) { //write code here
super(n,r);
}
}
public double computeInterest(int amount) {/write code here
double interest = 0;
if( amount < 1000 )

{
interest = amount*r;
}
else
{
interest = 1000*r + (amount-1000)*2*r;
}
return interest;
}
}
class CheckingAccount extends Account {
public CheckingAccount(String n, double r) {//write code here
super(n,r);
}
public double computeInterest(int amount) {//write code here
return amount*r;
}
}

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