Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(1) The CellPhone class Assume that a cell phone retailer wanted you to write a

ID: 3782084 • Letter: #

Question

(1) The CellPhone class Assume that a cell phone retailer wanted you to write a program to keep track of its inventory. Define an object called CellPhone which maintains state representing a cell phone's model (a string), manufacturer (a string), monthsWarranty (an integer) and price (a float) All instance variables (i.e. attributes) should be made private. Create a zero-parameter constructor as well as one that takes all 4 parameters (in the order listed above). Also create get and set methods for each attribute. Save and compile the file. The program below is called CellPhoneTestProgram and it should test your CellPhone methods. However, the testing code is incomplete (see highlighted areas). Please complete the testing code according to the directions given, then test out the code to make sure that it works: tesling code according to the direcions gven, hen test out the cde to ake sure thatit works

Explanation / Answer

CellPhone.java

public class CellPhone {

  
   //Declaring instance variables
private String model;
private String manufacture;
private int monthsWarranty;
private float price;

//Zero argumented constructor
public CellPhone() {
}

//Parameterized constructor
public CellPhone(String model, String manufacture, int monthsWarranty,
       float price) {
   this.model = model;
   this.manufacture = manufacture;
   this.monthsWarranty = monthsWarranty;
   this.price = price;
}

//Setters and getters
public String getModel() {
   return model;
}
public void setModel(String model) {
   this.model = model;
}
public String getManufacture() {
   return manufacture;
}
public void setManufacture(String manufacture) {
   this.manufacture = manufacture;
}
public int getMonthsWarranty() {
   return monthsWarranty;
}
public void setMonthsWarranty(int monthsWarranty) {
   this.monthsWarranty = monthsWarranty;
}
public float getPrice() {
   return price;
}
public void setPrice(float price) {
   this.price = price;
}


}

____________________

CellPhoneTestProgram.java

public class CellPhoneTestProgram {

   public static void main(String[] args) {
      
       //Creating the CellPhone class objects by passing the arguments
       CellPhone iphone=new CellPhone("iPhone6Plus","Apple",12, 915);
       CellPhone galaxy=new CellPhone("Galaxy S7","Samsung",18, 900);
       CellPhone priv=new CellPhone("PRIV","BlackBerry",24, 890);
      
      
       //Displaying the iphone class object information
       System.out.println("Here is the Apple phone information :");
       System.out.println(iphone.getModel());
       System.out.println(iphone.getManufacture());
       System.out.println(iphone.getMonthsWarranty());
       System.out.println(iphone.getPrice());

      
       //Displaying the samsung class object information      
       System.out.println("Here is the Samsung phone information :");
       System.out.println(galaxy.getModel());
       System.out.println(galaxy.getManufacture());
       System.out.println(galaxy.getMonthsWarranty());
       System.out.println(galaxy.getPrice());
      
      
       //Displaying the BlackBerry class object information
       System.out.println("Here is the BlackBerry phone information :");
       System.out.println(priv.getModel());
       System.out.println(priv.getManufacture());
       System.out.println(priv.getMonthsWarranty());
       System.out.println(priv.getPrice());  
      
       //Displaying the total price of three phones
       System.out.println("The Total cost of all phones is $"+(iphone.getPrice()+galaxy.getPrice()+priv.getPrice()));

      
       //Displaying which mobile has largest warranty
       if(iphone.getMonthsWarranty()>galaxy.getMonthsWarranty() && iphone.getMonthsWarranty()>priv.getMonthsWarranty())
           System.out.println("The Apple phone has the longest warranty");
       else if(galaxy.getMonthsWarranty() > priv.getMonthsWarranty())
           System.out.println("The Galaxy phone has the longest warranty");
       else
           System.out.println("The BlackBerry phone has the longest warranty");
   }

}

_______________________

Output:

Here is the Apple phone information :
iPhone6Plus
Apple
12
915.0
Here is the Samsung phone information :
Galaxy S7
Samsung
18
900.0
Here is the BlackBerry phone information :
PRIV
BlackBerry
24
890.0
The Total cost of all phones is $2705.0
The BlackBerry phone has the longest warranty

___________Thank You