java





/**

* COSC 1436

* EL Centro

* Week 15

* Cell Phone Class

*

* This CLASS does not need to change

*

*/

import java.util.ArrayList;

import java.util.Arrays;



public class CellPhone {

// Attributes

private final ArrayList AVAILABLE_BATTERY_TYPES = new ArrayList<>(

Arrays.asList("NiCd", "NiMH", "Lo-ion", "Li-pol"));

private ArrayList favoritePhoneNumbers = new ArrayList();



private String cellProvider = "AT&T";

private String batteryType = null;

private boolean isFlipPhone = false;

private boolean hasInternational = false;



// Methods

public ArrayList getFavoritePhoneNumbers() {

return favoritePhoneNumbers;

}



public void addAFavoritePhoneNumber(Long phoneNumber) {

this.favoritePhoneNumbers.add(phoneNumber);

}



public void deleteAFavoritePhoneNumber(int phoneNumber) {

this.favoritePhoneNumbers.remove(phoneNumber);

}



public String getCellProvider() {

return cellProvider;

}



public void setCellProvider(String cellProvider) {

this.cellProvider = cellProvider;

}



public String getBatteryType() {

return batteryType;

}



/**

* Validates battery type

* @param batteryType

* @return

*/

public boolean setBatteryType(String batteryType) {

if (AVAILABLE_BATTERY_TYPES.contains(batteryType)) {

this.batteryType = batteryType;

return true;

}

return false;

}



public boolean isFlipPhone() {

return isFlipPhone;

}



public void setFlipPhone(boolean isFlipPhone) {

this.isFlipPhone = isFlipPhone;

}



public boolean isHasInternational() {

return hasInternational;

}



public void setHasInternational(boolean hasInternational) {

this.hasInternational = hasInternational;

}



public ArrayList getAVAILABLE_BATTERY_TYPES() {

return AVAILABLE_BATTERY_TYPES;

}



public boolean isValidBatteryType() {

return batteryType != null;

}



@Override

public String toString() {

StringBuilder builder = new StringBuilder();

builder.append("CellPhone [favoritePhoneNumbers=");

builder.append(favoritePhoneNumbers);

builder.append(", cellProvider=");

builder.append(cellProvider);

builder.append(", batteryType=");

builder.append(batteryType);

builder.append(", isFlipPhone=");

builder.append(isFlipPhone);

builder.append(", hasInternational=");

builder.append(hasInternational);

builder.append(", valid battery type=");

builder.append(isValidBatteryType());

builder.append("]");

return builder.toString();

}



}

Create a new Java Project for this assignment.

       Copy the provided class CellPhone into your default package area.

  1. Create a new class called SmartPhone that extends CellPhone. Add the following attributes:

    1. boolean – hasGPS. 
    2. boolean – hasWIFI. 
    3. String OSVersion.   Default to “Windows 10 Mobile”;
    4. long internalMemoryStorageCapacity – Default to 16_000_000_000L;
    5. Generate the setters and getters and toString() method.
  2. Create a new class called TestPhone that includes a main() method.
  3. Inside the main() method of TestPhone, do the following: 
    1. Create an instance of CellPhone. Set all the following attributes to values of your choosing: (Call all the setters with values) 
      1. cell provider
      2. isFlipPhone
      3. hasInternational
      4. batteryType
      5. Add 2 favorite phone numbers
    2. Display the CellPhone toString results.
    3. Create an instance of SmartPhone. Set the following attributes to values of your choosing: 
      1. hasGPS
      2. hasWIFI
      3. OSVersion 
      4. cell Provider
      5. isFlipPhone
      6. hasInternational
      7. batteryType
      8. Add 1 favorite phone number
    4. Display the SmartPhone toString results.

Deliverables include the SmartPhone.java and TestPhone.java files.

There is no defined constructors in the CellPhone class so the super() method does not need to be addressed.

Tags: No tags