Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
77 views

MusicFile Psuedocode

This document describes an object-oriented program that models gadgets using inheritance in Java. It defines a Gadget parent class with attributes like model, price, size, and weight. Mobile and MP3 child classes inherit these attributes and define additional ones - Mobile has minutes and MP3 has memory. Methods are created to add/use minutes or download/delete files. The document includes class diagrams, pseudo code for each class' methods, and test results demonstrating adding calls/music and displaying gadget details using inheritance and polymorphism.

Uploaded by

Ashfaq Jan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

MusicFile Psuedocode

This document describes an object-oriented program that models gadgets using inheritance in Java. It defines a Gadget parent class with attributes like model, price, size, and weight. Mobile and MP3 child classes inherit these attributes and define additional ones - Mobile has minutes and MP3 has memory. Methods are created to add/use minutes or download/delete files. The document includes class diagrams, pseudo code for each class' methods, and test results demonstrating adding calls/music and displaying gadget details using inheritance and polymorphism.

Uploaded by

Ashfaq Jan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Introduction

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

1 addMinutes (minutesNumbers) :- the minutesNumbers is credited in the specific mobile


phone as it is provided by the input user. A verification handler here checks this number if it is
greater than zero it will be credited otherwise an exception alert will occur.

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 3: Call the method to display the details of a mobile phone

* 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 calling the MP3->download (21); we get the new RAM of 34 MB

* Delete Music from MP3 device

After deleting the RAM from MP3 device by calling MP3->delete (7) 7 MB of Ram is removed.

* Test 6: Call the method to display the details of an MP3 player


Conclusion
Looking at this document we can conclude that the inheritance in Java Programming language
using extend is very useful for the requirements in which a parent class has all the basic
attributes and methods define and each child class has it local define parameters and methods
can be used for child object requirements.
Another benefit we are getting using this inheritance is we don’t need to format the template of
output results in each object like here we have used the display() function in top level class
gadget and the format of output is same for both gadget and mp3 devices.
we also have saved the resources to declare the reusable parameters again and again and this
is achieved by using the magical technique of using Constructors. The Constructors save us to
redefine the reusable methods and parameters.
we have seen the use of super () function to make the local methods used globally and then the
use of word PIBLIC with the top-level super class how it helps to inherit all its properties in child
class
Java Code of the task
Gadgets.java
/* Class Gadget: Top level class */

public class Gadget {


/* Declaring the variables */
public String model;
public String size;
public double price;
public double weight;

public Gadget (String model, double price, double weight, String size) {

/* Initializing the Constructors parameters */

this.price = price;
this.size = size;
this.model = model;
this.weight = weight;
}
s

/* Show the results using the gadget properties */


/* The model is string, price in USD, weight in Grams, the size in Millimeter */

public void display()


{
System.out.println("Model: " + this.model);
System.out.println("Price: " + this.price + “ USD” );
System.out.println("Weight: " + this.weight + “ G ”);
System.out.println("Size: " + this.size );
}
}

Mobile.java
/*
Implements a class with attributes and methods for a mobile phone
Extends the Gadget class
*/

public class Mobile extends Gadget {


public int minutes;
public Mobile(String model, double price, double weight, String size, int minutes) {

super(model, price, weight, size);


this.minutes = minutes;
}

/* Add New Minutes to the system */

public void addMinutes (int NoOfMinutes) {


if (NoOfMinutes > 0) {

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
*/

public class Mp3 extends Gadget {


public int memory;
/*
Constructor of the MP3 Class
Local variable memory is declared
*/
public Mp3(String model, double price, double weight, String size, int memory) {
super(model, price, weight, size);
this.memory = memory;
}
/*
Download function to display the size of the file in MBs
*/

public void download(int fileSize) {


if (this.memory >= fileSize)
{
System.out.println("Downloading file of size " + fileSize + “MB”);
this.memory -= fileSize;
} else {
System.out.println("Memory Full, Unable to download");
}
}

/*
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
*/

public void display () {


System.out.println(" Details of Mp3 Section ");
super.display();
System.out.println(" MP3 Available Memory: " + this.memory);
}
}

You might also like