Recent Question/Assignment
This is worth 60 marks
Program
The program should consist of the following classes (with no additional attributes or methods).
1) The Gadget class has four attributes, which correspond to the model, the price (in pounds), the weight (in grams), the size (e.g. “71mm x 137mm x 9mm”) respectively. The price is a decimal number, the weight is an integer, and the model and the size are strings of text. Each attribute is initialised in the constructor, by being assigned the value of one of the constructors four parameters, and each attribute has a corresponding accessor method. A display method will output (suitably annotated) the model, the price, the weight and the size
2) The Mobile class is a subclass of the Gadget class and has just one attribute, which corresponds to the (whole) number of minutes of calling credit remaining. The attribute is initialised in the constructor by being assigned the value of one of the constructors five parameters and it has a corresponding accessor method. The other parameters of the constructor represent the model the price, the weight and the size of the mobile phone and these four values are passed to the constructor of the Gadget class.
The Mobile class has a method so that the user of the mobile can add (via a parameter) calling credit to the amount that they currently have. If the amount of credit provided by the user is greater than zero then this amount is added to the amount of credit stored in the mobile. Otherwise, a message is displayed prompting the user to enter a positive amount.
There is also a method to represent the user making a phone call. The user needs to provide the phone number and the duration of the call in minutes. If there is enough credit then a message giving the phone number and duration is displayed and the remaining calling credit is reduced by the number of minutes that the call lasted. Otherwise, a message informing the user that there is insufficient credit to make the call is displayed.
A method to display the details of the mobile is required. It must have the same signature as the display method in the Gadget class. It will call the method in the Gadget class to display the model, the price, the weight and the size. The number of minutes of calling credit remaining is then output suitably annotated.
3) The MP3 class is also a subclass of the Gadget class and has just one attribute, which corresponds to the available memory. The attribute is initialised in the constructor by being assigned the value of one of the constructors five parameters and it has a corresponding accessor method. The other parameters of the constructor represent the model, the price, the weight and the size of the MP player and these four values are passed to the constructor of the Gadget class.
The MP3 class also has a method for downloading music which takes a parameter representing the amount of memory that the music will take up and, if there is sufficient available memory on the MP3 player, decreases the available memory accordingly, otherwise an appropriate error message is printed. There is also a method for deleting music which takes a parameter representing the amount of memory that the music took up and increases the available memory of the MP3 player accordingly.
A method to display the details of the MP3 player is required. It must have the same signature as the display method in the Gadget class. It will call the method in the Gadget class to display the model, the price, the weight and the size. The available memory is then output suitably annotated.
4) Additional marks will be awarded for good program style, particularly naming, layout and documentation.