Computers and Technology

Consider the following Java class. Recall that x instanceof C tells you whether the dynamic type of x is C or a subtype of C.
class Coin {
private double value;
private double weight;
public void setValue(final double value) { this. value = value; }
public double getValue() { return value; }
public double getWeight() { return weight; }
public Coin(final double value, final double weight) {
this. value = value;
this. weight = weight;
}
public boolean equals(final Object that) {
return (that instanceof Coin) &&
(this. weight == ((Coin) that).weight);
}
}
a) TRUE or FALSE: The equals method does not care about the weight of the coin because coins are compared based on their face value.
b) Given the above Coin class, what is the output of the following code?
final Coin n1 = new Coin(0.05, 5.0);
final Coin n2 = new Coin(0.05, 5.1);
System. out. println(n1.equals(n2) + " " + (n1 == n2));
// answer here ->
n2.setWeight(5.0);
System. out. println(n1.equals(n2) + " " + (n1 == n2)); ));

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 05:00, 105001964
Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. after the loop terminates, it prints out, on a line by itself and separated by spaces, the sum of all the even integers read, the sum of all the odd integers read, a count of the number of even integers read, and a count of the number of odd integers read, all separated by at least one space. declare any variables that are needed. assume the availability of a variable, stdin, that references a scanner object associated with standard input. that is, stdin = new scanner(system. in); is given.
Answers: 3
image
Computers and Technology, 22.06.2019 20:40, broang23
Write a program that begins by reading in a series of positive integers on a single line of input and then computes and prints the product of those integers. integers are accepted and multiplied until the user enters an integer less than 1. this final number is not part of the product. then, the program prints the product. if the first entered number is negative or 0, the program must print “bad input.” and terminate immediately. next, the program determines and prints the prime factorization of the product, listing the factors in increasing order. if a prime number is not a factor of the product, then it
Answers: 2
image
Computers and Technology, 24.06.2019 07:30, Isabellawuzhere
Aproject involves many computing systems working together on disjointed task towards a single goal what form of computing would the project be using
Answers: 3
image
Computers and Technology, 24.06.2019 16:50, genyjoannerubiera
Ramp charts are generally created in wordlotusexcelpowerpoint
Answers: 1
Do you know the correct answer?
Consider the following Java class. Recall that x instanceof C tells you whether the dynamic type of...

Questions in other subjects:

Konu
Mathematics, 19.05.2021 07:10