Prutt05 Tentamen

1 / 12
About This Presentation
Title:

Prutt05 Tentamen

Description:

Prutt05 Tentamen. Model Answers. Note that many variations are possible to obtain full marks. ... The user clicks on an item and selects 'purchase' option. ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 13
Provided by: karlm

less

Transcript and Presenter's Notes

Title: Prutt05 Tentamen


1
Prutt05 Tentamen
  • Model Answers
  • Note that many variations are possible to obtain
    full marks.

2
Q1.
0,1
1
1
Shopping_Cart
List_of_Item
totalPricefloat
Item purchase
1
totalDiscountfloat
clubMemberbool
Add(Item purchase)
Delete(Item purchase)
itemCountint
Delete( )
Add(Item purchase)

Delete(Item purchase)

Item
Delete( )
Pricefloat
checkout( )
DiscountOnPricefloat
ShoppingCart(Item purchase )
QuantityInt
Book
Clothing
DVD
authorString
sizeInt
artistString
titleString
descriptionString
titleString
MensClothing
WomensClothing
ChildrensClothing
3
  • Q1.(iii)
  • Add(Item purchase)
  • if (purchase.Quantity gt0)
  • this.theItemList.add(purchase)
  • purchase.Quantity--
  • this.itemCount
  • if (purchase instanceOf Clothing
    clubMember1)
  • (purchase instanceOf Book clubMember2)
  • (purchase instanceOf DVD clubMember3)
  • this.totalPrice ( purchase.Price -
    purchase.DiscountOnPrice)
  • else this.totalPrice purchase.Price
  • else
  • // throw an exception OutOfStock error?
  • // of Add()

4
  • Q2.(i)
  • Precondition user has entered the web site. No
    shopping cart exists yet.
  • Actors end_user
  • Scenario
  • The user clicks on an item and selects purchase
    option.
  • A new ShoppingCart object is created, and its
    List_Of_Item component is initialised to contain
    the purchase.
  • Repeated any finite number of times
  • 2.a The user clicks on an item and selects the
    purchase option. The item is added to the
    ShoppingCarts List_Of_Item attribute. OR
  • 2.b The user clicks on an item in the
    ShoppingCart and selects the delete option. The
    item is deleted from the ShoppingCarts
    List_Of_Item attribute.
  • 3.a. The user clicks on the checkout button,
    OR
  • 3.b The user clicks on the empty shopping cart
    button.
  • Postcondition User has placed an order and
    shopping cart is deleted, or else no order and
    shopping cart is empty but still exists.

5
Shopping_Cart
List_Of_Item
ShoppingCart(purchase)

Alt
Add(purchase)
Add(purchase)
Delete(purchase)
Delete(purchase)
Alt
Checkout()
Delete()
Delete()
6
  • Q4
  • import junit.framework.TestCase
  • public class Shopping_Cart_Test extends TestCase
  • private Shopping_Cart testCart
  • private Book testBook new Book(Title1,
    Author1, 10.99, 1.00, 10)
  • // 10 copies in store at 10.99 each, discount
    1.00
  • private Book testBook2 new Book(Title2,
    Author2, 11.99, 2.00, 20)
  • // 20 copies in store at 11.99 each, discount
    1.00
  • protected void setUp()
  • testCart new Shopping_Cart() // no items
  • clubMember2 True
  • testCart.addItem(testBook) // setup with a
    first item
  • protected void tearDown() // not needed

7
  • Q3.
  • For such a small project XP or COTS would seem to
    be the best models. There
  • seems to be no room for large documentation.
    However both these approaches
  • will satisfy any bank needs for project
    visibility. Study the course notes further to
  • appreciate the consequences of these two choices.
    Consider also the many
  • disadvantages of the spiral model and waterfall
    model in this case. Lastly, rapid
  • prototyping doesnt seem necessary here, as the
    product is quite well understood.
  • (We may even be able to buy most of it off the
    shelf!).

8
  • Public void testAdd() // add an item and then
    check its there
  • testCart.addItem(testBook2)
  • assertEquals(testCart.totalPrice, 9.99 9.99)
  • assertEquals(testCart.itemCount, 2)
  • assertEquals(testCart.totalDiscount, 2.00
    1.00)
  • assertEquals(testBook2.getQuantity(), 19)
  • // testBook2 is still in the cart
  • Public void testDelete(Item purchase) throws
    ItemNotFoundException
  • // delete an item and check its gone i.e. back
    in store
  • testCart.delete(testBook2)
  • assertEquals(testCart.totalPrice, 9.99)
  • assertEquals(testCart.itemCount, 1)
  • assertEquals(testCart.totalDiscount, 1.00)
  • assertEquals(testBook2.getQuantity(), 20)

9
  • Public void testDeletItemNotInCart() // try to
    delete a non-existent item,
  • // is this possible via the user interface?
    Maybe?
  • try
  • private Book testBook3 new Book(Title3,
    Author3, 10.99, 1.00, 10)
  • testCart.delete(testBook3)
  • fail(Should raise an ItemNotFoundException)
  • catch (ItemNotFoundException e) //passes the
    test
  • public void testDelete() // empty the cart and
    it should be empty!
  • testCart.delete()
  • assertEquals(testCart.itemCount, 0)
  • assertEquals(testCart.totalPrice, 0.0)

10
  • Q5.
  • ltDOCTYPE Shopping_Cart
  • lt!ELEMENT Shopping_Cart (Shopper, Book, DVD,
    Clothes)gt
  • lt!ATTLIST Shopping_Cart totalPrice REQUIREDgt
  • lt!ATTLIST Shopping_Cart totalDiscount REQUIREDgt
  • lt!ATTLIST Shopping_Cart itemCount REQUIREDgt
  • lt!ATTLIST Shopping_Cart dvdMember (TRUEFALSE)
    FALSEgt
  • lt!ATTLIST Shopping_Cart bookMember (TRUEFALSE)
    FALSEgt
  • lt!ATTLIST Shopping_Cart clothingMember
    (TRUEFALSE) FALSEgt
  • lt!ELEMENT Book (Title, Author)gt
  • lt!ELEMENT Title (PCDATA)gt
  • lt!ELEMENT Author (PCDATA)gt
  • lt!ATTLIST Book Price REQUIREDgt
  • lt!ATTLIST Book DiscountOnPrice REQUIREDgt
  • lt!ATTLIST Book Quantity REQUIREDgt

11
  • lt!ELEMENT DVD (Title, Artist)gt
  • lt!ELEMENT Title (PCDATA)gt
  • lt!ELEMENT Artist (PCDATA)gt
  • lt!ATTLIST DVD Price REQUIREDgt
  • lt!ATTLIST DVD DiscountOnPrice REQUIREDgt
  • lt!ATTLIST DVD Quantity REQUIREDgt
  • lt!ELEMENT Clothing (Style, Size, Description)gt
  • lt!ELEMENT Style (PCDATAMensClothingWomensClothi
    ngChildrensClothing)gt
  • lt!ELEMENT Size (PCDATAXSSMLXL)gt
  • lt!ELEMENT Description (PCDATA)gt
  • lt!ATTLIST Clothing Price REQUIREDgt
  • lt!ATTLIST Clothing DiscountOnPrice REQUIREDgt
  • lt!ATTLIST Clothing Quantity REQUIREDgt

12
  • lt?xml version1.0 encodingUTF-8?gt
  • ltShopping_Cart totalPrice11.99, itemCount1,
    totalDiscount1.00,
  • dvdMemberTRUE, bookMemberTRUE,
    clothesMemberTRUEgt
  • ltBook price11.99, discount_On_Price1.00,gt
  • ltTitlegtMyTitlelt/Titlegt
  • ltAuthorgtMyAuthorlt/Authorgt
  • lt/Bookgt
  • lt/Shopping_Cartgt
  • Q6. The problem here is that item prices need to
    be synchronised. If this is done
  • then it is not possible for cusomers to access
    them while they are being changed.
  • If they are not synchronised then race can
    occur, which leads to the
  • phenomenon described in the question. Study the
    course notes in order to
  • appreciate how to make changes to the code.
Write a Comment
User Comments (0)