-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplyDiffQuestions.java
139 lines (117 loc) · 4.34 KB
/
ApplyDiffQuestions.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Names: Ishan Garg, Krish Patel, Pranav Mahabal
* Course: MCV4U0-1
* Date: January 18, 2023
* Teacher: Ms Iulia Gugoiu
*
* Generates the applications of differentiation questions.
*/
import java.util.Random;
public class ApplyDiffQuestions {
private double correctAnswer;
private String displayFunction;
private int x;
private int y;
private String question;
private Random rand;
private String[] displayFunctions;
/**
* Class constructor.
*/
public ApplyDiffQuestions() {
correctAnswer = 0.0;
displayFunctions = new String[] {
"sin^2(x)/x^2",
"(1-cos(x))/x^2",
"(sin(x)-x)/x^3",
"((e^x)-1-x)/x^2",
"tan(x)/x"
};
x = 0;
y = 0;
question = "";
rand = new Random();
}
/**
* Generates the balloon volume related rates question.
*/
private void generateQuestion1() {
x = rand.nextInt(30) + 30;
y = rand.nextInt(5) + 1;
correctAnswer = ((double) x) / (((double) (y * y)) * Math.PI);
question = "Air is being pumped into a spherical balloon at a rate of " + x
+ " cm^3/min. Determine the rate at which the radius of the balloon is increasing when its diameter is "
+ y + "cm.";
}
/**
* Generates the L'Hopital question.
*/
private void generateQuestion2() {
int i = rand.nextInt(5) + 0;
displayFunction = displayFunctions[i];
switch (i) {
case 0 -> correctAnswer = 1.0;
case 1 -> correctAnswer = 1.0 / 2.0;
case 2 -> correctAnswer = -1.0 / 6.0;
case 3 -> correctAnswer = 1.0 / 2.0;
case 4 -> correctAnswer = 1.0;
}
displayFunction = displayFunction.replaceAll("Math.", "");
question = "Evaluate the limit of y = " + displayFunction
+ " as x approaches zero.\n\nPlease enter the answer correct to two decimal places.";
}
/**
* Generates the ladder related rates question.
*/
private void generateQuestion3() {
x = rand.nextInt(10) + 5;
y = rand.nextInt(10) + 5;
int z = rand.nextInt(10) + 5;
correctAnswer = Math.sqrt((double) (y * y) + Math.pow((double) (-y * x) / (z), 2));
question = "A ladder is resting on a vertical wall. The foot of the ladder is sliding away at a rate of " + x
+ " m/s and is " + y + "m from the wall. At this moment, the top of the ladder is moving down at a "
+ "rate of " + z + " m/s. Find the length of the ladder.";
}
/**
* Generates the right circular cone optimization question.
*/
private void generateQuestion4() {
int x = rand.nextInt(16) + 5;
correctAnswer = (32.0 * Math.PI * x * x * x) / 81.0;
question = "Find the volume of the largest right circular cone that can be inscribed in a sphere of radius " + x
+ ".";
}
/**
* Generates the square and circle wire optimization question.
*/
private void generateQuestion5() {
int x = 10 * (rand.nextInt(12) + 4);
correctAnswer = (double)x/(Math.PI + 4.0);
question = "A piece of wire " + x + "m long is cut into two pieces. One piece is "
+ "bent into a square and the other is bent into a circle. What is the side length "
+ "of the square so that the total area enclosed by both shapes is a minimum?"
+ "\n\nPlease do not enter in terms of pi.";
}
/**
* Sends correct answer to the main program.
* @return Correct answer
*/
public double getCorrectAns() {
return correctAnswer;
}
/**
* Retrieves which question to generate, then generates and sends it to the main program.
* @param num Question number.
* @return question to be asked.
*/
public String getQuestion(int num) {
switch (num) {
case 100 -> generateQuestion1();
case 200 -> generateQuestion2();
case 300 -> generateQuestion3();
case 400 -> generateQuestion4();
case 500 -> generateQuestion5();
}
return question;
}
}