Problem Set 1 - (Basic) Methods & Mathematical Operations
Assigned: January 12, 2026
Due: January 21, 2026 at 11:59 PM EST
Assigned: January 12, 2026
Due: January 21, 2026 at 11:59 PM EST
For each problem, create a class named ProblemX,
where X is the problem number
(e.g., Problem1.java).
Write corresponding JUnit test classes named
ProblemXTest.
Each method must include proper Javadoc comments describing the (1) purpose of the method, (2) parameters, and (3) return value.
Do not round your solutions. For example, do not use
Math.round or float your output to, e.g.,
2 decimal places, unless specified.
You may not use anything beyond Chapter 1.1. This includes but is not limited to:
You may use methods from the Math class, as well as comparison (e.g., <, >, ==) and logical operators (e.g., &&, ||).
Any violation results in a score of 0 on the problem set.
Note 1: This page (and other assignments and materials) use MathML for formatting mathematics. This uses special fonts for mathematics, which usually works but seems to be missing on some computers. The best "check" for this is to look at question 6 below - the "v" should have a subscript "i". If you see that, great! If you don’t see it (e.g., just see a box) then you should investigate how to install MathML fonts (or use a different browser...).
Update 01/14: clarification to Problems 9 with the permitted use of logical OR.
Design the double gigametersToLightDays(double gkm) method, which converts a distance
in gigameters to light days (i.e., the distance that light travels in one day). Light travels
299,792,458 meters per second, and there are 86,400 seconds in a day.
Files to Submit: Problem1.java, Problem1Test.java
Design the double grocery(int a, int b, int o, int g, int p, int c) method, which
receives six integers representing the number of apples, bananas, oranges, grapefruits,
pineapples, and coconuts purchased at a store. Use the following table to compute the total
purchase cost in US dollars.
| Item | Price Per Item |
|---|---|
| Apple | $3.43 |
| Banana | $2.91 |
| Orange | $2.12 |
| Grapefruit | $5.23 |
| Pineapple | $4.36 |
| Coconut | $3.11 |
Files to Submit: Problem2.java, Problem2Test.java
Design the double coneSurfaceArea(double r, double h) method, which computes the
surface area of a cone. The formula is:
\[ A = \pi r \left( r + \sqrt{h^2 + r^2} \right) \]
Files to Submit: Problem3.java, Problem3Test.java
The z-score is a measure of how far a given data point is away from the mean of a normally-distributed sample. In essence, roughly 68% of data falls between z-scores of [−1, 1], roughly 95% falls between [−2, 2], and 99.7% falls between [−3, 3]. This means that extreme outliers have z-scores of either less than −3 or greater than 3.
Design the boolean isExtremeOutlier(double x, double avg, double stddev) method that, when given
a data point $x$, a mean $\mu$, and a standard deviation $\sigma$, computes the corresponding z-score of $x$
and returns whether it is an "extreme" outlier. Use the following formula:
\[ Z = \frac{(x - \mu)}{\sigma} \]
Hint: remember that you cannot use if, switch, or conditional statements.
How can you leverage a Math class method to solve the problem? Remember, you are allowed to use
comparison and logical operators, e.g., < and ||.
Files to Submit: Problem4.java, Problem4Test.java
Design the double lawOfCosines(double a, double b, double th) method that, when given
two side lengths of a triangle $a$, $b$ and the angle between those two sides $\theta$ in degrees,
returns the length of the third side $c$.
\[ c = \sqrt{a^2 + b^2 - 2ab\cos \theta} \]
Files to Submit: Problem5.java, Problem5Test.java
A physics formula for computing object distance displacement is
\[ d = t \cdot v_i + (1/2) \cdot at^2 \]
Design the double distanceTraveled(double vi, double a, double t) method that,
when given these variables as parameters, returns the distance that the object in question traveled.
Files to Submit: Problem6.java, Problem6Test.java
The "square root curve" is a method of scaling grades for an assessment.
The idea is to "curve" a student's grade to a "more meaningful" grade.
For example, suppose a student scores 65/100 on an exam.
Their curved score is \(\sqrt{65}\cdot 10 \approx 8.06 \cdot 10 \approx 80.62\).
Therefore, the student earned 15.06 points from the square root scale.
Design the double squareRootScalePoints(double score, double maxPoints) method that, when given a raw score and the maximum number of points for some assessment, returns the number of points earned from the curve.
For example, squareRootScalePoints(65, 100) returns approximately 15.62, because the student earned an 80.62 after the square root scaling.
If the exam were out of 80 points, i.e., squareRootScalePoints(65, 80), the method would instead return a value that is approximately 7.111.
(Note: this exercise purposefully omits the mathematical details to get you to think about what you're supposed to do!)
Files to Submit: Problem7.java, Problem7Test.java
Design the double billTotal(double t) method, which computes the total for a bill.
The total is the given subtotal $t$, plus 6.75% of $t$ for the tax, and 20% of the taxed total
for the tip.
Files to Submit: Problem8.java, Problem8Test.java
Design the boolean areOddOrSum(int x, int y, int z) method that returns true if $x$
or $y$ are odd, but not both (and not neither), OR if the sum of $x$ and $y$ is equal to $z$.
Hint: you are allowed to use ||, which is a logical operator that returns true if at least one of its operands are true.
Files to Submit: Problem9.java, Problem9Test.java
Design the double angle(double a, double b, double c) method that, when given three
side lengths of a triangle $a$, $b$, and $c$, returns the angle $\theta$ opposite to that of $c$
in degrees.
\[ \theta = \cos^{-1}\left(\frac{a^2 + b^2 - c^2}{2ab}\right) \]
Files to Submit: Problem10.java, Problem10Test.java