Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
CMP-4008Y Programming 1
Reassessment CW 1 - Electronic Component Inventory
Learning outcomes
The aim of this assignment is for the student to gain experience in the design and implementa- fion of arelafively small program using an object oriented approach. This will further reinforce the student’s grasp of fundamental concepts such as classes, objects, instance variables and methods, but will also introduce the use of mulfiple classes, each of which defines a different type of object. During the assignment, the student will also begin to gain object-oriented de- sign skills by deciding how the state and behaviours of the objects should be implemented and how the objects should interact.
On successful complefion of this exercise, the student will have reinforced a basic under- standing of the concepts of classes and objects, will be familiar with the basic syntax of Java programming constructs used to implement classes, instance variables and methods and will be able to select the instance variables and methods required to represent the state and be- haviours of simple types of real-world objects. The student will have gained familiarity with some of the classes in the Java standard libraries used for file based I/O and collecfions. The student will also have an improved ability to use the ideas of cohesion and coupling to guide the design of programs comprised of more than a single class definifion.
Specification
Overview
Chartlins is a company that specialises in providing electronic components for hobbyists to build simple electronic circuits of their own design, or from a kit of parts. They have hired you to write a system to manage their inventory of components etc. The program must be written in the Java programming language and demonstrate the use of classes and object-oriented design to write modular, maintainable programs. The file inventory. txt, available via black-board, provides details of the company’s inventory of electronic components (resistors, ca- pacitors, diodes, transistors and integrated circuits). For each stock item, the file provides the component type, the stock code, the number of items in stock and the unit price in pence. The remainder of the record provides some addifional informafion:
• Resistors — the resistance in Ohms (see en.wikipedia.org/wiki/RKM_code).
• Capacitors — the capacitance in Farads, encoded in a manner similar to resistance.
• Diodes — no addifional informafion.
• Transistors — an indicafion whether theyare NPN, PNP or FET devices.
• Integrated Circuits (ICs) — a brief descripfion.
The program must read the data in this file into memory, stored in an appropriate set of objects, and print answers to the following queries on the console:
• Print a list of the inventory, sorted in decreasing order of the number of items in stock.
• What is the component with the smallest number of components in stock?
• How many PNP transistors does Chartlins have in stock?
• What is the total capacitance of all of the capacitors in stock?
• How many stock items have more than ten in stock?
The program should consist of three files, which define the basis of the marking scheme:
• StockItem. java, which should definea class that records the informafion about a stock item.
• Inventory. java which should definea class represenfing the inventory of the company, using some appropriate data structure or container. The class should have methods that assist in answering the same queries as before (the methods should be generic so they could potenfially be used to answer similar queries, rather than specifically those given in the specificafion).
• StockProgram. java This file contains the main part of the program that loads and pro- cesses the inventory data, and provides answers to the five queries.
Hints:
• Tackle the problem one class at a fime. I would start with StockItem; have it fully imple- mented and tested before moving on to Inventory. Only once you have implemented and tested classes represenfing each type of object, should you try to implement the StockProgram itself. Note this is an example of “top-down design, bottom-up imple- mentafion” discussed in the lectures.
• Make sure you have a good idea of what you have to do before you start wrifing code. This is especially true for aspects of the project that require some research, for instance gaining some understanding electronic components such as resistors and capacitors.
• For each class, it is a good idea to work out what methods the class should provide in order to provide the services required to implement the program, before starfing to code.
• It is important to test each class in isolafion (don’t write all the code for all three classes and expect them to work first fime). StockItem and Inventory could have a main method, used as a test harness.
• The implementafion of Inventory requires the use of arrays, or more advanced types of collecfion, which we will cover in later lectures, However StockItem can be imple- mented and tested based on the material already covered. Reading in the file should be left unfil last as it will be covered a什er arrays and ArrayLists.
• It simplifies the design if StockItem has a constructor that takes a String argument containing a line from the file.
• If you have done some programming before in a language other than Java, do not try to implement the program in the style used in adifferent language. Programming languages have different purposes and different programming styles. If you try and write in another style (parficularly that used in Python), the task will be more difficult, and will not meet the learning objecfives (and hence will attract lower marks).
• The science ficfion writer Robert A. Heinlein wrote “... when faced with a problem you do not understand, do any part of it you do understand, then look at it again.” , which some- fimes can be a good approach to programming. This approach really helps deal with the complexity of wrifinga non- trivial program. It is easy to get infimidated by the complex- ity of the whole program, so if we can find one small part of the program that we can implement, then we have made some pracfical progress and we have made the remain- der of the task less complex. Abstracfion is especially useful; if you can find a method of a class that you are confident you can implement, then once you have implemented it, you can use it elsewhere in the program without having to think about how it works
- you just need to know the name of the method, what arguments it expects and what informafion it returns.
All quesfions regarding the specificafions must be asked via the appropriate discussion board on BlackBoard. Note that inventory . txt may change before the due date for the as- signment, and the answers to the queries must be based on the final version of that file.
Relationship to formative assessment
This assignment builds on the skills gained from the laboratory exercises for cmp-4008Y that have already been completed, for which formafive feedback can be obtained from the teaching assistants during your scheduled laboratory session.
Deliverables
Your solufion must be submitted via blackboard. The submission must be a single . pdf file generated using PASS, using the PASS server at http://pass.cmp.uea.ac.uk/ . The PASS program formats your source code, and compiles and runs your program, appending any com- piler messages and the output of your program to the . pdf file. If there is a problem with the output of PASS, contact me ([email protected]). Do not leave it unfil the last moment to generate the . pdf file, there is a limit to the amount of help I am able to give if there is little fime left before the submission deadline.
PASS is the target environment for the assignment. If your program doesn’t operate cor- rectly using PASS, it doesn’t work, even if gives the correct answers on your own computer:
• The PASS program is notable 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 compafible with PASS. Design your program to operate correctly without any user input from the keyboard.
• Do not use absolute path names for files as the PASS server is unable to access files on your machine. If your program is required to load data from a file, or save data to a file, the file is expected to be in the current working directory. If the program is required to load data from a file called rhubarb . txt then the appropriate path name would be just "rhubarb. txt" rather than "C:some\long\chain\of\directories\rhubarb. txt" .
• If you develop your solufion on a computer other than the laboratory machines, make sure that you leave adequate fime to test it properly with PASS, in case of any unforeseen portability issues.
• If your program works correctly under InteliJ on the laboratory machines, but does not operate correctly using PASS, then it is likely that the data file you are using has become corrupted in someway. PASS downloads afresh version of the fileto test your submission, so this is the most likely explanafion
Resources
- https://stackoverflow.com/- An excellent site for finding informafion about specific issues relafing to various programming languages, including Java. It is important however not to become too reliant on sites such as StackOverflow, which are great for details, but don’tgive the “big picture”, so it is difficult to get a good understanding of program- ming in this way. Note that if you re-use or modify code found on-line, then you must provide a comment giving the URL and a brief explanafion of what modificafions have been made. Re-using code found on-line without proper attribufion would consfitute plagiarism.
- https://docs.oracle.com/javase/tutorial/ - A set of tutorials, provided by Ora- cle, who now develop the Java programming language.
- https://docs.oracle.com/en/java/javase/17/docs/api/index.html- Java Ap- plicafion Programming Interface (API) documents. Very useful for findingout what meth- odsa class from the Java standard libraries provide.
Marking Scheme
Marks will be awarded according to the proporfion of specificafionssuccessfully implemented, programming style (indentafion, good choice of idenfifiers, commenfing etc.), and appropri- ate use of programming constructs. It is not sufficient that the program generates the correct output, professional programmers are required to produce maintainable code that is easy to understand, easy to debug when (rather than if) bug reports are received and easy to extend. The code needs to be modular, where each module (e.g. class) has a well-defined interface to the rest of the program. The funcfion of modules should be made as generic as possible, so that it not only solves the problem specified today, but can easily be modified or extended to implement future requirements without undue cost. The code should also be reasonably effi- cient. Marks may also be awarded for correct use of more advanced programming constructs not covered in the lectures.
The marking scheme is as follows (out of 35 marks):
• StockItem. java - 10 marks.
• Inventory. java - 10 marks.
• StockProgram. java - 5 marks.
• The remaining 10 marks are awarded for the answers to the five inventory quesfions listed above (two marks each).
Plagiarism, collusion, and contract cheating
The University takes academic integrity very seriously. You must not commit plagiarism, col-lusion, or contract cheafing in your submitted work. Our Policy on Plagiarism, Collusion, and Contract Cheafing explains:
• what is meant by the terms ‘plagiarism’, ‘collusion’, and ‘contract cheafing’
• how to avoid plagiarism, collusion, and contract cheafing
• using a proof reader
• what will happen if we suspect that you have breached the policy.
It is essenfial that you read this policy and you undertake (or refresh your memory of) our school’straining on this. You can find the policy and related guidance here:
https://my.uea.ac.uk/departments/learning-and-teaching/students/academic- cycle/regulations-and-discipline/plagiarism-awareness
The policy allows us to make some rules specific to this assessment. Note that:
In this assessment, working with others is not permitted. All aspects of your sub- mission, including but not limited to: research, design, development and wrifing, must be your own work according to your own understanding of topics. Please pay careful attenfion to the definifions of contract cheafing, plagiarism and collusion in the policy and ask your module organiser if you are unsure about anything.