In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called...

23
In class exercise In class exercise (I) (I) Problem specification: Problem specification: An e-commerce company based in An e-commerce company based in Maryland, U.S. called Dogwood, needs Maryland, U.S. called Dogwood, needs an online sale system. You are asked to an online sale system. You are asked to write the part of the system to deal write the part of the system to deal with sale order. with sale order.

description

First SaleOrder Design SaleOrder -itemQuantity: integer -unitPrice: double -itemSold: string -customerName: string +calTax(): double … double calcTax(){ return itemQuantity*unitPrice*0.05; }

Transcript of In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called...

Page 1: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

In class exercise (I)In class exercise (I)

Problem specification:Problem specification:An e-commerce company based in An e-commerce company based in

Maryland, U.S. called Dogwood, needs Maryland, U.S. called Dogwood, needs an online sale system. You are asked an online sale system. You are asked to write the part of the system to deal to write the part of the system to deal

with sale order.with sale order.

Page 2: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

Stage OneStage One• Step I. Create the class library for sale order

Implement the sale order class according to the following specification. Please note that this class is not responsible for getting input from users. You must assume that the information needed is passed in through its constructor. Class Attributes OperationsSaleOrder customName, Calculate price before tax Calculate

itemSold, Calculate tax amountitemQuantity, Calculate total priceunitPrice Display a receipt with custom name,

item sold,quantity, unit price, tax amount and total price.

• Step II. Write an application using the sale order libraryWrite an application to test the above class you create. Basic things you need to do are to create an object of SaleOrder and to see if the receipt is displayed properly.

Page 3: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

First SaleOrderFirst SaleOrder Design DesignSaleOrder

-itemQuantity: integer-unitPrice: double-itemSold: string

-customerName: string

+calTax(): double…

double calcTax(){ return itemQuantity*unitPrice*0.05;}

Page 4: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

Result of Stage One:Result of Stage One:• Your library works so

well for Dogwood• Another two e-

commerce companies based in Maryland, Elm and Holly, bought your library and used it in their on-line sale application as well.

Page 5: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

Stage Two:Stage Two:

• Requirement changes:Dogwood’s business is booming and they decide to extend their business to Delaware.

You are asked to rewrite the sale order library to deal with the taxation rule with both Maryland and Delaware.

Page 6: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

• Step I. Changing requirement leading to changing sale order library

• Step II. Write an application using the new sale order library

Write an application to test the above class you create. Basic things you need to do are to create an object of SaleOrder and to see if the receipt is displayed properly for both Maryland and Delaware customers.

Page 7: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

Result of Stage Two:Result of Stage Two:• Your library works so well

for Dogwood’s business in Delaware and Maryland.

• You also sold your new library to an Delaware and Maryland e-commerce firm called Chestnut.

• Due to your change to sale order library, Elm and Holly are affected.

Page 8: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

Stage Three:Stage Three:

• Requirement changes:Dogwood’s business is booming again and they decide extend their business to the rest of U.S. You are asked to rewrite the sale order library to deal with the taxation rule with all the states in U.S..

Page 9: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

• Step 0. Before we do anything, we need to sit back and think first.

Page 10: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

What got us into this

mess?

Identify the changing

partHow can we make

our design

flexible?design

Requirement changes

What is changing in sale order?

Implement changes without

affecting the existing

tax and how tax is calculated

Separate changing

part

Page 11: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

New SaleOrderNew SaleOrder Design Design

SaleOrder…

-saleTax: SaleTax

+calTax(): double…

USTax

+calTax(…): double

CanadaTax

+calcTax(…): double

GermanyTax

+calcTax(…): double

<<interface>>SaleTax

+calcTax(…): double

double calcTax(){ return saleTax.calcTax(…);}

Page 12: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

• Step 1. Implement the new sale order class according to the new design

Page 13: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

• Step II. Write an application using the new sale order library

Write an application to test the above class you create. Your application should be something like:

SaleOrder saleOrder1 = new saleOrder(“Joe”,“appletSeed”,10,1.0, new USTax());

SaleOrder saleOrder2 = new saleOrder(“Mary”,“roseTree”,2,25.0, new CanadaTax());

Page 14: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

Change requirement on tax Change requirement on tax calculation on old designcalculation on old design

SaleOrder

-itemQuantity: integer-unitPrice: double-itemSold: string

-customerName: string

+calTax(): double…

App1

App2

App3

App4

Page 15: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

Change requirement on tax Change requirement on tax calculation on new designcalculation on new design

SaleOrder…

-saleTax: SaleTax

+calTax(): double…

USTax

+calTax(…): double

CanadaTax

+calcTax(…): double

GermanyTax

+calcTax(…): double

<<interface>>SaleTax

+calcTax(…): double

App1

App2App3

NewZealandTax

+calTax(…): double

App4

Page 16: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

In class exercise (II)In class exercise (II)Problem One Specification:Problem One Specification:

1.1. You and your friend started a company to deliver software You and your friend started a company to deliver software solution to customer problem. solution to customer problem.

2. Your first business is from Salisbury University Register’s 2. Your first business is from Salisbury University Register’s office. They are using a class library to keep course office. They are using a class library to keep course information. Their current class library allow to sort the information. Their current class library allow to sort the students list using a selection sort. students list using a selection sort.

3. Now they ask you to improve the design to allow different 3. Now they ask you to improve the design to allow different sorting strategy being used.sorting strategy being used.

Page 17: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

Current Course ClassCurrent Course Class Design DesignCourse

-title: string-instructor: string-students: string[]

……

+sortStudents(): void…

void sortStudents(){ // selection sort of students array

… …}

Course calcII = new Course(…);…calcII.sortStudents();…

Application

Page 18: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

New Course ClassNew Course Class Design DesignCourse

-title: string-instructor: string-students: string[]

??????

+sortStudents(): void…

void sortStudents(){ // sort of students array

??????}

Course calcII = new Course(…, new BubbleSort()); or calcII.setSortStrategy(new BubbleSort());

calcII.sortStudents();…

Application

Page 19: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

Problem Two Specification:Problem Two Specification:

1. Your second business is from Perdue Stadium 1. Your second business is from Perdue Stadium Ticket Office. They asked you to write a class Ticket Office. They asked you to write a class library to calculate ticket sale price.library to calculate ticket sale price.

2. Here are the rule for ticket sale at Perdue 2. Here are the rule for ticket sale at Perdue Stadium:Stadium:

- Ticket sale price consist of two parts: ticket price and sale tax.

- Ticket price also varies between children, and adult.

Page 20: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

• Short sighted with quick and dirt approach

• Long term with solid and clear approach

Your viewYour view

Page 21: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

SaleOrderSaleOrder Design Design

SaleOrder…

-saleTax: SaleTax

+calTax(): double…

USTax

+calTax(…): double

CanadaTax

+calcTax(…): double

GermanyTax

+calcTax(…): double

<<interface>>SaleTax

+calcTax(…): double

double calcTax(){ return saleTax.calcTax(…);}

Page 22: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

BubbleSort+sort(string[]):void

SelectionSort+sort(string[]):void

QuickSort+sort(string[]):void

<<interface>>SortStrategy

+sort(string[]):void

Course

-title: string-instructor: string-students: string[]

-sortStrategy: SortStrategy

+sortStudents(): void+setSortStrategy(SortStrategy): void

void sortStudents(){ // sort of students array sortStrategy.sort(students);}

Page 23: In class exercise (I) Problem specification: An e-commerce company based in Maryland, U.S. called Dogwood, needs an online sale system. You are asked to.

US+getAmt(…):doubld

Canada+getAmt(…):double

Germany+getAmt(…):double

<<interface>>TaxStrategy

+getAmt(…):double

TicketSale

-priceStrategy: PriceStrategy-taxStrategy: TaxStrategy

+getAmt(): double

double getAmount(){ return priceStrategy.getAmt(…)

+ taxStrategy.getAmt(…);}

Senior+getAmt(…):doubld

Children+getAmt(…):double

Adult+getAmt(…):double

<<interface>>PriceStrategy

+getAmt(…):double