Assignment 4 – OOP: Encapsulated Class This is an exercise in file I/O management through an encapsulated class, not an exercise in List or Array management. If you declare a collection such as an...


Assignment 4 – OOP: Encapsulated Class


This is an exercise in file I/O management through an encapsulated class, not an exercise in List or Array management.
If you declare a collection such as an array or List outside of a method or as a property,

It will not be graded
.

You must think of a multi-user environment.
Read and understand the entire question before attempting to answer



/76


An

encapsulated

class contains both the properties and the methods required to instantiate and manage objects of the class. The class you create will save and retrieve records from a text file. It will not store things in memory (i.e. not in an array).



Note this is good practice for later, you can replace it with one that uses a relational database table. If the class name and its
method signatures
are the same, applications will run & not know the storage mechanism has been replaced.


This is

abstraction

or

decoupling

… applications become rigid and fragile when they talk directly to (are
tightly coupled
to) a specific data storage mechanism.




Where you see

XX
, insert your initials instead.


1. Create a new Windows Forms project.


2.
[1 mark]
Add a folder to your project called

XXClasses
. If you prefer, you can use a separate

XXClassLibrary

project.


XXSalesService class


This class you will create manages sales and services items in a dentist office. Services are, like cleaning and xRay, while others are products sold, like electrical toothbrushes and prescribed toothpaste or conditioners; but if it is a procedure like a tooth filling, it also stores the number of minutes it will take (so they can tell customers how long the appointment will be).



[1 mark]
Add a class called

XXSalesService

to your XXClasses folder. Add the following properties and methods – they must be public instance methods unless stated otherwise:


1.
[2marks]
Add the following properties:


a. Strings

SaleServiceName


(e.g.
tooth filling).


b. Double

Price


(Each item/service sold has a price)


c. Boolean

IsProcedure


d. Integer

Minutes



i.

[1 mark]

(If the service is a procedure, it also stores the number of minutes it will take (so they can tell customers how long the appointment will be).


2.
[1 mark]
Add a global class-level string variable called
filePath
and initialise it to “dentist.txt”. Where will this file end up being stored?


3.
[2 marks]
Override the

ToString()

method that your class inherited from Object:


a. This method must return a string containing the object’s properties, delineated so the string can be parsed back into an XXSalesService object later.


4.
[3 marks]
Add a class (static) method called

XXParse

that accepts a string parameter and returns an object of the XXSalesService class. The string is a record from the dentist file containing the dentist’s properties.


5. Add the following
class
“Get” methods, to retrieve XXSalesService object(s) from the file:


b.
[2 marks]
XXGetStocks

has no parameters and returns a List containing all Stocks on file.


c.
[2 marks]
XXGetByStockName

accepts a string parameter and returns the XXSalesService object with a Name equal to the given string … or null if not found.


d.
[2 marks]
XXGetByDescription

accepts a string parameter and returns a List of all Stocks containing the given string phrase in either their Name or Description.





e. Add an instance method called

XXEdit

that performs the following validations on the current object (ie: the method has no parameters):


f.
[1 mark]

SaleServiceName
are required … please don’t edit their contents.



i.
[2 marks]
If adding a new record, ensure the
SaleServiceName
is unique (not already on file).



ii.
[3 marks]
If updating an existing record, ensure there is a record on file with the given
SaleServiceName. Do not prevent users from updating an existing record.


g.
[1 mark]

Price
cannot be less than zero


h.
[1 mark]

Minutes
cannot be less than zero


i.
[2 marks]
If it is a procedure (isProcedure),
Minutes
must be greater then zero. Otherwise,
Minutes
must be zero.


j.
[1 mark]
each time a new operation is being done - Initialize an empty string to collect all the error messages. Each error message should include the property name in the message and end with a new-line character, so errors display one line per error.


k.
[2 marks]
Trim all strings, converting nulls into an empty string.


l.
[2 marks]
If there are any error or exception messages, throw them all at once in an exception.




6.
[3 marks]
Add an instance method called

XXAdd

that accepts an XXSalesService object and adds it to file, if it passes all edits.


7.
[4 marks]
Add an instance method called

XXUpdate

that accepts an XXSalesService object and replaces the current record of the same name, if the updated record passes the edits.


8.
[3 marks]
Add a class method called

XXDelete

that accepts a string and removes the record with the given Name from the file.


XXSalesServiceMaintenance


1. Create a form see GUI example at end of this document - to perform Create, Retrieve, Update and Delete (CRUD) maintenance on the Stock table, through your XXSalesService class.


a. Don’t bother with browse/modify modes … you have enough work.


2. The

ListBox

on the left is used to navigate through the Stock records:


a.
[2 marks]
once the program is run It must be loaded with all Stock names on file … it both displays the StockName and returns it as the ListBox’s value.


b.
[2 marks]
The Stock names must be displayed in alphabetical order.


c.
[3 marks]
When the user selects a Stock, that Stock’s properties must be loaded to the input areas.


d.
[1 mark]
The list must be updated When the user successfully adds a new Stock or updates an existing Stock:



i.
[2 marks]
In this process the ListBox must be reloaded and resorted, and the modified/new record selected.


e. When the user deletes an existing record:



i.
[3 marks]
The ListBox must be reloaded and have the record after the one deleted selected (or the last record, if the user deleted the prior last record).


3.
[1 mark]
The

Clear Inputs


button must clear all input fields.



4.

[3 marks]
The

Save

button must create a new XXSalesService object – based on the data entered in the input fields on the form



a.

[4 marks]
It must pass and passes it to the object’s appropriate Add method
or Update method - if the record already exists.


b.
[2 marks]
You must check for numbers and Booleans before stuffing them into the object’s properties.


c.
[2 marks]
Error messages and Exceptions must be displayed in a red label or a rich text box, one line per message.


5.
[2 marks]
The

Cancel

button returns the input areas to their values before the user cleared or modified them. What remembers the original Stock name, whether it was an edit or add that was cancelled?


6.
[3 marks]
Proper error/exception handling must be used throughout the entire program,


a. [2 marks] use a throw exception to manage any user input that must be greater than or equal to 0.



7.

[3 marks]
The form must match the example below:

Aug 03, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here