Java Assignment: Class Design, Implementation, and Testing of Gadgets
VerifiedAdded on  2019/09/20
|16
|1551
|57
Practical Assignment
AI Summary
This Java assignment focuses on the implementation of a Gadget class and its subclasses, Mobile and MP3. The solution includes the creation of these classes with appropriate attributes and methods, such as `addCallingCredits`, `phoneCall`, `downloadMusic`, and `deleteMusic`. The code demonstrates inheritance and object-oriented principles. Test cases are provided to validate the functionality of each class, including scenarios for adding calling credits, making phone calls, downloading and deleting music. A class diagram visually represents the class structure and relationships. The `TestClass` demonstrates how to create and interact with objects of each class, showcasing the expected behavior through various test scenarios. This assignment provides a comprehensive understanding of Java programming, class design, and testing methodologies.

Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Contents
Class Diagram..................................................................................................................................3
Test Cases and Screen Shots............................................................................................................4
Test 1:..........................................................................................................................................4
Test 2:..........................................................................................................................................4
Test 3:..........................................................................................................................................4
Test 4:..........................................................................................................................................4
Test 5:..........................................................................................................................................4
Test 6:..........................................................................................................................................4
Code with description......................................................................................................................5
Gadget.java..................................................................................................................................5
Mobile.java..................................................................................................................................7
MP3.java....................................................................................................................................10
TestClass.java............................................................................................................................12
Class Diagram..................................................................................................................................3
Test Cases and Screen Shots............................................................................................................4
Test 1:..........................................................................................................................................4
Test 2:..........................................................................................................................................4
Test 3:..........................................................................................................................................4
Test 4:..........................................................................................................................................4
Test 5:..........................................................................................................................................4
Test 6:..........................................................................................................................................4
Code with description......................................................................................................................5
Gadget.java..................................................................................................................................5
Mobile.java..................................................................................................................................7
MP3.java....................................................................................................................................10
TestClass.java............................................................................................................................12

Class Diagram
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

Test Cases and Screen Shots
Test 1: Inspect a mobile phone, add calling credit, and re-inspect the mobile phone
Test 2: Inspect a mobile phone, make a call, and re-inspect the mobile phone
Test 3: Call the method to display the details of a mobile phone
Test 4: Inspect an MP3 player, download music, re-inspect theMP3 player
Test 5: inspect an MP3 player, delete a piece of music, and re-inspect the MP3 player
Test 6: Call the method to display the details of an MP3 player
One screen shot for all test cases
Test 1: Inspect a mobile phone, add calling credit, and re-inspect the mobile phone
Test 2: Inspect a mobile phone, make a call, and re-inspect the mobile phone
Test 3: Call the method to display the details of a mobile phone
Test 4: Inspect an MP3 player, download music, re-inspect theMP3 player
Test 5: inspect an MP3 player, delete a piece of music, and re-inspect the MP3 player
Test 6: Call the method to display the details of an MP3 player
One screen shot for all test cases
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser


⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

Code with description
Gadget.java
public class Gadget {
private String model; // gadget model name
private String size;// gadget size
private double price;// gadget price
private int weight ; // gadget weight
/* this constructor initialize the all the instance variables */
public Gadget(String m,String s, double p, int w){
this.model = m;
this.size = s;
this.price =p;
this.weight = w;
}
Gadget.java
public class Gadget {
private String model; // gadget model name
private String size;// gadget size
private double price;// gadget price
private int weight ; // gadget weight
/* this constructor initialize the all the instance variables */
public Gadget(String m,String s, double p, int w){
this.model = m;
this.size = s;
this.price =p;
this.weight = w;
}
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

// this getModel method returns the model name
public String getModel() {
return model;
}
// getSize() method returns the size of gadget
public String getSize() {
return size;
}
// getPrice() method return price of gadget
public double getPrice() {
return price;
}
// getWeight() method returns weight of gadget
public int getWeight() {
return weight;
}
// display() method returns the details of gadget, model, size, price and weight
public void display(){
String str = "Model: "+this.model+"\n"+
"Size: "+this.size+"\n"+
public String getModel() {
return model;
}
// getSize() method returns the size of gadget
public String getSize() {
return size;
}
// getPrice() method return price of gadget
public double getPrice() {
return price;
}
// getWeight() method returns weight of gadget
public int getWeight() {
return weight;
}
// display() method returns the details of gadget, model, size, price and weight
public void display(){
String str = "Model: "+this.model+"\n"+
"Size: "+this.size+"\n"+

"Price: "+this.price+"\n"+
"Weight: "+this.weight;
System.out.println(str); // this method prints the details of gadget (mobile or mp3 player)
}
}
Mobile.java
public class Mobile extends Gadget {
public double noOfMinsOfCallingCredits; // number of minutes of calling credits
/* this constructor initialize the Mobile class instance variable */
public Mobile(float noOfMinsOfCallCrdts, String model, String size, double price, int weight)
{
super(model, size, price, weight); // calling the super class that is Gadget constructor to
// initialize the Gadget instance variables
this.noOfMinsOfCallingCredits = noOfMinsOfCallCrdts;
}
// getNoOfMinutes() method returns the number of minutes of calling credits
public double getNoOfMinutes() {
"Weight: "+this.weight;
System.out.println(str); // this method prints the details of gadget (mobile or mp3 player)
}
}
Mobile.java
public class Mobile extends Gadget {
public double noOfMinsOfCallingCredits; // number of minutes of calling credits
/* this constructor initialize the Mobile class instance variable */
public Mobile(float noOfMinsOfCallCrdts, String model, String size, double price, int weight)
{
super(model, size, price, weight); // calling the super class that is Gadget constructor to
// initialize the Gadget instance variables
this.noOfMinsOfCallingCredits = noOfMinsOfCallCrdts;
}
// getNoOfMinutes() method returns the number of minutes of calling credits
public double getNoOfMinutes() {
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

return noOfMinsOfCallingCredits;
}
// add new calling credits - number of minutes
/**
* if phone call credits greater than zero then
* it will added to existing number of minutes of calling credits
* otherwise error message will be printed
* @param newCallingCredits // number of mins of calling credits to add
*/
public void addCallingCredits(double newCallingCredits) {
if (newCallingCredits > 0) { // checking the new calling credits if greater than zero
this.noOfMinsOfCallingCredits += newCallingCredits;
} else { // if new calling credits less than 0 then error message will be printed
System.out.println("Please enter positive amount!"); // error message
}
}
// this method make the phone call
/**
* if remaining calling charges are not less than zero then
* an error message will be printed
* other wise phone number and call duration will be printed
}
// add new calling credits - number of minutes
/**
* if phone call credits greater than zero then
* it will added to existing number of minutes of calling credits
* otherwise error message will be printed
* @param newCallingCredits // number of mins of calling credits to add
*/
public void addCallingCredits(double newCallingCredits) {
if (newCallingCredits > 0) { // checking the new calling credits if greater than zero
this.noOfMinsOfCallingCredits += newCallingCredits;
} else { // if new calling credits less than 0 then error message will be printed
System.out.println("Please enter positive amount!"); // error message
}
}
// this method make the phone call
/**
* if remaining calling charges are not less than zero then
* an error message will be printed
* other wise phone number and call duration will be printed
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

* @param phoneNumber // called phone number
* @param callDuration // total call duration in minutes
*/
public void phoneCall(String phoneNumber, float callDuration) {
double remainingCharges = noOfMinsOfCallingCredits - callDuration;
if (!(remainingCharges < 0)) { // if remaining calling credits not less than zero then
// a message will be printed and the user calling credits will be updated
System.out.println("Phone number: " + phoneNumber + "\n"
+ "Call Duration: " + callDuration + " mins");
this.noOfMinsOfCallingCredits = remainingCharges;
} else {// if the calling credits less than zero than a message will be printed
// user cannot make call because of insufficient credit.
System.out.println("Insufficient credit to make the call!"); // print message
}
}
/**
* this method print the details
*/
public void display() {
* @param callDuration // total call duration in minutes
*/
public void phoneCall(String phoneNumber, float callDuration) {
double remainingCharges = noOfMinsOfCallingCredits - callDuration;
if (!(remainingCharges < 0)) { // if remaining calling credits not less than zero then
// a message will be printed and the user calling credits will be updated
System.out.println("Phone number: " + phoneNumber + "\n"
+ "Call Duration: " + callDuration + " mins");
this.noOfMinsOfCallingCredits = remainingCharges;
} else {// if the calling credits less than zero than a message will be printed
// user cannot make call because of insufficient credit.
System.out.println("Insufficient credit to make the call!"); // print message
}
}
/**
* this method print the details
*/
public void display() {

super.display(); // calling the super class display method user super keyword
// this method will display the gadget (mobile) details like model, price, weight
String str = "Remaining Calling Credits: " + noOfMinsOfCallingCredits+"\n";
System.out.println(str); // print the calling credits of user
}
}
MP3.java
public class MP3 extends Gadget {
private double availbleMemory; // memory size of mp3 player
/* this constructor initialize the instance variable to this class */
public MP3(float memory, String model, String size, double price, int weight) {
super(model, size, price, weight); // calling the super class Gadget constructor to
initialize // //the Gadget class variables
this.availbleMemory = memory;
}
// this method will display the gadget (mobile) details like model, price, weight
String str = "Remaining Calling Credits: " + noOfMinsOfCallingCredits+"\n";
System.out.println(str); // print the calling credits of user
}
}
MP3.java
public class MP3 extends Gadget {
private double availbleMemory; // memory size of mp3 player
/* this constructor initialize the instance variable to this class */
public MP3(float memory, String model, String size, double price, int weight) {
super(model, size, price, weight); // calling the super class Gadget constructor to
initialize // //the Gadget class variables
this.availbleMemory = memory;
}
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 16
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
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.