// Recording weather information with a superclass (version~3) // fig:recordings-super4 abstract class ARecording { int high; int today; int low; ARecording(int high,int today,int low) { this.high = high; this.today = today; this.low = low; } int dHigh() { return this. high - this. today; } int dLow() { return this. today - this. low; } String asString() { return String.valueOf(high).concat("-").concat(String.valueOf(low)).concat(this.unit()); } abstract String unit(); } class Temperature extends ARecording { Temperature(int high,int today,int low) { super(high,today,low); } String unit() { return "F"; } } class Pressure extends ARecording { Pressure(int high,int today,int low) { super(high,today,low); } String unit() { return "hPa"; } } class Examples { Pressure p1 = new Pressure(103289, 101325, 95839); Pressure p2 = new Pressure(102389, 102325, 100839); Temperature t1 = new Temperature(82, 78, 67); Temperature t2 = new Temperature(57, 48, 32); // tests for the method dHigh boolean testDHigh1 = p1.dHigh() == 1964; boolean testDHigh2 = p2.dHigh() == 64; boolean testDHigh3 = t1.dHigh() == 4; boolean testDHigh4 = t2.dHigh() == 9; // tests for the method dLow boolean testDLow1 = p1.dLow() == 5486; boolean testDLow2 = p2.dLow() == 1486; boolean testDLow3 = t1.dLow() == 11; boolean testDLow4 = t2.dLow() == 16; // test the method asString boolean testAsString1 = p1.asString().equals("103289-95839hPa"); boolean testAsString2 = p2.asString().equals("102389-100839hPa"); boolean testAsString3 = t1.asString().equals("82-67F"); boolean testAsString4 = t2.asString().equals("57-32F"); }