首页 > > 详细

COMP282 Coursework 2 – C#

Department of Computer Science
COMP282 – Advanced Object-Oriented C Languages
Coursework 2 – C#
Deadline: Thursday 12th May at 17:00
Last possible time to hand-in: Thursday 26th May at 17:00
Weighting: 50%
Feedback: General feedback will be released shortly after the last possible time you can hand-in (see 
above). Since your grade and personal feedback will be based on your last submission, we can’t 
really look at it much before the last time you can hand-in. Therefore, you will first get that 
sometime in early June.
Compress your Visual Studio project into a single zip file and submit it via CodeGrade – CodeGrade is 
only used to make grading easier, but it will be done by hand. In particular, you will not get feedback 
when submitting. Penalties for late work will be applied in accordance with the Code of Practice on 
Assessment. You can submit multiple times. If you submit more than once, we will only look at and 
mark the most recent, and late penalties will be based on your final submission.
Project Overview: 
You will create a small Windows GUI application to input details about countries and show and 
modify the data. The project consists of several tasks, which you should tackle in order (except for 
the hard tasks at the end where any subset can be done, and the order is not important). Each non￾hard task builds on the previous one. Do as much as you can and then submit your project.
Read through this entire document before you start coding, so you are aware of all the tasks and the 
overall structure of the program. In particular, if you are aiming for the hard tasks as well, do look at 
them before starting to code, since you will otherwise likely have to rewrite code if you did not keep 
them in mind. Your solution should demonstrate your knowledge of C# and GUI development with 
Visual Studio.
Important: Each non-hard task requires you to add extra code. The hard tasks will each impose 
stricter requirements on some aspect of your program, but after perhaps a refactoring, your 
program is meant to be able to answer each task you aim for at the end. Note, the non-hard tasks 
should each be simple to do based on what you have seen in the course, but each hard task will 
require you to go beyond that and will give you pointers on where to look. This is necessary to give 
people grades above the 70s according to the university’s marking descriptors.
Note: Much of the code will be generated for you by Visual Studio. We’ll mark the code you write. 
User Interface & User Experience Design
Your application should look something like the screenshots shown on the next page. It doesn’t have 
to be identical, but it should have equivalent controls and buttons. There should also be space for an 
error message below the form area unless you do task 8, which requires you to change it into a 
message box.
The solution is shown working and discussed in lecture 9. Please watch the stream of that to get a 
good idea of how your application should behave (if it ends up being unclear, a video will be made).
Part 1 (Worth 20%)
Task 1 – Country Class Definition (5%)
Create a Country class that stores a name and population size. The name should be stored as a 
string, and the population size as a long. Implement a constructor that takes appropriate parameters 
and stores them in the object. Also, implement the appropriate C# property getters and setters (incl. 
appropriate access modifiers). Finally, override the ToString() method for the class so that it outputs 
information about the content, e.g. name and population size.
Task 2 – Form Layout (15%)
Use the Visual Studio layout designer to create a form similar to the one shown above. At this stage,
the application should be runnable. Note the arrows on the sort buttons! You can e.g. use ASCII 
arrows, such as ↓. Also, set up the design so that it is nice to work with, incl. tab order and names of 
elements. When it’s run, the form window should be displayed without any build errors, although it
will not do anything apart from terminate correctly when the user closes the window.
Part 2 (Worth 30%)
Task 3 – Adding Countries (Internal and Visual) (10%)
Use a relevant C# container class to store Country objects. Implement the code that runs when the 
user clicks the Add button. Your code should retrieve the text entered into the Name and Population 
Size boxes, convert them into a Country object, and store that object in a collection. You should also 
update the GUI so the added country appears in the large list area. Use the format shown above on 
the previous page (or very similar).
Task 4 – Removing Countries (Internal and Visual) (10%)
Implement the code that runs when the user clicks the Remove button. Your code should find out 
which item in the list is currently selected (represented by the blue background) and remove it.
Important: Make sure you remove the item from both the internal list and the visible display. Be 
sure to check the index of the removed item to prevent runtime out-of-bounds errors.
Solution without the hard tasks Solution with the hard tasks
Task 5 – Updating Country Data (10%)
When the user clicks on an item in the visible list (or uses the keyboard to move up and down the 
list), the Name and Population Size text boxes should be updated to reflect the current selection.
Implement the code that runs when the user clicks the Update button. Your code should update the
current selection with whatever text is currently in the Name and Population Size boxes. You should 
update both the internal data collection and the visible list.
Part 3 (Worth 25%)
Task 6 – Sorting by Name and Population Size (10%)
Add the code that runs when the user clicks the Name Sort and Population Size Sort buttons. When 
the user clicks one of these, switch the direction of the arrow (↓ becomes ↑ and vice versa) and 
sort the data in descending order (according to which button was clicked) if the arrow was ↓ and 
otherwise in ascending order.
Task 7 – General UX Improvements & Robustness (15%)
The last non-hard task is to make sure the blue highlight (current selection) stays visible when the 
list changes. For example, when the currently selected item is removed, you need to decide what 
should become the new current selection, then set the blue highlight accordingly. For this task, add 
any necessary code to ensure the blue highlight remains visible when there is data in the list. The 
most annoying part is likely to ensure that you have the blue highlight after sorting and you may 
wish to implement an Equals method for countries to do this (alternately, you can sort the displayed 
list directly, but you will need to look into the interface IComparer for that).
You should also ensure there is consistency between the current selection and the values shown in 
the Name and Population Size boxes. 
Add validation code so that the application doesn’t crash when the user clicks Update or Remove 
with an empty list, and any other checks that you deem necessary for a robust implementation (in 
particular in Add, Remove, and Update). Display any errors in the label below the Sort buttons (or in 
a message box, see Task 8).
Part 4 (Worth 25%) – Hard tasks
Task 8 – Error message in a message box (5%)
Instead of writing error messages in a label below the Sort buttons, use a message box.
Hint: Investigate the MessageBox class.
Task 9 – Add with index (5%)
Modify Add so that if there is a country selected, Add inserts before that country (and otherwise, 
inserts at end). Hint: Investigate the Insert method.
Task 10 – Action on Enter (5%)
When pressing the Enter key on your keyboard while in the Name or Population Size boxes, the last 
button used amongst Add, Remove, and Update should be used, or Add if none has been used yet. 
You might also set Update as the button after having selected an index, but this is not required. 
Hint: Investigate what the AcceptButton property does on the form.
Task 11 – Two-column layout of the displayed list (10%)
The goal of this task is to change the format of the displayed list so that you have multiple columns 
(2, i.e. one for Name and one for Population Size). The task is rather annoying because it is likely best 
to use the class/form element ListView and the setup for that requires quite a few changes to do 
what you need for this task. After having done so, replace the sort buttons with the headers for the 
columns as shown in the demonstration. Make sure that only vertical scrollbars are used (and only if 
needed)
How to Submit
Locate your Visual Studio project folder and compress it into a single .zip archive. If you use any 
other format we won’t be able to extract and mark your work. 
If you want to draw our attention to anything, make a comment in the code itself. We will not read 
or mark any other documents.
Submit your archive via CodeGrade. 
Marking Descriptors
We draw your attention to the standard Department Grade Descriptors, which are listed in the 
Student Handbook.
联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!