This repository has been archived by the owner on Nov 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
returnFunctionsComplex.java
56 lines (52 loc) · 1.35 KB
/
returnFunctionsComplex.java
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
/*
Lesson _05
In this lesson we will expand our knowledge on how we can use return functions in java
In this example, we will use return functions to heat/cool objects
*/
/*
* @author Surya
*/
public class returnFunctionsComplex
{
public static void main(String[]args)
{
System.out.println("This program is used to calculate the number of minutes it requires to heat/cool an object.");
double rate = 2; //degrees per minute
double currentTemp = 111;
double requiredTemp = 91;
if(requiredTemp>currentTemp)
{
System.out.println(Heater(currentTemp, requiredTemp, rate));
}
else if(requiredTemp<currentTemp)
{
System.out.println(Cooler(currentTemp, requiredTemp, rate));
}
else
{
System.out.println("They are literally the same temperature. Nothing to cool or heat");
}
}
//This function heats the object
static String Heater(double initialTemp, double finalTemp, double rate)
{
int time =0; //in minutes
while(initialTemp<finalTemp)
{
initialTemp+=rate;
time++;
}
return "It took " + time + " minutes in order to heat the object.";
}
//This function cools the object
static String Cooler(double initialTemp, double finalTemp, double rate)
{
int time =0; //in minutes
while(initialTemp>finalTemp)
{
initialTemp-=rate;
time++;
}
return "It took " + time + " minutes in order to cool the object.";
}
}