9. Consider the following incomplete Fraction class. The relevant portions of th
ID: 3717725 • Letter: 9
Question
9. Consider the following incomplete Fraction class. The relevant portions of the class are given below. Fill in the blank in the class header to make each Fraction object Comparable. Also, fill in the compareTo method such that fractions are compared according to their toDouble values. public class Fraction private long numerator; private long denominator; public double toDouble0 return numerator / (double) denominator; public int compareTo(Fraction other) // FILL IN 10. Provide a code fragment that declares and creates an ArrayList of strings, as well as adds the elements "a", "b", and "c" to the list. 12. Suppose that a classmate has written the following method. public static void increment(int i) f She is surprised by the output of the following code fragment. int x = 5; increment (x); System.out.println(x); Discuss what is printed and why, as well as how to fix your classmate's code to match the intent.Explanation / Answer
Hi, I have answerd Q12.
Please repost others in separate post.
Output: 5, because in function increment, x is being passed by value, so any change inside increment function will not affect then original value of x.
Fixed code:
public static int increment(int i) {
i = i + 1;
return i;
}
int x = 5;
x = increment(x);
System.out.println(x);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.