In: Computer Science
Write a tester program to test the mobile class defined below.
Create the class named with your id (for example: Id12345678) with the main method.
Your answer should include a screenshot of the output. Otherwise, you will be marked zero for this question.
public class Mobile {
private int id;
private String brand;
public Mobile() {
id = 0;
brand = "";
}
public Mobile(int n, String name) {
id = n;
brand = name;
}
public void setBrand(String w) {
brand = w;
}
public void setId(int w) {
id = w;
}
Public int getId() {
class Mobile {
private int id;
private String brand;
public Mobile() { // Constructor 1 - Default Constructor
id = 0;
brand = "";
}
public Mobile(int n, String name) { // Constructor 2 - Parameterised Constructor
id = n;
brand = name;
}
public void setBrand(String w) {
brand = w;
}
public void printCharacterstics()
{
System.out.printf("Id:%d\n",id);
System.out.printf("Brand:"+brand,"\n");
System.out.printf("\n");
}
public void setId(int w) {
id = w;
}
public int getId()
{
return id;
}
public int changeId(int n){
id = n;
return 0;
}
public int changeBrand(String b){
brand = b;
return 0;
}
}
class Main
{
public static void main(String[] args) {
Mobile m1 = new Mobile(); // Create object m1 with
constructor 1
Mobile m2 = new Mobile(); // Create object m2 with
constructor 1
m1.setId(1100123456); // Set the id of m1
m1.setBrand("Samsung"); // Set the Brand of m1
m2.setId(1100654123); // Set the id of m2
m2.setBrand("Apple"); // Set the Brand of m1
System.out.println("Characterstics of M1:\n");
m1.printCharacterstics(); // Call function
printCharacterstics to print the characterstics
System.out.println("\nCharacterstics of M2:\n");
m2.printCharacterstics();
Mobile m3 = new Mobile(1100789456,"Huwai"); // Create the object m3 with second constructor
System.out.printf("\nCharacterstics of M3:\n");
m3.printCharacterstics();
m3.changeId(1234567890); // Change the id of m3
m3.changeBrand("OnePlus"); // Change the brand of m3
System.out.printf("\nId of M3(After Change):%d",m3.getId()); // Print the id of m3
}
}
OUTPUT: