Uploaded by Man Rich

Test1 Store 1

advertisement
Programming 2 – Store Application.
StoreApp
Your company was asked to build a contact manager for a grocery store, the software
architects of your company have designed the system and your supervisor has assigned the
task of coding four classes.
Do not use the class diagram below, or even the UML object diagram, to directly develop your
code, as not all methods specified are necessarily required. Please read the specification/
description of each class, including all the members, before starting to implement the system.
It is recommended that you implement each class in the order that they are specified.
Warning:
You may not use ANY techniques that have not been covered in COMP123 thus far.
Test 1 – Store
Fall 2021
The StorePerson class
7 marks
The StorePerson class is abstract and is described in the diagram below.
StorePerson
abstract class
Fields
$# ID
Properties
+ «property, no setter» Cell
+ «property, no setter » Name
+ «property, no setter » Id
: int = 100_000
: string
: string
: string
Methods
+ «constructor» StorePerson(
name
: string,
cell
: string)
Description of class members
Fields:
There is a single static field that is decorated with the protected modifier.
ID – this int field represents the id of the next customer or employee to be created. This is
used in the constructor to generate sequential id for objects. It is initialized to 100_000 at
declaration.
Properties:
There are three properties. The getters are public, and the setters are absent.
Cell – this string property represents the cell (mobile) number of this store person.
Name – this string property represents the name of this store person.
Constructor:
StorePerson(string name, string cell) – This constructor takes two arguments
and does the following:
1. Assigns the arguments to the appropriate properties.
2. Increments the static field ID.
Methods:
There are no methods.
n.k.p
Programming II
Page 2 of 11
Test 1 – Store
Fall 2021
The Customer class
7 marks
The Customer class inherits from the StorePerson class and is described in the diagram below.
Customer
class
→ StorePerson
Fields
Properties
+ «property» Credit
: double
Methods
+ «constructor» Customer(
name
: string,
cell
: string,
credit : double = 500)
+ ToString()
: string
Description of class members
Fields:
There are no fields.
Properties:
There is a single property that has a public getter with the setter missing.
Credit – this double property represents the credit limit of this customer. The getter is
public and there is no setter.
Constructor:
There is a single constructor.
Customer(string name, string cell, double credit = 500) – This constructor
takes two string arguments and an optional double argument and does the following:
1. Calls the parent constructor with appropriate arguments.
2. Assigns the other argument to the appropriate property.
Methods:
There is one instance method that is public.
public override string ToString() – This method returns a string representing
this customer.
n.k.p
Programming II
Page 4 of 11
Test 1 – Store
Fall 2021
The Employee class
7 marks
The Employee class also inherits from the StorePerson class and is described in the diagram
below.
Employee
class
→ StorePerson
Fields
Properties
+ «property» Salary
: double
Methods
+ «constructor» Employee(
name
: string,
cell : string,
salary : double = 2500)
+ ToString()
: string
Description of class members
Fields:
There are no fields.
Properties:
There is a single property that has a public getter with the setter missing.
Salary – this double property represents the salary of this employee. The getter is public
and there is no setter.
Constructor:
There is a single constructor.
Employee(string name, string cell, double salary = 2500) – This
constructor takes two string arguments and an optional double argument and does the
following:
1. Calls the parent constructor with appropriate arguments.
2. Assigns the other argument to the appropriate property.
Methods:
There is one instance method that is public.
n.k.p
Programming II
Page 5 of 11
Test 1 – Store
Fall 2021
The Store class
17 marks
The Store class is described in the diagram below.
Store
static class
Fields
-$ people
Properties
Methods
+$ «constructor» Store()
+$ Show()
+$ Show(length int)
+$ Show(name: string)
+$ Show(amount: double)
+$ Save()
: List<StorePerson>
:
:
:
:
:
void
void
void
void
void
Description of class members
All the members of this class are static
Fields:
There is a single private field.
people – this List<StorePerson> field represents a collection of customers and employees
associated with this store.
Properties:
There are no properties.
Constructor:
There is a single static constructor.
Store() – As with all static constructors, you may not have any arguments. This constructor
initializes the field people to a collection of 10 customer and employee objects. See the Test
Harnass for further info. (Customers will have a Credit property while Employees will have
a Salary property)
Methods:
There are the following public static methods:
public static void Show() – This method will display all the objects in the people
collection.
public static void Show(string name)– This method will display all the objects in the
people collection whose names matches the argument.
n.k.p
Programming II
Page 7 of 11
Test 1 – Store
Fall 2021
Test Harness
In your main method, initialize your Store with at least 10 people, of differing types. There should
be at least three people with the name "Kassie" in your initialization.
Copy the following into your main method after the Store initialization, and run to verify your
application.
//Showing all the people
Console.WriteLine($"\n\nAll people");
Store.Show();
//Showing a person with matching name
string name = "Kassie";
Console.WriteLine($"\nPerson with name {name}:");
Store.Show(name);
n.k.p
Programming II
Page 9 of 11
Download