-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeater.java
More file actions
112 lines (96 loc) · 2.79 KB
/
Heater.java
File metadata and controls
112 lines (96 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* A Heater models a simple space-heater. The operations provided by a Heater
* object are:
* 1. Increase and decrease the temperature setting by a set amount.
* 2. Return the current temperature setting.
* 3. Change the set amount by which the temperature is increased and lowered.
*
* @author L.S. Marshall, SCE, Carleton University
* (incomplete implementation for SYSC 2004 Lab 2)
* @author Kalid Wehbe
* @version 1.03 January 17th, 2024
*/
public class Heater
{
/** The temperature setting that the heater should maintain. */
private int temperature;
/** The temperature setting for a newly created heater. */
private static final int INITIAL_TEMPERATURE = 15;
/**
* The amount by which the temperature setting is raised/lowered when
* warmer() and cooler() are invoked.
*/
private int increment;
/**
* The default amount by which the temperature setting is
* increased when warmer() is invoked and decreased when cooler()
* is invoked.
*/
private static final int DEFAULT_INCREMENT = 5;
/**
* The default max and min values set for the temperature range
*/
private static final int MAX_TEMP = 100;
private static final int MIN_TEMP = 0;
/**
* max and min temperature of the heater
*/
private int max;
private int min;
/**
* Constructs a new Heater with an initial temperature setting of 15
* degrees, and which increments and decrements the temperature
* setting in increments of 5 degrees.
*/
public Heater()
{
temperature = INITIAL_TEMPERATURE;
increment = DEFAULT_INCREMENT;
min = MIN_TEMP;
max = MAX_TEMP;
}
/**
* construct with parameters that will be the values for max and min
*/
public Heater(int minTemp, int maxTemp)
{
temperature = INITIAL_TEMPERATURE;
increment = DEFAULT_INCREMENT;
min = minTemp;
max = maxTemp;
}
/**
* Returns the heaters current temperature.
*/
public int temperature()
{
return temperature;
}
/**
* Increase the heater by a the value in increment
*/
public void warmer()
{
if (max >= temperature + increment){
temperature = temperature + increment;
}
}
/**
* Decrease the heater by the value in increment
*/
public void cooler()
{
if (min <= temperature - increment){
temperature = temperature - increment;
}
}
/**
* Sets up a new increment for changing the temperature
*/
public void setIncrement(int newIncrement)
{
if (newIncrement > 0 ){
increment = newIncrement;
}
}
}