Java Java CISC 3120 CUNY Brooklyn College 1. In the two code snippets below, whi
ID: 3731861 • Letter: J
Question
Java Java CISC 3120 CUNY Brooklyn College 1. In the two code snippets below, which case is of the "composition pattern, and which "inheri tance"? Case 1 public class Thermostat I private Temperat ureSensor sensor public Thermostat ) I sensor = new TemperatureSensor ("Nest"); publie double getFarenheit O return sensor.measure ) toFarenheit O Case 2 public elass Thermostat extends TemperatureSeasor publie Termostat (String mansfacturer) super manufacturer //somE code below represented b private Temperature measure) Temperaturenew Temperature) /soNE code below, represented by... return t; public double getFarenheit return measure) toFarenbeit 2. The following code has at least two major errors. What are they? Suggest a way to fix it publie elass Sensor public abstract Temperature measure) //some correct code below, represented by public static void main (String args) Sensor sensor- new Sessor // some correct code below, represented b9 3. Write an interface, PointingDevice, containing e an abstract method, getXCoord that returns an int e an abs e an abstract method, attentionRequired that returns a boolean ean abstract method, set Resolution that accepts a double and returns a double tract method, getYCoord tha t returns an intExplanation / Answer
Question 1:Composition Pattern/Inheritance Pattern
Case 1 is Composition Pattern
Case 2 is Inheritance Pattern
Question 2: Major Errors
-The Class Sensor must be an abstract class to define abstract methods
- Abstract methods do not specify a body
- Temperature cannot be resolved to a type
Question 3: Interface PointingDevice
public interface PointingDevice {
public abstract int getXCoord();
public abstract int getYCoord();
public abstract boolean attentionRequired();
public abstract Double setResolution(Double res);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.