Design and Implement Gadget Hierarchy
VerifiedAdded on 2019/09/18
|2
|1076
|633
Project
AI Summary
The assignment is to create a class called Gadget with two subclasses, Mobile and MP3. The Gadget class has four attributes: model, price, weight, and size. Each subclass (Mobile and MP3) has its own specific attributes and methods. The Mobile class has an attribute for the number of minutes of calling credit remaining and methods to add credit, make a phone call, and display details. The MP3 class has an attribute for available memory and methods to download and delete music, as well as display details.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
Assignment
Aim
The aim of this assignment is to create a class to represent a gadget, together with two subclasses to
represent a mobile phone and an MP3 player respectively. 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
WebLearn. Your report should be no more than 1200 words in length (excluding the table of contents,
class diagram and code listing).
Deliverables
When you are ready to submit your solution, upload your Gadget.java, Mobile.java and MP3.java files
(not any other files from the project) to WebLearn together with your report in Microsoft Word format
and, when you are absolutely sure that you have uploaded the correct files, press the submit button.
Program (60 marks)
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),
theweight (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 constructor's 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 [20 marks]
2) The Mobile class is a subclass of the Gadget class and has just one attribute, which corresponds
tothe (whole) number of minutes of calling credit remaining. The attribute is initialised in the
constructor by being assigned the value of one of the constructor's 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,
Aim
The aim of this assignment is to create a class to represent a gadget, together with two subclasses to
represent a mobile phone and an MP3 player respectively. 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
WebLearn. Your report should be no more than 1200 words in length (excluding the table of contents,
class diagram and code listing).
Deliverables
When you are ready to submit your solution, upload your Gadget.java, Mobile.java and MP3.java files
(not any other files from the project) to WebLearn together with your report in Microsoft Word format
and, when you are absolutely sure that you have uploaded the correct files, press the submit button.
Program (60 marks)
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),
theweight (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 constructor's 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 [20 marks]
2) The Mobile class is a subclass of the Gadget class and has just one attribute, which corresponds
tothe (whole) number of minutes of calling credit remaining. The attribute is initialised in the
constructor by being assigned the value of one of the constructor's 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,
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
the weight and the size. The number of minutes of calling credit remaining is then output suitably
annotated. [15 marks]
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 constructor's 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. [15 marks]
4) Additional marks will be awarded for good program style, particularly naming, layout and
documentation. See http://www.bluej.org/objects-first/styleguide.html for details. [10 marks]
Report (40 marks)
The report should contain:
A class diagram showing the inheritance relationship between the three classes and, for each class, the
name of the class, the data types and names of the fields and the return types and signatures of the
methods [10 marks]
A short description of what each method does [5 marks]
You should give evidence (through appropriate screenshots) of the following testing that you carried
out on your program:
Test 1: Inspect a mobile phone, add calling credit, re-inspect the mobile phone[2 marks]
Test 2: Inspect a mobile phone, make a call, re-inspect the mobile phone[2 marks]
Test 3: Call the method to display the details of a mobile phone [2 marks]
Test 4: Inspect an MP3 player, download music, re-inspect the MP3 player [2 marks]
Test 5: Inspect an MP3 player, delete a piece of music, re-inspect the MP3 player [2 marks]
Test 6: Call the method to display the details of an MP3 player [2 marks]
annotated. [15 marks]
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 constructor's 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. [15 marks]
4) Additional marks will be awarded for good program style, particularly naming, layout and
documentation. See http://www.bluej.org/objects-first/styleguide.html for details. [10 marks]
Report (40 marks)
The report should contain:
A class diagram showing the inheritance relationship between the three classes and, for each class, the
name of the class, the data types and names of the fields and the return types and signatures of the
methods [10 marks]
A short description of what each method does [5 marks]
You should give evidence (through appropriate screenshots) of the following testing that you carried
out on your program:
Test 1: Inspect a mobile phone, add calling credit, re-inspect the mobile phone[2 marks]
Test 2: Inspect a mobile phone, make a call, re-inspect the mobile phone[2 marks]
Test 3: Call the method to display the details of a mobile phone [2 marks]
Test 4: Inspect an MP3 player, download music, re-inspect the MP3 player [2 marks]
Test 5: Inspect an MP3 player, delete a piece of music, re-inspect the MP3 player [2 marks]
Test 6: Call the method to display the details of an MP3 player [2 marks]
1 out of 2
Related Documents
Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
© 2024 | Zucol Services PVT LTD | All rights reserved.