Instructions
Objective
Write a program to create various classes using concepts of inheritance in C language.
Requirements and Specifications
- Use the included CellPhone class for this assignment. The CellPhone class should not be modified.
- Create a class named SmartPhone. Modify this class to extend (inherit) the provided CellPhone class.
- Include the main() method
- Add the following data items to the SmartPhone.
- boolean HasWIFI - Default to false
- boolean HasGPS - Default to false
- boolean hasSMS - Default to true
- boolean readTextMessagesWhenDelivered - Default to false;
- String OSVersion - Default to "Windows 10 Mobile";
- long internalMemoryStorageCapacity - Default to 32_000_000_000L;
- Generate a toString() method for this class. Create Getters and Setters for the data items in Step 3.
- Select "Inherit Methods" to include the superclass methods.
- In the main() method in SmartPhone- do the following:
- Create an instance of the SmartPhoneclass
- i.e., SmartPhone mySmartPhone = new SmartPhone();
- Using the instance of the SmartPhone, explicitly set the following data to values of your choosing:
- All the items in Step 2.
- isFlipPhone
- hasInternational
- cellProvider
- Add 2 ten digit phone numbers to the phoneNumber ArrayList.
- You will need to include a trailing L in a literal number.
- Use System.out.println and directly or indirectly call your toString method.
- Create your own base class and a 2nd class that extends this class. Consider the following as base classes that could be extended:
- Musical Instrument ( subclass as trumpet, piano, drum, etc)
- Boat ( subclass as bass boat, cargo, ferry, speed)
- Business ( subclass as service, product, etc)
- Timekeeper ( subclass as atomic, battery, spring, etc)
- Cake ( subclass as birthday, wedding, etc)
- Television ( subclass as LCD, plasma, projection, etc)
- Create your class that will be treated as the base class. It must have at least 4 data items (also called attributes).
- Generate getters and setters for these data items.
- Create a subclass that includes a main() method and inherit the base class. Add at least 4 data items Create a toString method in your subclass that also refers to the inherited methods.
- Generate getters and setters for these data items.
- In the main() method in your subclass
- Create an instance of your subclass
- Set all the data items for this subclass, including inherited data items
- Display the result of the toString() method via System.out.println.
- Both classes needed to be named with meaningful names - not SuperClass or SubClass
Set the Battery Type to a valid battery type as specified in the CellPhone class as part of Step 5b.
You can choose one of the topics/subclasses listed above or use your own.
Source Code
BIRTHDAY CAKE
//
// Decompiled by Procyon v0.5.36
//
public class BirthdayCake extends Cake
{
private String name;
private int birthdayDay;
private int birthdayMonth;
private int birthdayYear;
public BirthdayCake() {
this.name = "Jack";
this.birthdayDay = 1;
this.birthdayMonth = 1;
this.birthdayYear = 2000;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
public int getBirthdayDay() {
return this.birthdayDay;
}
public void setBirthdayDay(final int birthdayDay) {
this.birthdayDay = birthdayDay;
}
public int getBirthdayMonth() {
return this.birthdayMonth;
}
public void setBirthdayMonth(final int birthdayMonth) {
this.birthdayMonth = birthdayMonth;
}
public int getBirthdayYear() {
return this.birthdayYear;
}
public void setBirthdayYear(final int birthdayYear) {
this.birthdayYear = birthdayYear;
}
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("BirthdayCake [height=");
builder.append(this.getHeight());
builder.append(", diameter=");
builder.append(this.getDiameter());
builder.append(", shape=");
builder.append(this.getShape());
builder.append(", taste=");
builder.append(this.getTaste());
builder.append(", name=");
builder.append(this.name);
builder.append(", birthdayDay=");
builder.append(this.birthdayDay);
builder.append(", birthdayMonth=");
builder.append(this.birthdayMonth);
builder.append(", birthdayYear=");
builder.append(this.birthdayYear);
builder.append("]");
return builder.toString();
}
public static void main(final String[] args) {
final BirthdayCake cake = new BirthdayCake();
cake.setHeight(8.0);
cake.setDiameter(25.0);
cake.setShape("Square");
cake.setTaste("Fruit");
cake.setName("Tom");
cake.setBirthdayDay(23);
cake.setBirthdayMonth(3);
cake.setBirthdayYear(2002);
System.out.println(cake);
}
}
CELL PHONE
import java.util.Collection;
import java.util.Arrays;
import java.util.ArrayList;
//
// Decompiled by Procyon v0.5.36
//
public class CellPhone
{
private final ArrayList<String> AVAILABLE_BATTERY_TYPES;
private ArrayList<Long> phoneNumbers;
private String cellProvider;
private String batteryType;
private boolean isFlipPhone;
private boolean hasInternational;
public CellPhone() {
this.AVAILABLE_BATTERY_TYPES = new ArrayList<String>(Arrays.asList("NiCd", "NiMH", "Lo-ion", "Li-pol"));
this.phoneNumbers = new ArrayList<Long>();
this.cellProvider = "AT&T";
this.batteryType = null;
this.isFlipPhone = false;
this.hasInternational = false;
}
public ArrayList<Long> getPhoneNumbers() {
return this.phoneNumbers;
}
public void addAPhoneNumber(final Long phoneNumber) {
this.phoneNumbers.add(phoneNumber);
}
public void deleteAPhoneNumber(final int phoneNumber) {
this.phoneNumbers.remove(phoneNumber);
}
public String getCellProvider() {
return this.cellProvider;
}
public void setCellProvider(final String cellProvider) {
this.cellProvider = cellProvider;
}
public String getBatteryType() {
return this.batteryType;
}
public boolean setBatteryType(final String batteryType) {
if (this.AVAILABLE_BATTERY_TYPES.contains(batteryType)) {
this.batteryType = batteryType;
return true;
}
return false;
}
public boolean isFlipPhone() {
return this.isFlipPhone;
}
public void setFlipPhone(final boolean isFlipPhone) {
this.isFlipPhone = isFlipPhone;
}
public boolean isHasInternational() {
return this.hasInternational;
}
public void setHasInternational(final boolean hasInternational) {
this.hasInternational = hasInternational;
}
public ArrayList<String> getAVAILABLE_BATTERY_TYPES() {
return this.AVAILABLE_BATTERY_TYPES;
}
public boolean isValidBatteryType() {
return this.batteryType != null;
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("CellPhone [phoneNumbers=");
builder.append(this.phoneNumbers);
builder.append(", cellProvider=");
builder.append(this.cellProvider);
builder.append(", batteryType=");
builder.append(this.batteryType);
builder.append(", isFlipPhone=");
builder.append(this.isFlipPhone);
builder.append(", hasInternational=");
builder.append(this.hasInternational);
builder.append(", valid battery type=");
builder.append(this.isValidBatteryType());
builder.append("]");
return builder.toString();
}
}
SMART PHONE
//
// Decompiled by Procyon v0.5.36
//
public class SmartPhone extends CellPhone
{
private boolean hasWIFI;
private boolean hasGPS;
private boolean hasSMS;
private boolean readTextMessagesWhenDelivered;
private String OSVersion;
private long internalMemoryStorageCapacity;
public SmartPhone() {
this.hasWIFI = false;
this.hasGPS = false;
this.hasSMS = true;
this.readTextMessagesWhenDelivered = false;
this.OSVersion = "Windows 10 Mobile";
this.internalMemoryStorageCapacity = 32000000000L;
}
public boolean isHasWIFI() {
return this.hasWIFI;
}
public void setHasWIFI(final boolean hasWIFI) {
this.hasWIFI = hasWIFI;
}
public boolean isHasGPS() {
return this.hasGPS;
}
public void setHasGPS(final boolean hasGPS) {
this.hasGPS = hasGPS;
}
public boolean isHasSMS() {
return this.hasSMS;
}
public void setHasSMS(final boolean hasSMS) {
this.hasSMS = hasSMS;
}
public boolean isReadTextMessagesWhenDelivered() {
return this.readTextMessagesWhenDelivered;
}
public void setReadTextMessagesWhenDelivered(final boolean readTextMessagesWhenDelivered) {
this.readTextMessagesWhenDelivered = readTextMessagesWhenDelivered;
}
public String getOSVersion() {
return this.OSVersion;
}
public void setOSVersion(final String OSVersion) {
this.OSVersion = OSVersion;
}
public long getInternalMemoryStorageCapacity() {
return this.internalMemoryStorageCapacity;
}
public void setInternalMemoryStorageCapacity(final long internalMemoryStorageCapacity) {
this.internalMemoryStorageCapacity = internalMemoryStorageCapacity;
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("SmartPhone [phoneNumbers=");
builder.append(this.getPhoneNumbers());
builder.append(", cellProvider=");
builder.append(this.getCellProvider());
builder.append(", batteryType=");
builder.append(this.getBatteryType());
builder.append(", isFlipPhone=");
builder.append(this.isFlipPhone());
builder.append(", hasInternational=");
builder.append(this.isHasInternational());
builder.append(", valid battery type=");
builder.append(this.isValidBatteryType());
builder.append(", hasWIFI=");
builder.append(this.hasWIFI);
builder.append(", hasGPS=");
builder.append(this.hasGPS);
builder.append(", hasSMS=");
builder.append(this.hasSMS);
builder.append(", readTextMessagesWhenDelivered=");
builder.append(this.readTextMessagesWhenDelivered);
builder.append(", OSVersion=");
builder.append(this.OSVersion);
builder.append(", internalMemoryStorageCapacity=");
builder.append(this.internalMemoryStorageCapacity);
builder.append("]");
return builder.toString();
}
public static void main(final String[] args) {
final SmartPhone smartPhone = new SmartPhone();
smartPhone.setHasWIFI(true);
smartPhone.setHasGPS(true);
smartPhone.setHasSMS(false);
smartPhone.setReadTextMessagesWhenDelivered(true);
smartPhone.setOSVersion("IOS 12");
smartPhone.setInternalMemoryStorageCapacity(64000000000L);
smartPhone.setFlipPhone(true);
smartPhone.setHasInternational(true);
smartPhone.setCellProvider("T-Mobile");
smartPhone.addAPhoneNumber(9998887766L);
smartPhone.addAPhoneNumber(5554443322L);
smartPhone.setBatteryType("NiMH");
System.out.println(smartPhone);
}
}