MusicFile Psuedocode
MusicFile Psuedocode
1 Class Diagram…………………………………………………….
2. Pseudo Code…………………………………………………….
2.1. Getting the display number from the GUI
2.2. Adding a mobile
2.3. Adding an MP3
2.4. Displaying all gadgets in the array list
2.5. Making a call
2.6. Downloading music
3. Description…………………………………………………….
4. Testing………………………………………………………….
4.1. Test 1: Adding a calling credit
4.2. Test 2: Make a Call
4.3. Test 3: Displaying the details of mobile phone
4.4. Test 4: Download MP3 music
4.5. Test 5: Delete the Memory
4.6 Test 6: Display MP3 Device Details
Conclusion………………………………………………………
Pseudo Code…………………………………………………….
Introduction
This is an assignment task to create an object-oriented Class structure with three classes.
Gadget / Mobile and MP3. the task with these classes is using inheritance using Java as a
programming language. We are using the key word Extend to achieve this. The attributes
declared in the top main Constructor class and a default method “Display ()” in the main class
gadget play a key role in this object-oriented approach.
The two child classes MP3 and Mobile are also acting as two different objects of Main class
gadget. Thus, these two objects type classes inherit the properties of main gadget classes along
with its own new properties.
One of the unique things we will see in this task assignment is we will see that the gadget class
display method defining 4 attributes that is model, weight, size and price of a gadget. and each
of the child class can utilize these attributes in terms of displaying or showing the results on the
screen using exactly the same format defined in the constructor class. Thus, we can say that
the inheritance is used here not only to inherit the properties and values but also the format and
the displaying result shape as well.
Class Diagram
We will define the variables and methods of each class in detailed bellow.
Class Gadget
It is the top-level base class as explain in the above introduction. the 4 attributes defined in this
class are
1. Model – type = string (this string show gadget model type like Samsung A8 etc.)
2. Size - type = double (these are three values i.e. WIDTH X LENGTH X BREADTH) the unit of
measurement is Millimeter (MM)
3. Price - type = int (This is a whole number showing the price) the default unit used here is
USD
4. Weight – type = double (This is whole number showing weight of the gadget device) the
default unit if weight is grams.
To create a gadget object this class uses constructor. the above four attributes declared in here
are used as main entry of values. and then the display () function which show the gadget values
in predefined formats
Class Mobile
This class is inherited from the main gadget class including all attributes and methods. The
Mobile Phone as an object of gadget type has some extra attributes “calling minutes” for each
specific phone the calling minutes are separately calculated. In the constructor class the
minutes is an extra attribute the rest of all are same inherited of parent class. Here in
constructor, we use a special java function super () for calling minutes attribute to set it with all
other parent’s attributes. The Mobile class methods are as following
2 makeCall (CallingNumber, CallDuration): This method declared in the mobile class has two
arguments as an attribute. The CallingNumber is of string type and it accept all valid phone
numbers. and CallDuration is of int type it returns the total number of minutes call was made
and verify by comparing the CallDuration with AvailableMinutes that this call has enough
positive minutes to make a call. If in case the CallDuration is greater than available minutes the
system will throw an exception and will stop making a call and exit this method on the other
hand it will simply deduct the CallDuration Number from the AvailableMinutes.
3 displays (): This is a local display function is returning the status of the phone call it also calls
the main display () function in the top class and returns the number of the calling minutes.
Class MP3
This is another type of gadget serving as an object of the main gadget class. MP3 class as a
child class has its own defined attributes and methods. Along with all the attributes inherit from
parent class it has an extra attribute called Memory it serves as a storage space available in the
MP3 player device.
following are the Methods defined in MP3 Class
1. download (fileSize): the argument in this local function verifies that the device has
enough memory by comparing both of fileSize and availableMemor.in case the fileSize is
greater than the availableMemory the system generates an exception and exit the
function by producing alert message of insufficient Memory. On the other hand, it fileSize
is deducted from the availableMemory and file is downloaded in the device successfully
2. delete (fileSize): This internal method in the class adds the fileSize int number to the
availableMemory. It also verifies if the fileSize is a positive integer to be added otherwise
it throw an exception that a positive number needs to be provided to delete the file and
free up the memory
3. display (): Its again a local method calling super method from parent class it prints the
main attributes from Gadget class and available memory of the MP3 device
Testing results
1: Adding Calling Credit
In the first compilation I received above syntax error in the mp3 class after removing this error I
recompile all the files and it work and got the following results
This is the result of the main class
* Test 2: Inspect a mobile phone, make a call, re-inspect the mobile phone
After calling the makeCall Method with call duration 6 the method return 39 minutes means from
total 45 minutes 6 minutes were deducted.
* Test 4: Inspect an MP3 player, download music, re-inspect the MP3 player
RAM of the MP3 device Lenovo 55 before downloading 13 MB
After deleting the RAM from MP3 device by calling MP3->delete (7) 7 MB of Ram is removed.
public Gadget (String model, double price, double weight, String size) {
this.price = price;
this.size = size;
this.model = model;
this.weight = weight;
}
s
Mobile.java
/*
Implements a class with attributes and methods for a mobile phone
Extends the Gadget class
*/
this.minutes += NoOfMinutes;
System.out.println(" Number of minutes added into the system: " + NoOfMinutes);
} else {
System.out.println("Enter Number of Minutes to be Added");
}
}
/*
makeCall function with 2 arguments phone Number and No of minutes call to make
*/
public void makeCall(String phonenumber, int callDuration) {
if (this.minutes >= callDuration) {
System.out.println("Dialing " + phonenumber);
System.out.println(callDuration + " minutes debited from your plan");
this.minutes -= callDuration;
} else {
System.out.println("There is insufficient credit to make this call");
}
}
/*
Display all variables using main class display function
Super function to show the local data of remaining AvailableMinutes
*/
public void display() {
System.out.println("Mobile Details ");
super.display();
System.out.println("Available Minutes: " + this.minutes);
System.out.println("----------------------------\n");
}
}
Mp3.java
/**
* Implements a class for the Mp3 Gadget. Extends the Gadget class
*/
/*
Remove the given amount of memory and display the remaining memory left in MBs
*/
public void delete(int fileSize)
{
if (fileSize >= 0)
{
this.memory += fileSize; System.out.println("Deleted amount of memory " + fileSize + “MB”);
} else {
System.out.println("Size of file cannot be negative"); } }
/*
Display all the parameters related to the device and the A
*/