The aim of this assignment is to add a class to the project that you developed for the first part of the coursework to make a graphical user interface (GUI) for a system that stores details of gadgets in a shop. The class will contain a main method and will be tested using the command prompt. You will also need to write a report about your program. You are advised to study the learning aid on reflective practice, which is linked from the module WebLearn homepage, and the learning aids entitled “Using the Command Prompt” and “Examples of screenshots for Coursework 2” which are included in the learning and teaching materials. Your report should be no more than 1200 words in length (excluding the table of contents, class diagram, pseudocode and code listing).
Create a new class within the project called GadgetShop. When you are ready to submit your solution, upload your GadgetShop.java file, together with the Gadget.java, Mobile.java and MP3.java files from the first part of the coursework (not any other files from the project) to WebLearn together with your report in Microsoft Word and, when you are absolutely sure that you have uploaded the correct files, press the submit button. (You will not need to make any changes to the Gadget, Mobile or MP3 classes as long as they work correctly, but ask your tutor if you need help completing those classes to the specification of the first part of the coursework.)
Program (60 marks)
An example GUI is shown below:
Your GUI should contain the same components but you are free to use a different layout if you feel that it improves the aesthetics, ease of use etc. The GadgetShop class should store an array list (not an array) of type Gadget to hold the gadgets.
Text Field Input Methods
For each text field, write a method to read its contents and return the value. For the model, size and phone number, the value should simply be returned as a string but, for each of the other text fields, the input value should be converted into its correct numerical data type and then that value should be returned.
There should be text fields for entering:
(1) the model
(2) the price
(3) the weight
(4) the size
(5) the initial credit (when adding a mobile phone)
(6) the initial available memory (when adding an MP3 player)
(7) the phone number (when making a mobile phone call)
(8) the duration (when making a mobile phone call)
(9) the download size (when downloading music to the MP3 player)
(10) the display number, which is the same as the index of the gadget in the array list
The input method for the display number is different from the input methods for the other text fields. The method first initialises the display number to -1. If the input from the user via the GUI is valid, the display number will be changed to a value that corresponds to a gadget in the array list. The input from the display number text field must therefore be tested using a try/catch statement to ensure that the gadget number entered is an integer and, if it is, that it is in the correct range. If the value entered is an integer but is not in the correct range, a suitable error message is displayed using a message dialog box. If the display number entered is not an integer then an alternative error message is displayed using a message dialog box. The method will therefore either return –1 or a value that corresponds to a gadget in the array list, depending on whether or not there was an error in the input. Any method that gets the display number should check its value and only use it if its value is not equal to –1.
The GUI should have the following buttons:
1) Add Mobile
The model, price, weight, size and credit are input via the GUI. When this button is pressed, the methods to get the model, price, weight, size and credit are called, and these values are used to create a new object of type Mobile, which is added to the array list of gadgets.
2) Add MP3
The model, price, weight, size and memory are input via the GUI. When this button is pressed, the methods to get the model, price, weight, size and memory are called, and these values are used to create a new object of type MP3, which is added to the array list of gadgets.
When this button is pressed, the text is cleared from each of the ten text fields.
4) Display All
When this button is pressed, the display number is printed and the method to display the details of the gadget is called, for each gadget in the array list.
5) Make A Call
The display number, phone number and duration are input via the GUI. When this button is pressed, the method to get the display number is called and its value is checked. If it is not equal to –1:
- The display number is used to get the gadget from the array list and cast it to Mobile.
- The method to make a call in the Mobile class is called with the phone number and duration entered.
6) Download Music
The display number and download size are input via the GUI. When this button is pressed, the method to get the display number is called and its value is checked. If it is not equal to –1:
- The display number is used to get the gadget from the array list and cast it to MP3.
- The method to download music in the MP3 class is called with the download size entered.
Marks will be awarded as follows:
1) GUI [12 marks]
2) The actionPerformed method [2 marks]
3) The main method [1 mark]
4) Functionality of buttons [18 marks]
5) Reading input [10 marks]
6) Use of try/catch, checking input and displaying appropriate message dialogs [7 marks]
7) Program style (see http://www.bluej.org/objects-first/styleguide.html) [10 marks]
Report (40 marks)
The report should contain:
A class diagram of the GadgetShop class only, showing the name of the class, the data types and names of the fields, and the return types and signatures of all of the methods. [3 marks]
Pseudocode for the following button-handling methods:
- Getting the display number from the GUI
- Adding a mobile
- Adding an MP3
- Displaying all gadgets in the array list
- Making a call
- Downloading music [12 marks]
A short description of each of the 6 methods above [3 marks]