Você está na página 1de 10

SIT232

Object-Oriented Development

Trimester 1, 2016

Assignment 1:
Programming Project 1

Due Date: 5pm Tuesday May 3rd

Work submitted late without documented approval of the Unit Chair will be penalised.
Assignments that are submitted after the submission date will be subject to a mark penalty equal
to 10% of the marks per day of the marks available for the piece of work, up to and including
three days after the published due date. Assignments submitted more than three days after the
published submission date will not be marked.

This assessment task must be completed individually, no group work is permitted.

All work completed/submitted as part of this assessment task must be your own, individual
work. Any content drawn from other materials, including unit materials, must be clearly quoted
where appropriate, and/or clearly referenced. All students should review and be familiar with
the content provided by the University regarding how to reference other materials:

http://www.deakin.edu.au/students/study-support/referencing

And in particular the information provided regarding Academy Integrity:

http://www.deakin.edu.au/students/study-support/referencing/academic-integrity

Unit Learning Outcomes

ULO 1 – Apply object-oriented concepts including abstraction, encapsulation, inheritance, and


polymorphism.
You will be required to demonstrate the correct application of object-oriented concepts including
abstraction, encapsulation, inheritance, and polymorphism.

ULO2 – Solve programming problems using object-oriented techniques and the C# programming
language.
You will be required to construct one or more object-oriented applications using the C#
programming language.
Question 1 (30 marks)

Objective: In this task you will be required to demonstrate your mastery / understanding of the
C# programming language. In the first few weeks of the unit we reviewed the basic syntax for
constructing an object-oriented application. As such, the instructions in the question below
should allow you to develop a working application straightforwardly. To complete this task you
will need to know how to develop logic for a program (knowledge from the pre-requisite unit),
and basic object-oriented concepts and the syntax of the C# programming language (from
studies in this unit).

Note: This task is a programming task worth 30 marks. If your submitted solution fails to
compile and/or run properly you have failed this task and will be penalized 50% of the
available marks for this question, i.e., you will lose 15 marks.

For this task we will be preparing an application to model the stock control and sales system
for a supermarket. Fundamentally, the products that supermarkets sell will be divided into
two categories:
 Discrete products – these items are supplied to the supermarket and sold as individual
units, e.g., a packet of chips; and
 Weighed products – these items are supplied to the supermarket in bulk and sold on
the basis of some measure such as $5 per kilogram which is weighed at the time of
purchase, e.g., fruit and vegetables
This question guides you to construct the bulk of the application, the next question will extend
this application. Sample output can be found at the end of this question sheet. Along with this
question, two C# program files have been provided that must be used in completing the
assignment:

 Program.cs – this file contains the Main method which creates the initial data and
invokes the methods in the classes you define to establish stock levels and perform an
example purchase; and
 Line.cs – this class coordinates the creation of lines of stock as well as representing
individual stock lines in the OO model.

No modifications are permitted to these files for this question. Any changes made to these
provided files for this question will result in a penalty of 5 marks per file.

Start by creating a new C# console application containing the above files. Below you will find
a specification of the features required for each class you need to define. For the majority of
these features, there are no problems to be solved and you only need to implement that
feature directly, thereby demonstrating your knowledge of the relevant OO concept. For
example, if you are required to add a feature to a class:
 A private string attribute named ‘_BirthDate’
You would write in the class:
private string _BirthDate;
Class features that will likely require additional thought are indicated below using a  symbol
for the bullet point.

SIT232 Object-Oriented Development Due: 5pm Wednesday May 3rd


Trimester 1, 2016: Programming Project 1 Page 1
Note that you may not be able to complete some of these features until other classes are
completed, so if you get stuck, continue with the rest of the question and return later! The
classes and features you need to write/define to complete Question 1 are as follows:

Create a new class ‘StockQuantity’ with the following features:


 The class is abstract; and
 The class has no members defined (it is an empty class).

Create a new class ‘DiscreteStockQuantity’ with the following features:


 Inherits from the class ‘StockQuantity’;
 A private integer attribute ‘_Quantity’;
 A public read-only property encapsulating the above attribute; and
 A public custom constructor which accepts a single parameter quantity (integer) that
initialises the above attribute.

Create a new class ‘VolumeStockQuantity’ with the following features:


 Inherits from the class ‘StockQuantity’;
 A private double attribute ‘_Quantity’;
 A public read-only property encapsulating the above attribute; and
 A public custom constructor which accepts a single parameter quantity (double) that
initialises the above attribute.

Create a new class ‘Item’ with the following features:


 A private integer attribute ‘_Quantity’;
 A private string attribute ‘_Description’;
 A private double attribute ‘_Weight’;
 Public read-only properties encapsulating the above attributes;
 A public custom constructor which accepts parameters quantity (integer), description
(string), and weight (double) that initialises the above attributes; and
 Overrides the ToString() method to return a string in the format1:
quantity description (weight kg)

Create a new class ‘Receipt’ with the following features:


 A private List<> of Item objects named ‘_Items’;
 A public read-only property encapsulating the above List<> (see notes below);
 A public method Add which accepts a single parameter of an Item object (item) and
adds the item to the _Items List above; and
 A public method GetText() which has no parameters and returns a string containing
the ToString() for every element stored in the _Items List above, one per line (see notes
below).

1Note that text appearing in italics and underlined, e.g., example, refers to values stored in the object’s attributes.
The remaining parts of the text are just are reproduced as indicated.
SIT232 Object-Oriented Development Due: 5pm Wednesday May 3rd
Trimester 1, 2016: Programming Project 1 Page 2
Create a new class ‘Stock’ with the following features:
 The class is abstract;
 A private attribute to refer to a Line object named ‘_Line’;
 A public read-only property encapsulating the above attribute;
 A public custom constructor which accepts a single parameter line (Line) that
initialises the above attribute;
 Three public abstract methods, as follows:
public abstract void AdjustStock(StockQuantity quantity);
public abstract bool Purchase(StockQuantity quantity, out Item item);
public abstract void Restock();

Create a new class ‘DiscreteStock’ with the following features:


 Inherits from the Stock class;
 A private integer attribute named ‘_StoredStock’;
 A private integer attribute named ‘_ShelfStock’;
 A private double attribute named ‘_WeightPerItem’;
 Public read-only properties encapsulating the above attributes;
 A public custom constructor which accepts parameters for line (Line) and
weightPerItem (double) that passes the line parameter to the base class’ constructor
and initialises the above attributes (initialise both stored and shelf stock to zero);
 Implements/overrides the AdjustStock() method:
o If the quantity is a discrete quantity, add the specified quantity to stored stock;
o If the quantity is not a discrete quantity, it is ignored.
 Implements/overrides the Purchase() method:
o Determine the number of items to be purchased:
 If the quantity is a discrete quantity, the number of items to be
purchased will be the quantity specified;
 If no quantity is specified (null value) or the quantity specified is not a
discrete quantity, the number of items to be purchased will be a single
item (one item);
 If the number of items to be purchased exceeds the number of items on
the shelf (the shelf stock), then the number of items to be purchased is
reduced to be equal to the shelf stock, i.e., if you wanted to buy five items
but there was only three on the shelf, you could only buy three items;
o If the number of items to be purchased is zero, the item output parameter is set
to null and a value of false is returned;
o Otherwise the items output parameter is assigned an Item object created with
quantity set to the amount purchased, the line’s description, the weight set to
the total weight of those items (number of items * weight per item), and a value
of true is returned;
 Implements/overrides the Restock() method, where any stored stock is added
to/moved to the shelf stock;
 Overrides the ToString() method to return a string:
shelf stock
or if there is also stored stock:
shelf stock (stored stock in storage)

SIT232 Object-Oriented Development Due: 5pm Wednesday May 3rd


Trimester 1, 2016: Programming Project 1 Page 3
Create a new class ‘WeighedStock’ with the following features:
 Inherits from the Stock class;
 A private double attribute named ‘_StoredStock’;
 A private double attribute named ‘_ShelfStock’;
 A private double attribute named ‘_DefaultPurchase’;
 Public read-only properties encapsulating the above attributes;
 A public custom constructor which accepts parameters for line (Line) and
defaultPurchase (double) that passes the line parameter to the base class’ constructor
and initialises the above attributes (initialise both stored and shelf stock to zero);
 Implements/overrides the AdjustStock() method:
o If the quantity is a volume quantity, add the specified volume to stored stock;
o If the quantity is not a volume quantity, it is ignored.
 Implements/overrides the Purchase() method:
o Determine the volume of items to be purchased:
 If the quantity is a volume quantity, the number of items to be purchased
will be the quantity specified;
 If no quantity is specified (null value) or the quantity specified is not a
volume quantity, the number of items to be purchased will be the default
purchase;
 If the volume to be purchased exceeds the volume on the shelf (the shelf
stock), then the volume to be purchased is reduced to be equal to the
shelf stock, i.e., if you wanted to buy five kilograms but there was only
three kilograms on the shelf, you could only buy three kilograms;
o If the volume of items to be purchased is zero, the items output parameter is set
to null and a value of false is returned;
o Otherwise the item output parameter is assigned an Item object created with
quantity set to one, the line’s description followed by the text “weight kg”, the
weight set to the volume purchased, and a value of true is returned;
 Implements/overrides the Restock() method, where any stored stock is added
to/moved to the shelf stock;
 Overrides the ToString() method to return a string:
shelf stock kg
or if there is also stored stock:
shelf stock kg (stored stock kg in storage)

SIT232 Object-Oriented Development Due: 5pm Wednesday May 3rd


Trimester 1, 2016: Programming Project 1 Page 4
Notes:
 Duplicate code must be avoided wherever possible.
 Additional class members (attributes, properties, and methods), although not required,
may be introduced to the above classes if you wish, however you must ensure such
members are encapsulated appropriately. As indicated above however, no changes
may be made to the Program or Line classes for any purpose for this question.
 When encapsulating a List<> collection in a property, you are required to use the
ReadOnlyCollection<>, as described in Workbook Task 4.1 and illustrated in the
following example:
using System.Collections.ObjectModel;

private List<int> _Numbers = new List<int>();
public ReadOnlyCollection<int> Numbers
{
get { return _Numbers.AsReadOnly(); }
}
 To create a multi-line string, the simplest approach is to use the StringBuilder class
which is described in Workbook Section 10.2.8 and illustrated in the following
example2:
public string CountToTen()
{
StringBuilder sb = new StringBuilder();
for(int i = 1 ; i <= 10 ; i++)
sb.AppendLine(string.Format(“Number {0}”, i));
return sb.ToString();
}

Build, test, and debug your program. Once complete, keep a copy to submit as your
Question 1 solution (Question 1 is marked separately to Question 2).

2 Note that this example is not particularly realistic, and there are other ways to do this, however the example
illustrates a technique you can use for the project requirements above.
SIT232 Object-Oriented Development Due: 5pm Wednesday May 3rd
Trimester 1, 2016: Programming Project 1 Page 5
Question 2 (20 marks)

Objective: In this task you will be required to demonstrate your mastery / understanding of
object-oriented relationships by extending your solution to the first task. This task focuses on
Weeks 4-6 (Relationships, Inheritance, and Polymorphism). Unlike the first task, you are not
provided with step-by-step instructions to complete this task. To complete this task you will need
to know how to create objects, establish relationships between them, and work with those
objects/relationships to build effective functionality, i.e., to demonstrate you can successfully
write code using an object-oriented programming language.

Note: This task is a programming task worth 20 marks. If your submitted solution fails to
compile and/or run properly you have failed this task and will be penalized 50% of the
available marks for this question, i.e., you will lose 10 marks.

For this task you are required to extend your solution to the first question to support a third
category of items: pre-packed items. Pre-packed items, such as meat products (consider
sausages or minced meat for instance), are stock lines that are purchased in bulk by the
supermarket and then packaged into discrete items before being placed on the shelf for a
customer to select for purchase.

Your solution must include the following features:


 Interfaces, inheritance and/or polymorphism must be exploited where appropriate;
 Duplicate code must be avoided wherever possible (delegation is expected);
 Stored stock will be a single volume figure similar to WeighedStock;
 Shelf stock will be discrete items, however they may not all be the same weight (so you
cannot use a count and default weight for example);
 Purchases again can only be taken from shelf stock, in discrete items whose weight is
determined during restocking;
 Restocking the shelf again requires carrying stock from stored stock to shelf stock,
however this must include converting from a volume form (the stored stock) to a
discrete form (the shelf stock) which can vary in weight;
 Changes can be made to the code you wrote for Question 1 and to the provided Line
class, however these changes must be restricted to a minimum (only changes required
to support the new type of stock are permitted);
 You must modify the Program class to demonstrate creating pre-packed items,
stocking them, and their purchase; and
 The output for your program must be similar to the output shown above for Question
1, subject to the changes required for this question.

Build, test, and debug your program. Once complete, submit your solution to this
question separately to your Question 1 solution (Question 1 is marked separately to
Question 2).

SIT232 Object-Oriented Development Due: 5pm Wednesday May 3rd


Trimester 1, 2016: Programming Project 1 Page 6
SUBMISSION REQUIREMENTS

Please note the following submission requirements:


 All classes and interfaces must be stored in separate files, e.g., the Receipt class must
be in the Receipt.cs file;
 Only C# source files (*.cs) need to be submitted, you do not need to submit the whole
Visual Studio solution/project files;
 Executable files (*.exe) should not be submitted, your program will be recompiled by
the marker;
 All files relevant to your answer for each question should be submitted, i.e., you should
include a copy of any provided files and/or unmodified files;
 You may combine the files for each task into a single ZIP file, however other
compressed file formats, e.g., RAR and 7z, will not be accepted (use separate folders if
you are submitting multiple questions in one ZIP file);
 Further submission instructions are provided in CloudDeakin.

SIT232 Object-Oriented Development Due: 5pm Wednesday May 3rd


Trimester 1, 2016: Programming Project 1 Page 7
MARKING SCHEME

Question 1:

 2 marks: Abstract classes have been defined correctly;


 2 marks: Attributes of simple types have been defined correctly;
 2 marks: Attributes of the List type have been defined correctly;
 2 marks: Attributes of simple types have been encapsulated correctly;
 3 marks: Attributes of the List type have been encapsulated correctly;
 2 marks: Custom constructors have been defined correctly;
 2 marks: ToString methods have been overridden correctly;
 3 marks: Receipt GetText method has been defined correctly;
 3 marks: DiscreteStock Purchase method has been defined correctly;
 3 marks: WeighedStock Purchase method has been defined correctly;
 3 marks: DiscreteStock and WeighedStock AdjustStock methods defined correctly;
 3 marks: DiscreteStock and WeighedStock Restock methods defined correctly;
 Penalties:
o -15 marks: program failed to compile or crashed;
o -5 marks: Program class modified;
o -5 marks: Line class modified.

Question 2:

 2 marks: Delegation used appropriately;


 2 marks: Pre-packed stored stock represented reasonably;
 2 marks: Pre-packed shelf stock represented reasonably;
 3 marks: Shelf stock representation allows for different sizes;
 2 marks: Purchases are in the form of discrete items;
 3 marks: Restocking converts volume form to discrete form appropriately;
 2 marks: Program class modifications to demonstrate pre-packed items reasonable;
 2 marks: Program output shows pre-packed item stock levels reasonably; and
 2 marks: Program output shows pre-packed items on receipt reasonably.
 Penalties:
o -10 marks: program failed to compile or crashed;
o -5 marks: Q1 classes modified outside of specifications;
o -5 marks: Program class modified outside of specifications;
o -5 marks: Line class modified outside of specifications.

SIT232 Object-Oriented Development Due: 5pm Wednesday May 3rd


Trimester 1, 2016: Programming Project 1 Page 8
SAMPLE OUTPUT FOR QUESTION 1

=====================
Stock Before Purchase
=====================
- 111111 - Original Corn Chips 150g Stock: 8 (20 in storage)
- 222222 - Special Supreme Pizza 500g Stock: 1 (50 in storage)
- 333333 - Golden Delicious Apples Stock: 2.000 kg (15.000 kg in storage)
- 444444 - Button Mushrooms Stock: 1.000 kg (5.000 kg in storage)

=======
Receipt
=======
5 Original Corn Chips 150g (0.75 kg)
1 Special Supreme Pizza 500g (0.5 kg)
1 Golden Delicious Apples 0.555 kg (0.555 kg)
1 Button Mushrooms 0.035 kg (0.035 kg)
1 Button Mushrooms 0.965 kg (0.965 kg)

====================
Stock After Purchase
====================
- 111111 - Original Corn Chips 150g Stock: 3 (20 in storage)
- 222222 - Special Supreme Pizza 500g Stock: 0 (50 in storage)
- 333333 - Golden Delicious Apples Stock: 1.445 kg (15.000 kg in storage)
- 444444 - Button Mushrooms Stock: 0.000 kg (5.000 kg in storage)

SIT232 Object-Oriented Development Due: 5pm Wednesday May 3rd


Trimester 1, 2016: Programming Project 1 Page 9

Você também pode gostar