CMP-4008Y Programming 1
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 blackboard1
, provides details of the company’s inventory of electronic components
(resistors, capacitors, 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 additional information:
• 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 additional information.
• Transistors — an indication whether they are NPN, PNP or FET devices.
• Integrated Circuits (ICs) — a brief description.
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 define a class that records the information about a stock item.
• Inventory.java which should define a class representing 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 potentially be used to answer similar queries, rather than specifically those given
in the specification).
• StockProgram.java This file contains the main part of the program that loads and
processes the inventory data, and provides answers to the five queries.
Hints:
• Tackle the problem one class at a me. I would start with StockItem;
have it fully implemented and tested before moving on to Inventory. Only once you have implemented
and tested classes representing each type of object, should you try to implement the
StockProgram itself. Note this is an example of “top-down design, bottom-up implementation”
discussed in the lectures.
• Make sure you have a good idea of what you have to do before you start writng 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 starting to code.
• It is important to test each class in isolation (don’t write all the code for all three classes
and expect them to work first time). StockItem and Inventory could have a main
method, used as a test harness.
• The implementation of Inventory requires the use of arrays, or more advanced types
of collection, which we will cover in later lectures, However StockItem can be implemented
and tested based on the material already covered. Reading in the file should be
last as it will be covered aer 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 a different language. Programming languages
have different purposes and different programming styles. If you try and write in another
style (particularly that used in Python), the task will be more difficult, and will not meet
the learning objectives (and hence will attract lower marks).
• The science fiction 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-
times can be a good approach to programming. This approach really helps deal with the
complexity of writing a non- trivial program. It is easy to get intimidated by the complexity
of the whole program, so if we can find one small part of the program that we can
implement, then we have made some practical progress and we have made the remainder
of the task less complex. Abstraction 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
information it returns.
All questions regarding the specifications must be asked via the appropriate discussion
board on BlackBoard. Note that inventory.txt may change before the due date for the assignment,
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 formative feedback can be obtained from the teaching
assistants during your scheduled laboratory session.
咨询 Alpha 小助手,获取更多课业帮助