PK Ֆ}1K Wednesday/TV.javapackage Wednesday; public abstract class TV { private static final int DIAGONAL_LENGTH = 10; private static final String BRAND = "cmsc131"; private int diagonalLength; private String brand; private int channelNum; /* Relying on the general constructor to implement the */ /* the following two constructors. */ public TV() { this(DIAGONAL_LENGTH, BRAND); } public TV(String brand) { this(DIAGONAL_LENGTH, brand); } /* Most general Constructor */ public TV(int diagonalLength, String brand) { this.diagonalLength = diagonalLength; this.brand = brand; channelNum = 1; } public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public int getDiagonalLength() { return diagonalLength; } public void setDiagonalLength(int diagonalLength) { this.diagonalLength = diagonalLength; } public String toString() { return "Brand: " + brand + ", Diagonal Length: " + diagonalLength; } /* Notice this method calls an abstract method */ /* to be implemented by a subclass. */ public void changeChannel(int channelNum) { this.channelNum = channelNum; processAndDisplaySignal(); } public int changeChannel(double channelNum) { return 1; } /* Can we defined the access specifier to be private? */ protected abstract void processAndDisplaySignal(); public static void main(String[] args) { /* Are the two following statements allowed? */ /*TV tvSet1 = new TV(); System.out.println(tvSet1);*/ } } PK ͑}1q}**Wednesday/ConventionalTV.javapackage Wednesday; public class ConventionalTV extends TV { private static final String DEFAULT_CATHODE_RAY_TUBE = "A"; private String cathodeRayTubeType; public ConventionalTV() { super(20, "GEConv"); cathodeRayTubeType = DEFAULT_CATHODE_RAY_TUBE; } public ConventionalTV(String cathodeRayTubeType) { super(30, "GEConvSpec"); this.cathodeRayTubeType = cathodeRayTubeType; } public ConventionalTV(int diagonalLength, String brand, String cathodeRayTubeType) { super(diagonalLength, brand); this.cathodeRayTubeType = cathodeRayTubeType; } /* Implementation of abstract method */ protected void processAndDisplaySignal() { System.out.println("Processing and Displaying conventional TV signal."); } public String toString() { return super.toString() + ", Cathode Ray Tube Type: " + cathodeRayTubeType; } public static void main(String[] args) { ConventionalTV tvSet1= new ConventionalTV(); ConventionalTV tvSet2 = new ConventionalTV(32, "GE", "B"); System.out.println(tvSet1); System.out.println(tvSet2); } } PK ڋ}1k8""Wednesday/ValidInvalid.javapackage Wednesday; public class ValidInvalid { public static void main(String[] args) { /* The following three declarations are correct */ TV tv1 = new ConventionalTV(); TV tv2 = new HighDefTV(); HighDefTV high1 = new HighDefTV(); /* Which of the following statements are valid? */ /* Notice that some of these statements may not compile */ /* HighDefTV high2 = new ConventionalTV(); HighDefTV high3 = new TV(); ConventionalTV conv1 = new ConventionalTV(); System.out.println(conv1.super.toString()); HighDefTV high4 = (HighDefTV)tv2; ConventionalTV conv2 = (ConventionalTV)tv2; TV tv3 = new TV(); TV tv4 = high1; tv4.getDigitalConverter(); tv4.changeChannel(4); tv4.toString(50); tv4.processAndDisplaySignal(); */ } } PK }1hf|Wednesday/HighDefTV.javapackage Wednesday; public class HighDefTV extends TV { private static String DIGITAL_CONVERTER = "1280DPI"; private String digitalConverter; public HighDefTV() { super(); // We don't need it. Why??? digitalConverter = DIGITAL_CONVERTER; } /* Calls super class constructor by using super */ public HighDefTV(int diagonalLength, String brand, String digitalConverter) { super(diagonalLength, brand); this.digitalConverter = digitalConverter; } public String getDigitalConverter() { return digitalConverter; } /* overrides toString and calls the toString method of the superclass */ public String toString() { return super.toString() + ", Digital Converter: " + digitalConverter; } /* overloads toString and uses the other toString() to generate result */ public String toString(int indentation) { String result =""; for (int i=0; i