CMP-4008Y Programming 1 2 2024Java

Java Python CMP-4008Y Programming 1

Reassessment Coursework Assignment 2

Learning outcomes

The aim of this assignment is to facilitate the development of Java and object orientated pro- gramming skills by designing and implementing a program to simulate the operation of a fic-  tional arcade company.  In addition to using the fundamental concepts that were developed  throughoutthefirstassignment(suchas classes, objects, instancevariablesandinstancemeth- ods), this assignment will also develop skills in UML class diagrams, file I/O, inheritance, ex-ceptions and basic enumerative types in Java. Further general learning outcomes include: de-  scribing abstract systems using technical diagrams; following specifications when developing  software; documenting code to enhance readability and reuse; increased experience of pro-  gramming in Java; increased awareness of the importance of algorithm complexity; and using  inheritance to model relationships between classes.

Specification

ArcadeCorp, a new division of GreedyEnterprises Inc. has approached you to create a prototype system for simulating the use of their newly proposed contactless arcades. Driven by changes in many industries due to the recent pandemic, ArcadeCorp wants to open a cashless arcade on a floating island in the middle of the UEA Broad (pending planning permission).

Your task is to model ArcadeCorp’s new system using an object orientated approach in the Java programming language. You will need to model key objects in the system by creating classes to represent objects such as cabinet games (e.g.  pinball, joystick games, etc.), active games (e.g.  pool, air hockey, etc.), virtual reality games (e.g.  using VR headsets, full-body tracking suits, etc.), customers, and arcades, in addition to a number of other classes to support the functionality of the system. A full description of the required implementation is given in the Description section, but in summary, you will:

1.  create a UML class diagram to give an overview of the system;

2.  implement the required classes and functionality in Java using an object orientated ap- proach, including sucient documentation and evidence of testing;

3.  simulate the use of the system through loading and processing a number of provided text files

Figure 1: An artist’s impression of ArcadeCorp’s proposed floating arcade in the UEA Broad.

Overview

To create a system that models customer interactions and transactions for arcades you will firstly need to be able to store information about arcade games. This will start with an abstract base class that stores basic information about generic arcade games, such as an ID number for the game, the game’s name, and the basic price to play the game (in pence). Subsequently, you will need to specialise this class to represent cabinet games, active games and virtual reality games.

All customers in the system will have a unique customer ID, a name, a balance and an age. Functionality will also be required to both top-up and charge accounts when appropriate trans- actions are carried out. Anyone from the public can sign up for a standard customer account, but since ArcadeCorp will be operating on UEA campus, they have agreed to special treatment of both CMP staff members and any UEA student. As a thankyou for forcing their students to prototype this system, ArcadeCorp will give all CMP staff a flat 10% discount when using any arcade game. Students, regardless of school of study, will get a flat discount of 5% off all arcade games, but will also be able to have a negative balance of up to ε5, similar to an overdraft. Further, the arcade will operate peak andoff-peak hours where specific discounts are applica- ble for different types of game (off-peak discounts are applied BEFORE customer discounts and specific details of the individual off-peak discounts for different game types are given in the Description section).

Once arcade games and customers can be modelled, each arcade should maintain its own collection of games and and its own collection of customers.  It will need functionality to pro- cess transactions when passed a customer ID and a game ID, charging a customer the correct amount to play a game if if the customer has asufficient balance (or rejecting the sale if they do not). An age limit may also apply for certain types of arcade game and this should be checked too. An arcade will also need to keep track of the total value of all sales (this is the most impor- tantthingtoGreedyEnterprisesInc., ofcourse)anditwillalsorequiresomespecialised methods that are of interest to corporate, such as reporting the median price of all games within an ar- cade.

Finally, this will all be tied together by populating an arcade with customers and games by reading in a number of text files that have been provided. You will also be given a list of trans- actions in another fileto simulate the use of an arcade.

Please note that you are expected to provide toString methods for all object classes, ap- propriate comments to aid someone reading your code, and evidence of testing in all classes (i.e. simple test harnesses in all of your non-abstract object classes).

(hint:  please read the full assignment rather than diving in straight away - it will make your life a lot easier if you implement it in a logical order and plan ahead).

Description

1. UML Class Diagram (15%)

Your first task is to fully read this assignment specification and then create a UML class diagram for the proposed system. You should include all classes, and relationships between them, but you are not required to include accessor and mutator methods in this diagram, and you also should not include your main method class (Simulation).  Marks will be awarded for the ac- curacy and correctness of your diagram, and presentation will also betaken into account (i.e. make sure that it is clear and easily readable, and make sure it follows conventionstaught on this module for UML class diagrams and not conventions taken from anywhere else).

I recommend that you use diagrams.net as shown in the live lecture that accompanied UML class diagrams, but you are free to use any other simple tools (such as MS PowerPoint or Word) to draw your diagram if you wish.

To avoid issues when including your diagram in PASS, please make sure to save your UML class diagram as a .pdf and do not include spaces in your file name (you can use exportpdf in diagrams.net/PowerPoint/Word to do this, or ask for help from the lab assistants if you are struggling to format your work correctly - they cannot answer the coursework for you but they are free to help you with technical issues).

(hint: before starting, read the full coursework specification first and then come back to create your class diagram before writing code. It will help you understand all of the functionality and relationships between the classes, and give you something to refer to while working on the code - that is the whole point of class diagrams, after all).

2. Object Classes

This section describes the classes that you must implement. Please note that all non-abstract object classes should have a main method to demonstrate simple usage/testing and anappro- priate implementation of toString. You do not need to include a full javadoc, but you should include a short comment at the start of each class to explain its purpose and use appropriate comments throughout to explain any complex operations or calculations.  If it is not immedi- ately obvious what a piece of code is doing then this is a good candidate for a comment that would aida reader.

2.1 ArcadeGame (10%)

Arcade games are initially split into two types of game: cabinet games (e.g. pinball, pac-man, lightgun games, etc.) and active games (e.g. things that require active movement, such as pool, darts, air hockey, etc.). There is also a third type of game, virtual reality games, that further ex- tend the active games class (more on that in Section 2.3). To start with however, you will need to begin by creating an abstract base class for ArcadeGame that will form the basis for the cab- inet game and active game subclasses.

All arcade games have a name, serial number and price to play games.

•  Game IDs should uniquely identify a specific game.  IDs are 10 characters long and may contain a mixture of numbers and letters.

•  Price per play is stored as a whole number in pence (e.g. if a game costs £2 to play, this would be stored as 200).

You are required to write an abstract class called ArcadeGame. This class should include fields for the ID, name and price per game of an arcade game. Your class should have a single con- structor that takes values for each of those three fields and it should check that the provided ID is valid. If it is not, it should throw an InvalidGameIDException (you will need to implement your own Exception for this).

Further, your ArcadeGame class should have accessor methods for all fields and an abstract method called calculatePrice(boolean peak) that returns an int and takes a boolean as input (true for peak, false for off-peak). The purpose of this method is that subclasses can over- ride it to return the correct price depending on whether it is used during peak/off-peak hours (more on that in Section 2.2).

2.2 CabinetGame and ActiveGame (10%)

You are required to extend ArcadeGame into two sub-classes:

•  CabinetGame should have an extra field to determine whether or not the game can pay out a reward (for example, this would be true if a game can pay out tickets to a winner that they can trade for a prize).  The class should have a single constructor that takes values for all fields and the constructor should throw an InvalidGameIDException if the ID does not contain exactly 10 alphanumeric characters or if the ID does not start with the character ‘C’ .

Figure 2: Real world examples of cabinet games. (image source)

•  ActiveGame should include an additional field to determine the minimum age require- ment for playing the game. The age limit should be stored as a whole number in years (e.g. beer pong would have an age limit of 18 in the UK). Similarly to CabinetGame, there should be asingle constructor that accepts an argument for each field and the construc- tor should throw an InvalidGameIDException if the ID does not contain exactly 10 alphanumeric characters or if the ID does not start with the character ‘A’.

Figure 3: Real world examples of active games (e.g Foosball, air hockey, pool). (image source)

Both CabinetGame and ActiveGame classes should have accessor methods for the new fields and each should have an appropriate implementation of calculatePrice(boolean  peak) that incorporates the following rules:

•  During peak hours no game is discounted;

•  Cabinetgamesthatdonotgiveoutrewardsarediscountedby50%duringoff-peak hours;

•  Cabinet games that do give out rewards are discounted by 20% during off-peak hours;

•  All active games are discounted by 20% during off-peak hours, regardless of age limit.

The calculatePrice(boolean peak) in each subclass should follow the rules above and ei- ther return the full price to play a game during peak hours (i.e. peak==true) or the appropri- ately discounted price otherwise. These classes should also have a suitable toString imple- mentation, helpful comments, accessors for all fields and evidence of testing. Please note that if you need to round prices after applying a discount then you should round down (e.g.  if a discounted price was 208.8, it should be rounded down to 208 and not up to 209).

2.3 VirtualRealityGame (5%)

A third type of game should be represented with a class called VirtualRealityGame.  This class is a special type of active game, and therefore should be a subclass of ActiveGame, and stores an additional field to state whether the virtual reality game requires either: a headset only, headset and controller, or a full-body tracking suit. .

A single constructor should be provided to accept arguments for all fields and the constructor should throw an InvalidGameIDException if the ID does not contain exactly 10 alphanu- meric characters or if the ID does not start with the characters ‘AV’ (it must start with an ‘A’ because it is a subclass of ActiveGame, but also followed by ‘V’ to demonstrated that it is a  VirtualRealityGame too).

Finally, calculatePrice(boolean peak) should again be overloaded so that there is nodis- count during peak times for any virtual reality game, but there is a 10% off-peak discount for those that use a headset only, and a 5% discount for those that require a headset and a con- troller (no off-peak discount for full-body tracking virtual reality games). Similarly to the sub- classes of ArcadeGame, this class should also have helpful comments, accessors for all fields, evidence of testing and a suitable implementation of toString.

Figure 4: A real world example of people playing a virtual reality game. (image source)

2.4. Customer (20%)

The Customer class should store information about a customer’s account.  This includes ba- sic information such as their account ID (a 6 digit alphanumeric identifier), their name, their age (a whole number in years), their level of personal discount (none, CMP staff, or student), and their account balance (as an integer in pence, e.g. 1001 for ε10.01). You should have two constructors, one for ID, name, age and discount type only that sets a default balance of zero, and another constructor that takes arguments for all fields including a specified balance (but the initial balance must be at least zero).  The account balance is the amount of money that is in a customers account and it will be reduced appropriately each time a customer uses an arcade game (see the chargeAccount method below). A customer’s balance should never be allowed to become negative - with the only exception that those with a student discount are also allowed to have a balance that goes as low as -500 (similar to an overdraft), and it would not be sensible to allow a negative starting balance for an account. Therefore, your construc- tors should throw an InvalidCustomerException if the account ID is incorrect or a negative balance is provided (you will need to provide this Exception class).

Your class should include accessors for all fields and two methods for manipulating the bal- ance of an account - one to add to the balance and one to simulate accounts being charged.

•  First, the addFunds(int  amount) method should allow a customer to top-up their ac-count balance (only add a positive amount to a balance and do not alter the balance if a negative amount is provided).

•  Second, there should bean instance method called chargeAccount that is used to sim-ulate a customer using an arcade game. This method should take two arguments, where one is an arcade game object and the other is a boolean to determine whether the ac- count is being charged during peak time.  If a customer has a sufficient balance and is old enough to use an arcade CMP-4008Y Programming 1 Assignment 2 2024Java game then the method should operate successfully and re- turn an int equal to the amount that the customer was charged (after any applicable discounts - remember, there are off-peak discounts for some games and CMP Staff re- ceiveanadditional10%discountwhilestudents receiveanadditional5%discount. Again, round down to the nearest integer if necessary when calculating prices). If the customer does not have sufficient funds to use the arcade game then their balance should be left unaltered and an InsufficientBalanceException should be thrown. Similarly, if the customer is not old enough to use the arcade game, their balance should be left unal- teredana AgeLimitException should be thrown (you will need to create both of these sub-classes of Exception).

Finally, ensure that your class also includes a suitable toString, helpful comments and evi- dence of testing.

(Note:  in practice, a customer’s age would not be stored as an int and would likely be rep- resented by their date of birth. To keep it simple in this assignment though we are fixing it to be an int and you can assume a customer’s age will not change during the execution of your program).

2.5. Arcade (25%)

You will also need to create a class to model an Arcade. This class should have fields for the arcade’s name, a field for the revenue of the arcade,a collection of the arcade games that it of- fers, and and a collection of the customers that are registered with the arcade. The class should haveasingleconstructorthattakesasingleargumentforthearcade’s name, andthereshould be methodsto add individual customersand arcadegames (e.g. addCustomer(Customer  c)). Further, it should have accessor methods for the arcade’s name and the revenue of the arcade, in addition to a suitable toString and evidence of testing.

You should also provide methods for:

•  getCustomer(String  customerID)  throws  InvalidCustomerException

•  getArcadeGame(String  gameId)  throws  InvalidGameIDException

Finally, youshouldalsohaveprocessTransaction(String  customerID,  String  gameID, boolean peak) method which will be used to process a transaction when given a customer ID, product ID, and boolean to represent whether the transaction was carried out during peak time. This method should tie together what you have already implemented - it should retrieve the correct game, the correct customer, and then try to reduce that customer’s balance by the appropriate amount. If successful, this amount should be added to the arcade’s revenue amount and you should return true to indicate that the transaction was a success. Otherwise, the method should throw an appropriate exception for why the transaction not be successfully processed.

Additionally, ArcadeCorp has asked that you provide the following methods:

•  findRichestCustomer() which should search the customers that are registered at a specific arcade to return customer with the highest balance;

•  getMedianGamePrice() which will consider the price per game for all arcade games within this arcade and return the median (if there is an even number of games then this method should average the price of the two middle games);

•  countArcadeGames() which should return an int[] of size 3, where the first element is the number of cabinet games in this arcade, the second is the number of active games in this arcade (not including virtual reality games), and the third is the number of virtual reality games in this arcade;

•  printCorporateJargon() which should be a static method in the Arcade class that printsa messageanddoesnotreturnanything. Itshouldsimplyprintthecorporate motto of “GreedyEnterprises Inc. and ArcadeCorp do not take responsibility for any accidents or fits of rage that occur on the premises”.

It is up to you to decide how you wish to store collections of products and customers.  The simplest solution is to use arrays/ArrayList, but you can use any data structure that is im- plemented in Java (such as those that extend the Java Collection class or similar).  A small number of additional marks will be awarded for using a more appropriate data structure than array-based collections, but only if the data structure used is indeed more appropriate and the choice of data structure is justified in the code with a short comment (i.e. why exactly is the datastructurethatyouare usinga betterchoicethananarray/ArrayList). To beclearthough, using an ArrayList or array will still lead to a good mark if implemented correctly.

3. Main method class: Simulation (15%)

Your main method class will simulate the creation and use of an arcade. You are provided with three files:

•  customers . txt. This file contains information about customer accounts that should be created for your simulation. Each line includes information for an individual customer.

•  arcadeGames . txt. This file contains information about the arcade games that should be created for your simulation.  Again, each line includes information for an individual arcade game.

•  transactions . txt. This file includes a chronological list of transaction that you should simulate using the appropriate methods that you have implemented.

Simulation will be the main method class of your project and, in addition to a main method (more on that later), you should implement two static methods:

•  initaliseArcade(String  arcadeName,  File  gamesFile,  File  customerFile) This method should return an Arcade with its name set to arcadeName. Two files should also be passed into the method: one with information about arcade games, and one with information about customers. This method should parse both of these files and add each customer and arcade game from the respective files to the Arcade (using the methods you implemented in the previous question) before it is returned.

•  simulateFun(Arcade  arcade,  File  transactionFile)

This method should parse and proceed through a file that contains a list of transactions, simulating the running of an arcade (such as customers playing games, adding funds, or signing up for a new account).  Each line should be processed individually and the ac- tion should be carried out on the Arcade that is also passed into the method (and catch any exceptions that occur). As you process each line of the transaction file you should printout an informative summary line for each successful action, and also a summary line for each action that could not be performed (such as a customer having an insuf- ficient balance, or rejecting a transaction when an unrecognised game ID or customer ID is found, etc.). The actions that you can expect to see are adding new customers to the arcade (NEW CUSTOMER), customers attempting to play games (PLAY),and customers adding funds to their account (ADD FUNDS). Once all transactions have been processed, youshouldcallyour methodsfrom Arcade tofindtherichestcustomer, the mediangame price and the number of each kind of arcade game.  Print the results of each of these methods (formatted however you wish so that the user can read the results) and also print the company’s corporate jargon using the static method that you implemented in Arcade.  Finally, also print out the total revenue for the arcade after all transactions and other methods have been finished.

Your main method should call initialiseArcade to create an Arcade, and it should then pass that Arcade into your simulateFun method.  It is up to you what you want to call the arcade, but make sure that you use the three files that have been provided (make sure that you place those files in the root directory of your project). Note: it is important that, when run, your code does not need any further information from the user (i.e. your main method should simplycall initialiseArcade withthe providedfiles, andthen passthe returned Arcade into the simulateFun method without requiring any keyboard input to run when PASS calls your main method).

Relationship to formative work

Please see the following lectures and labs for background on each of the specified tasks:

Gavins content from Semester 1.  In particular, the fundamentals from the first assign- ment are relevant here. Lecture 5 introduces how to use objects, lecture 11 introduces writing classes, lecture 14 includes using collections 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 2 demonstrates the structure of atypical class. The lab reinforced this.

UML class diagrams: these were introduced in semester 2 week 2, and further explained in week 3 with relevance and examples including inheritance.

File I/O: Gavin introduced this in semester 1, and I have shown an alternative method of doing this in the live lecture in week 2 of semester 2.

Inheritance: this was covered in more detail in week 3 of semester 2.

Exceptions: this was covered in week 4 of semester 2 and examples were given in the recorded and live lectures, as well as the lab exercises.

Data structures:  see the lecture in week 6 of semester 2 for a discussion of different types of data structure that you can use within your Arcade.

Deliverables

Your solution must be formatted using PASS to produce a .pdf containing your UML class dia- gram (included as a .pdf itself), the source code of your project, the compiler messages (if any) and the output of your program. Once formatted, you must submit your .pdf on Blackboard.

IMPORTANT: PASS is only used to format your submission and you must submit the output of running your work through PASS to Blackboard yourself. If you do not submit anything on Blackboard then you have not submitted anything.

PASS is available online at pass.cmp.uea.ac.uk (VPN connection required off-campus).  In-structions are given on Blackboard for using of PASS, and limited help will be available on the day of submission to help with any issues relating to your use of PASS, but please make sure you take the time to understand how to use PASS in advance of the deadline and practice for- matting a solution, if necessary (you should already know how to use PASS if you completed the first coursework assignment).

And remember, PASS is not able to provide input to your program via the keyboard, so pro- grams with a menu system, or which expect user input of some kind, are not compatible with PASS. Design your program to operate correctly without user input from the keyboard as spec-ified in the Simulation class.

Resources

Previous exercises: If you get stuck when completing the coursework please revisit the labexercisesthatare listedinthe Relationshiptoformativework sectionduringyourallo- cated weekly lab sessions. The teaching assistants in the labs will not be able to help you with your coursework directly, but they will be more than happy to help you understand howtoanswerthe(very)relatedexercisesinthe labsheets. Youwillthen beabletoapply this knowledge and understanding to the new problems in this coursework assignment.

Discussion board:  if you have clarification questions about what is required then you must ask these questions on the Blackboard discussion board to make sure that other students have the same information for fairness (there will be a specificdiscussion board topic with anonymous questions to enable this). Also, please check that your question has not been asked previously before starting a new thread.

Course text: Java Software Solutions by Lewis and Loftus. Any version of this textbook is helpful for Programming 1 and will have specific chapters on topics such as inheritance and Exceptions. You can buy your own copy, but I‘d suggest doing a simple online search as many editions of the text are available online for free. The library also has a few copies of the latest version of this textbook too.

Live lecture code: Remember that I have been writing code in the live lectures of the module each week and have been pushing the code to GitHub. I have intentionally cov- ered many of the topics that will appear in the coursework, so this is a good place to revise some of the topics that you will need to tackle in this assignment. A reminder that you can find the codebase here: https://github.com/jasonlines/CMP-4008Y-2023

Tips

•  Identifyappropriate placeswhereyoucoulduseenumerativetypes-these have not been specifically requested, but there are some obvious places where they would be more appropriate than using in-built Java types and it is expected that you can recognise this and use enums appropriately.

•  File reading should only happen in the main method class (Simulation). You should not have any file reading logic within the object classes themselves.

•  Itisfinetoimplementadditional helper methodsthatare notspecifiedinthecoursework description if you choose, but this is not required and you will not gain extra marks. Do not add additional constructors or functionality that would change the intended imple- mentation of the classes that have been described, however.

•  Make sure to follow the specification and do not make unnecessary changes to it. If specific class names and method names are requested then you must follow these re- quirements.

•  You do not need to load the data from files to test any of your object classes - you should start by using hard-coded values in your test harnesses to check that you implementa- tions are correct before even considering the data within the text files.

•  Generally, exceptions are thrown within object classes and caught in the main method of your project - if you catch them too early (e.g. as soon as they are thrown in an object class rather than in the main method that called it) then there is no chance to handle the exceptional behaviour appropriately. Similarly, aside from when developing/debugging your code, printing to the console should normally only happen in test harnesses and the main method class (with the exception of any methods that specifically require this, such as the static method in Arcade that explicitly asks you to print a message). For example, if you print a message every time you construct an object, this may lead to annoying output if you were to reuse your class in another project (which is common in real-world development) because there would be noway to turn off the output.

Plagiarism

Plagiarism is the copying or close paraphrasing of published or unpublished work, including the work of another student without the use of quotation marks and due acknowledgement. Plagiarism is regarded a serious offence by the University and all cases will be reported to the Board of Examiners.

Work that contains even small fragments of plagiarised material will be penalised. This is an individual assignment so you should not work with others, discuss solutions or share any code.

Marking Scheme

Marks will be awarded according to the proportion of specifications successfully implemented, programming style (indentation, good choice of identifiers, commenting, testing, etc.), and appropriate use of object oriented programming constructs.  Note that it is not sufficient to ignore the specification to simply produce the “correct” output - marks are not given for the output specifically and having the correct output only implies that the specification may have been implemented correctly. Professional programmers are required to produce maintainable code that is easy to understand, easy to debug when bug reports are received, and easy to extend. Itemised marksare providedthroughouttheassignmentdescription, buttosummarise the marks available for each part:

1.  UML Class Diagram (15 marks)

2.  Object Classes

2.1.  ArcadeGame (10 marks)

2.2.  CabinetGame, ActiveGame (10 marks)

2.3.  VirtualRealityGame (5 marks)

2.4.  Customer (20 marks) 2.5.  Arcade (25 marks)

2.6         

  • 13
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值