/* this is the class program needed so I can run NumberAnonTesterPrac program be
ID: 3556663 • Letter: #
Question
/* this is the class program needed so I can run NumberAnonTesterPrac program below. The questions are all the way down.
public class NumberAnonPrac {
private double value;
public NumberAnonPrac(double value) { this.value = value;}
public NumberAnonPrac() { this.value = 0; }
public double a(double x) { return value += x; }
public double b(double x) { return value -= x; }
public double c(double x) { return value *= x; }
public double d(double x) { return value /= x; }
public double e() { return value; }
public void f(double value) { this.value = value; }
public double g() { return value = value*value; }
}
/* thiis is the program that needs to be run.
public class NumberAnonTesterPrac {
public static void main(String [] args) {
NumberAnonPrac number = new NumberAnonPrac();
System.out.printf("%.1f ", number.b(-2.2));
System.out.printf("%.1f ", number.c(3));
System.out.printf("%.1f ", number.d(1.5));
System.out.printf("%.1f ", number.b(1.1));
number.f(6);
System.out.printf("%.1f ", number.g());
System.out.printf("%.1f ", number.e());
number = new NumberAnonPrac(7);
System.out.printf("%.1f ", number.e());
System.out.printf("%.1f ", number.a(4.4));
}
}
/* this are the answers when NumberAnonTesterPrac program is run.
2.2
6.6
4.4
3.3
36.0
36.0
7.0
11.4
Write a constructor for the class in the previous question that takes two double arguments and initializes value to the larger of the two.
write a void instance method called n, for the class referenced in the previous question that changes value to be the negative of its current value.
Explanation / Answer
Constructor :
public double NumberAnonPrac(double value1,double value2)
{
if(value1>value2)
this.value=value1;
else this.value= value2;
}
Method n :
public void n()
{
this.value= (this.value * -1);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.