Java 基于抽象类号的PI赋值

Java 基于抽象类号的PI赋值,java,methods,Java,Methods,我有一个赋值,在这里我需要使用抽象类编号来使用类编号中的方法打印出值 下面是给出的代码,我只需要使用这些方法来打印PI值: public class Pi extends Number { public static double PI = 3.14159265358979323846264338327950; private int intValue; // PI rounded down to nearest int private long lon

我有一个赋值,在这里我需要使用抽象类编号来使用类编号中的方法打印出值

下面是给出的代码,我只需要使用这些方法来打印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

*
*/

我只是开始这件事有点困难。我不想让任何人为我做这个程序,请帮我开始,以及如何实现构造函数和方法。

非抽象的
Pi
类扩展了抽象类,它有4个抽象方法。因此,
Pi
类必须实现这4个抽象方法。此外,您必须在提供的
Pi
框架代码中实现标记为
的代码,并确保实现返回预期输出。

您的问题是如何将
双精度
转换为
int
?@ScaryWombat我不确定如何开始,我通读了类号,它说构造函数就是public Number()。我怎么把它写进我的代码里。我建议你回去问问我clarification@ScaryWombat好的,谢谢你的解释!