Question: How would i write this code in Java. The program should consist of the following classes ( with no additional attributes or methods ) .

How would i write this code in Java. 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 (inpounds), 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 sizeare strings of text. Each attribute is initialised in the constructor, by being assigned thevalue of one of the constructor's four parameters, and each attribute has acorresponding accessor method. A display method will output (suitably annotated) themodel, the price, the weight and the size2. The Mobile class is a subclass of the Gadget class and has just one attribute, whichcorresponds to the (whole) number of minutes of calling credit remaining. The attributeis initialised in the constructor by being assigned the value of one of the constructor'sfive parameters and it has a corresponding accessor method. The other parameters ofthe 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.TheMobile 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 providedby the user is greater than zero then this amount is added to the amount of creditstored in the mobile. Otherwise, a message is displayed prompting the user to enter apositive 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. Ifthere is enough credit then a message giving the phone number and duration isdisplayed and the remaining calling credit is reduced by the number of minutes thatthe call lasted. Otherwise, a message informing the user that there is insufficient creditto 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 callthe method in the Gadget class to display the model, the price, the weight and thesize. The number of minutes of calling credit remaining is then output suitablyannotated.3. The MP3 class is also a subclass of the Gadget class and has just one attribute, whichcorresponds to the available memory. The attribute is initialised in the constructor bybeing assigned the value of one of the constructor's five parameters and it has acorresponding accessor method. The other parameters of the constructor representthe model, the price, the weight and the size of the MP player and these four valuesare passed to the constructor of the Gadget class.The MP3 class also has a methodfor downloading music which takes a parameter representing the amount of memorythat the music will take up and, if there is sufficient available memory on the MP3player, decreases the available memory accordingly, otherwise an appropriate errormessage is printed. There is also a method for deleting music which takes aparameter representing the amount of memory that the music took up and increasesthe available memory of the MP3 player accordingly.A method to display the details ofthe MP3 player is required. It must have the same signature as the display method inthe Gadget class. It will call the method in the Gadget class to display the model, theprice, the weight and the size. The available memory is then output suitablyannotated.4. The GadgetShop class should store an array list (not an array) of type Gadget to holdthe gadgets. An example GUI is shown below: Your GUI (GadgetShop class) shouldcontain the same components, but you are free to use a different layout if you feel thatit improves the aesthetics, ease of use etc.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!