+1 (315) 557-6473 

Program To Create Various Classes Using Concepts of Inheritance in C Assignment Solution.


Instructions

Objective
Write a C homework program to create various classes using concepts of inheritance.

Requirements and Specifications

  1. Use the included CellPhone class for this assignment. The CellPhone class should not be modified.
    1. Create a class named SmartPhone. Modify this class to extend (inherit) the provided CellPhone class.
      1.  Include the main() method
    2. Add the following data items to the SmartPhone.
      1. boolean HasWIFI - Default to false
      2.  boolean HasGPS - Default to false
      3. boolean hasSMS - Default to true
      4. boolean readTextMessagesWhenDelivered - Default to false;
      5. String OSVersion - Default to "Windows 10 Mobile";
      6. long internalMemoryStorageCapacity - Default to 32_000_000_000L;
    3. Generate a toString() method for this class. Create Getters and Setters for the data items in Step 3.
      1. Select "Inherit Methods" to include the superclass methods.
    4. In the main() method in SmartPhone- do the following:
    1. Create an instance of the SmartPhoneclass
      1. i.e., SmartPhone mySmartPhone = new SmartPhone();
    2. Using the instance of the SmartPhone, explicitly set the following data to values of your choosing:
      1. All the items in Step 2.
      2.  isFlipPhone
      3.  hasInternational
      4.  cellProvider
      5. Add 2 ten digit phone numbers to the phoneNumber ArrayList.
      1. You will need to include a trailing L in a literal number.
      2. Use System.out.println and directly or indirectly call your toString method.

      Set the Battery Type to a valid battery type as specified in the CellPhone class as part of Step 5b.

    3. 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)

      You can choose one of the topics/subclasses listed above or use your own.

      1. Create your class that will be treated as the base class. It must have at least 4 data items (also called attributes).
        1. Generate getters and setters for these data items.
      2. 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.
        1. Generate getters and setters for these data items.
      3. In the main() method in your subclass
        1. Create an instance of your subclass
        2. Set all the data items for this subclass, including inherited data items
        3. Display the result of the toString() method via System.out.println.
      4. Both classes needed to be named with meaningful names - not SuperClass or SubClass
    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 AVAILABLE_BATTERY_TYPES;
        private ArrayList phoneNumbers;
        private String cellProvider;
        private String batteryType;
        private boolean isFlipPhone;
        private boolean hasInternational;
        public CellPhone() {
            this.AVAILABLE_BATTERY_TYPES = new ArrayList(Arrays.asList("NiCd", "NiMH", "Lo-ion", "Li-pol"));
            this.phoneNumbers = new ArrayList();
            this.cellProvider = "AT&T";
            this.batteryType = null;
            this.isFlipPhone = false;
            this.hasInternational = false;
        }
        public ArrayList 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 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);
        }
    }