Skip to main content
留学咨询

辅导案例-CMP-4008Y-Assignment 2

By May 15, 2020No Comments

School of Comput_ing Sciences Module: CMP-4008Y Programming 1Assignment: Coursework Assignment 2 Set by: Jason Lines ([email protected])Checked by: Gavin Cawley ([email protected])Date set: Friday 7th February 2020Value: 30% Date due: Friday 20th March 2020 3pm (Week 10)Returned by: Thurs 23rd April 2020Submission: PDF prepared with PASS submit_ted electronically on e:vision Learning outcomes The aim of this assignment is to facilitate the development of Java and object orientated pro-gramming skills by designing and implement_ing a program to simulate the operat_ion of a themepark. In addit_ion to using the fundamental concepts that were developed throughout the firstassignment (such as classes, objects, instance variables andmethods), this assignment will alsodevelop skills in UML class diagrams, file I/O, inheritance, except_ions and basic enumerat_ivetypes in Java.Further general learning outcomes include: describing abstract systems using technical dia-grams; following specificat_ionswhen developing sof_tware; document_ing code to enhance read-ability and reuse; increased experience of programming in Java; increased awareness of theimportance of algorithm complexity; and using inheritance to model relat_ionships betweenclasses. Specificat_ion Overview FunCorp, a new division of GreedyJay Inc., have approached you to create a system for manag-ing their new pay-as-you-go theme parks. Figure 1: An art_ist_ic impression of one of FunCorp‘s new theme park. To model this system you will need to create a number of classes. A theme park class will storeinformat_ion for a whole park, including its name, a collect_ion of its at_tract_ions and a collect_ionof its customers. 1 Each individual at_tract_ion will have informat_ion associated with it, including its name and costto ride the at_tract_ion. There will also be different discounts available for certain types of at_trac-t_ions during specific periods of a park‘s opening hours; this will be controlled in your applicat_ionby using an abstract at_tract_ion base class, and then using inheritance to create subclasses eachtype of at_tract_ion (transport, gentle and roller coaster). You will also need to create a class to store informat_ion about customers, including basic infor-mat_ion such as their name, age, and account balance. Further, this class will require funct_ion-ality to increase a customer’s account balance when they add funds, and decrease the balancewhen they ride at_tract_ions (subject to any addit_ional customer discounts that they may have). FunCorp would then like you to test your system using simulated data for a single park. Youwill therefore need to write a main method class with stat_ic methods to read in files to popu-late informat_ion about the park and simulate the use of the theme park (such as new customersjoining, account balances being updated and customers using at_tract_ions). A full descript_ionof the classes that you are required to create is given in theDescript_ion sect_ionof this document with specific implementat_ion requirements that you must follow. A summaryof the marks are also given in theMarking Scheme sect_ion. Informally, your tasks are to: 1. Describe this abstract system using a UML Class Diagram. 2. Implement each of the specified classes in Java 3. Create a main method class to read data from files to populate your system and simulateuse of the theme park. Please note that you are expected to provide toStringmethods for all object classes, appro-priate comments to aid someone reading your code, and evidence of test_ing in all classes (i.e.simple test harnesses in your object classes). (hint: please read the full assignment rather than diving in straight away – it will make yourlife a lot easier if you implement it in a logical order). Descript_ion 1. UML Class Diagram (15%) You are required to create a UML class diagram to describe the classes that are given in theremainder of the Descript_ion sect_ion for the proposed system. You should include all classes,and relat_ionships between them, but you are not required to include accessor and mutatormethods in your diagram. Do not use specialised sof_tware to create your UML class diagrams. It is fine to use Pow-erPoint, Word or other simple drawing tools, but do not use any specialised tools that help toautomate the drawing of your diagram. Marks will also be deducted due to poor presentat_ion(e.g. make sure the text is not t_iny once it is printed out). Your UML class diagram should fol-low the convent_ions given in the lectures. To avoid issues when including your diagram in PASS,make sure to save your UML class diagram as a .pdf and do not include spaces in your file name(you can use print to pdf or export to pdf in PowerPoint/Word to help get it into .pdf). 2 (hint: read the full specificat_ion first, but then come back and create a UML class diagram forthe system before writ_ing code. It will help you understand all of the funct_ionality and relat_ion-ships between the classes, and give you something to refer to while working on the code). 2. Object Classes The classes that you must implement are as follows. Please note that all object classes shouldhave amainmethod to demonstrate test_ing and an appropriate implementat_ions of toString. 2.1 Attraction (10%) At_tract_ions are split into three different categories: transport at_tract_ions (e.g. chair lif_t, monorail), gentle at_tract_ions (e.g. Ferris wheel, mini golf) and roller coasters (e.g. the corkscrew).You will model this through using an abstract base class for at_tract_ions and specific subclassesfor the three types of at_tract_ion. Each at_tract_ion has its own name and base price for using the at_tract_ion. For simplicity, priceswill be stored in pence and represented as integer numbers (e.g£1.00 = 100). Addit_ionally, specific discounts are applied to each category of at_tract_ion when used duringoff-peak t_imes (these should be rounded down to the nearest penny, where necessary). Theseoff-peak discounts are as follows: • transport at_tract_ions cost 50% of their base price at off-peak t_imes. • gentle at_tract_ions cost 80% of their base price during off-peak t_imes. • roller coasters do not have any discount during off-peak t_imes. You are required to write an abstract class called Attraction. This class should include fieldsto store informat_ion about the name and base price for using a ride. You should also includeaccessor and muators for both fields and a suitable toString method. Further, your classshould include an abstract method called getOffPeakPrice that takes no arguments and hasa return type of int. 2.2 TransportAttraction, GentleAttraction and RollerCoaster (15%) You are required to extend Attraction into these three sub-classes. Each should include anappropriate implementat_ion of getOffPeakPrice and the following addit_ional funct_ionality: • TransportAttraction should have an addit_ional field to record the distance that thejourney will cover (rounded up to the nearest meter). • GentleAttraction should have an addit_ional field to store the capacity of an at_tract_ion(e.g. 4 people). • RollerCoaster should have two addit_ional fields: one for the minimum age (in years)to use the roller coaster and another for the top speed of the roller coaster (in mph). Forexample, the top speed of the roller coaster called The Corkscrew is 62.4mph. Include accessor andmutator methods for the addit_ional fields and ensure that these fields arerepresented in calls to toString. 3 2.3. Customer (20%) The Customer class should store informat_ion about a customer‘s account. This includes basicinformat_ion such as their account number, their name and their age (in years), plus two ad-dit_ional fields: account balance and personal discount. The account balance is the amount ofmoney that is in their account, which should be a posit_ive number that is reduced by the ap-propriate amount when using an at_tract_ion. Personal discount is an addit_ional discount that acustomer may have. A personal discount should be applied af_ter any off-peak discount, andpersonal discounts can be one of the followin
g values: none, student or family. Students re-ceive an addit_ional 10% off and family members of park employees receive 15% off. Your class should include accessors and mutators for all fields except account balance; thisshould have an accessor but no mutator. Instead of a mutator, there should be a two meth-ods: addFunds(int amount) and useAttraction(int attractionPrice). The addFundsmethod will top up a customer‘s balance by the specified amount, while useAttraction willsimulate using an at_tract_ion. It should take in the base price/off-peak price of the at_tract_ionthat a customer wishes to ride as the attractionPrice argument. The method should calcu-late the final price by applying any personal discount, and at_tempt to reduce the account bal-ance by this amount. If the customer has a sufficient balance, deduct the appropriate amountand return the price that was paid (i.e. including any personal discount). If they do not havea sufficient balance, throw an InsufficientBalanceException except_ion (you will needto create this class as a sub-class of Exception). Further, overload useAttraction to cre-ate a second version of the method that takes in two arguments: the at_tract_ion price andthe age limit of the ride. This version of the method should addit_ionally be able to raise an AgeRestrictionException if an age limit is violated. The version of the method that you usein Simulation.java should then depend on whether a ride has an age limit or not. Finally, this class should have a stat_icmethod called getAvailableDiscountInfo that returnsa String including informat_ion about the discount types that are available and howmuch eachis worth. 2.4. ThemePark (20%) You will also need to create a class to model a theme park. This class should have fields for thepark’s name, a collect_ion of the at_tract_ions at this park, and a collect_ion of the customer ac-counts that are registered at this park. It should have a single default constructor and methodsto add individual customers and rides. You should also provide methods for: • getCustomer(String accountNumber), • removeCustomer(String accountNumber), • getRide(String rideName) and • removeRide(String rideName). These methods should each throw either a CustomerNotFoundException or RideNotFoundException (you will need to make these). You will also need to provide get/setmethods for the park‘s name. Addit_ionally, you should have the following methods: 4 • calculateTotalTransportDistance() which should return the sum of the distancesof all transport at_tract_ions in this park, • calculateAverageGentleCapacity()which should return the average capacity of allgentle at_tract_ions in this park as a decimal number, and • calculateMedianCoasterSpeed() which should return the median speed of all rollercoasters in this park. It is up to you to decide how you wish to store collect_ions of at_tract_ions and customers. Thesimplest solut_ion is to use arrays/ArrayList, but you can use any data structure that extendsthe Java Collection class (see the Java API 1 for more informat_ion on opt_ions). A small num-ber of addit_ional marks will be awarded for using a more appropriate data structures thanarray-based collect_ions, but only if you also just_ify your choice in a small comment when youdeclare the fields in this class (i.e. I want to know why you think your solut_ion is bet_ter than anarray/ArrayList). 3. Main method class: Simulation (20%) Your main method class will simulate the use of a theme park. You are provided with threefiles: • customers.txt. This file contains informat_ion about customer accounts that should becreated for your simulat_ion. Each line includes informat_ion for an individual customer. • attractions.txt. This file contains informat_ion about the at_tract_ions that should becreated for your simulat_ion. Again, each line includes informat_ion for an individual at-tract_ion. • transactions.txt. This file includes a chronological list of transact_ion that you shouldsimulate using the appropriate methods that you have implemented. You should design the following two methods in your Simulation class: createThemeParkand simulate (you may also add any sensible helper methods in this class if you wish). The createThemePark method should return a ThemePark that is populated with customersand at_tract_ions from the specified files (its up to you to come up with a name for your parkthough!). It is fine to either take in the file names as arguments for this method, or simplyhard-code the file names for this assignment, but make sure that your files are in the rootdirectory of your project, the contents are unchanged, and do not change the names of thefiles. Once you have returned a theme park, call and print the results of the three methodsyou implemented in ThemePark to print the total transport distance, average gentle at_tract_ioncapacity and median roller coaster speed. Thesimulationmethod should run through each line of thetransactions.txtfile. It shouldtake a ThemePark object that has been created in your createThemeParkmethod as an inputand the method should then simulate the day-to-day use of your theme park; each line is anew act_ion that should be processed and includes the relevant informat_ion that you need forthat act_ion. These events could be adding new customers to the park (NEW CUSTOMER), cus-tomers using an at_tract_ion (USE ATTRACTION), and customers adding funds to their account(ADD FUNDS). Your method should handle all act_ions in the file and print out an informat_ive 1https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html 5 summary line to the console for each transact_ion that is performed to describe what wasprocessed. This should also include elegantly handling any except_ional events that happenthroughout the simulat_ion, also print_ing amessage to the console for those. Finally, you shouldkeep track of the money that the theme park makes throughout the course of your simulat_ion.The last line of your simulat_ion‘s output should state the total amount of money that the parkmade from customers riding their at_tract_ions. You should then include a main method in your Simulation class that calls these methodswithout prompt_ing for any user input (i.e. it should call createThemePark and pass the re-turned ThemePark into the simulationmethod without requiring any keyboard input to runwhen PASS calls your main method). Relat_ionship to format_ive work Please see the following lectures and labs for background on each of the specified tasks: • Gavin’s content from Semester 1. In part_icular, the fundamentals from the first assign-ment are relevant here. Lecture 5 introduces how to use objects, lecture 11 introduceswrit_ing classes, lecture 14 includes using collect_ions to store objects, and lecture 16 in-troduces inheritance. • Classes and objects: the use case example that I went through in week 2 of semester 2demonstrates the structure of a typical class. The lab reinforced this. • UML class diagrams: these were introduced in semester 2 week 3, and further explainedin week 4 with relevance and examples including inheritance. • File I/O: Gavin introduced this in semester 1, and I have shown an alternat_ive method ofdoing this in week 3 of semester 2 (with example code in the lecture and exercises in theassociated lab). • Inheritance: this was covered in more detail in week 4 of semester 2. • Except_ions: this will be covered in week 5 of semester 2, 5 weeks before the deadline. Ihave intent_ionally released the coursework a week earlier than planned, before coveringExcept_ions, to give you extra t_ime (since there is no teaching in week 6 due to Do Some-thing Different week). We will cover this well in advance of the deadline however andthe exercises in the week 5 labs will reinforce the use of Except_ions in Java. Deliverables Your solut_ion must be format_ted using PASS, which is available on all laboratory machines. Youmust use PASS to produce a .pdf file containing your UML class diagram, the source code of theprogram, the compiler messages (if any) and the output of the program. This is what will bemarked an
d the .pdf must be submit_ted on e:vision. IMPORTANT: your solut_ion will ONLY bemarked if it has been submit_ted on e:vision. PASS does not submit your work for you and it isyour responsibility to upload your PASS-format_ted .pdf to e:vision before the deadline. We strongly recommend that you also upload your .pdf file to BlackBoard before the deadline.Please note that the Blackboard version will not be marked directly and the official submis-sion must be made on e:vision – it will be treated as a non-submission if you do not submityour work on e:vision. Further, if your Blackboard submission does not match your e:visionsubmission then we will ignore the Blackboard version. The reason we suggest that you also 6 submit your work on Blackboard is that there are somet_imes issues that are not easily resolvedusing only the printed code list_ing, and the markers may wish to compile and run the programfor themselves. Finally, please be advised that the Hub do not accept individual issues with using UEA com-put_ing facilit_ies (including PASS) as a suitable reason for grant_ing extenuat_ing circumstances ifa deadline is missed. Please make sure that you leave sufficient t_ime to run your code throughPASS before the deadline and do not leave it unt_il the last minute. To try to avoid last-minuteissues I have intent_ionally made the deadline for the assignment coincide with labs on thismodule. TAs will be there to help, but do not rely on this as they are likely to be in very highdemand on the deadline day. Plagiarism and collusion: Stackoverflow and other similar forums (such as the module dis-cussion board) are valuable resources for learning and complet_ing format_ive work. However,for assessed work such as this assignment, youmay not post quest_ions relat_ing to courseworksolut_ions in such forums. Using code from other sources/writ_ten by others without acknowl-edgement is plagiarism, which is not allowed (General Regulat_ion 18). Resources • Previous exercises: If you get stuck when complet_ing the coursework please revisit thelab exercises that are listed in the Relat_ionship to format_ivework sect_ion during your allo-cated weekly lab sessions. The teaching assistants in the labs will not be able to help youwith your coursework directly, but they will be more than happy to help you understandhow to answer the (very) related exercises in the lab sheets. Youwill then be able to applythis knowledge and understanding to the new problems in this coursework assignment. • Discussion board: if you have clarificat_ion quest_ions about what is required then pleaseask these quest_ions on the Blackboard discussion board. This will enable other studentsto also benefit from the quest_ion/answer. Please check that your quest_ion has not beenasked previously before start_ing a new thread. Please ask quest_ions on the discussionboard, rather than by email, so other students can also benefit from the answer. • Course text: Java Sof_tware Solut_ions by Lewis and Lof_tus. Any version of this textbook ishelpful for Programming 1 and will have specific chapters on topics such as inheritanceand Except_ions. You can buy your own copy, but I‘d suggest doing a simple online searchas many edit_ions of the text are available online for free. The library also has a few copiesof the latest version of this textbook too. Marking Scheme Itemised marks are provided throughout the assignment descript_ion. To summarise: 1. UML Class Diagram (15 marks) 2. Object Classes 2.1. At_tract_ion (10 marks) 2.2. At_tract_ion sub-classes (15 marks) 2.3. Customer (20 marks) 2.4. Theme Park (20 marks) 7 3. Simulat_ion (20 marks) Total: 100 Marks 8

admin

Author admin

More posts by admin