我有一个赋值,我需要使用抽象类号来使用类Number中的方法打印出值。
以下是给出的代码,我只需要使用这些方法来打印PI值:
public class Pi extends Number {
public static double PI = 3.14159265358979323846264338327950;
private int intValue; // PI rounded down to nearest int
private long longValue; // PI rounded up to nearest int
private float floatValue; // PI as type float
private double doubleValue; // PI as defined
/*
* TBI (To Be Implemented)
* The constructor assigns values to all of the instance
* variables defined above. The values that are assigned
* to the instance variables are documented using comments
* when the instance variables are defined.
*/
public Pi() {
// the expressions on the right side of each of the following
// assignment statements must use PI in them...
intValue = ;
longValue = ;
floatValue = ;
doubleValue = ;
}
/*
* TBI (To Be Implemented)
* Returns a String representation of this Pi object
* that is used as the output of this progam.
*/
public String toString() {
}
/*
* The following methods cannot be modified/deleted.
*/
public static void main(String[] argv) {
System.out.println(new Pi());
}
public double getPi() { return doubleValue; }
}
/*
* the output of the program must look something like the following
*
byteValue(): 3
shortValue(): 3
intValue(): 3
longValue(): 4
floatValue(): 3.1415927
doubleValue(): 3.141592653589793
*
*/
我只是很难开始这个。我不希望任何人为你做这个程序,只是帮助我开始,以及如何实现构造函数和方法。
答案 0 :(得分:1)
非抽象Pi
类扩展了抽象Number类,它有4个抽象方法。因此,Pi
类必须实现这4个抽象方法。此外,您必须在提供的To Be Implemented
框架代码中实现标记为Pi
的代码,并确保您的实现返回预期的输出。