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