如何让这位辅导员展示答案?我有一个调用程序,它使用mutator来设置变量

时间:2013-10-01 07:22:07

标签: java

我尝试运行我的代码,每次我做Aquarius Facilitator都会显示0.000。它与int和double有什么关系,因为我的变量和int导致我对trunkaid的回答?谢谢你的帮助

这是我的程序

public class JRambolus
{
public JRambolus(){}
public JRambolus(double A)
{
    Lengtus = A;
}
public JRambolus(double A, int B)
{
    Lengtus = A;
    Actus   = B;
}
    //mutator
void SetLengtus( double A )
{
    Lengtus = A;
}
    //mutator
void SetActus(int A)
{
    Actus = A;
}
    //accessor 
double GetLengtus()
{
    return Lengtus;
}
    //accessor 
int GetActus()
{
    return Actus;
}
//Facilitator
double Arius()
{ 
    return 3*Lengtus+(1/2*Actus);
}
double Aquarius()
{
    return 4/3*((1/2*Lengtus)+(2/5*Actus));
}
double Nebulus()
{
    return (Math.pow(Lengtus,2)+Math.pow(Actus,3/2))*4/3;
}

//Memeber Varibales
private double Lengtus;
private int Actus;
  }

这是我的通话程序

public class JShower
{
  public static void main(String[] args)
  {

    JRambolus FullRambolus = new JRambolus();

    //Calling out the the system
    System.out.printf("%43s %4s %8.3f%n"    ,"The Arius of FullRambolus is"   ,"=", FullRambolus.   Arius() );
    System.out.printf("%46s %s %8.3f%n"     ,"The Aquarius of FullRambolus is","=", FullRambolus.Aquarius() );
    System.out.printf("%45s %2s %8.3f%n%n%n","The Lengtus of FullRambolus is" ,"=", FullRambolus.Nebulus () );






    JRambolus DefaultRambolus  = new JRambolus();
    //Calling the Mutator From JRambolus
    DefaultRambolus.SetLengtus(6);
    DefaultRambolus.SetActus(3);




    //Calling out to the system
    System.out.printf("%46s %4s %8.3f%n","The Arius of DefaultRambolus is"   ,"=", DefaultRambolus.   Arius() );
    System.out.printf("%49s %s %8.3f%n" ,"The Aquarius of DefaultRambolus is","=", DefaultRambolus.Aquarius() );
    System.out.printf("%48s %2s %8.3f%n","The Nebulus of DefaultRambolus is" ,"=", DefaultRambolus.Nebulus () );




    }
}

2 个答案:

答案 0 :(得分:0)

返回该值。看看here,看看它们如何处理变量的打印/显示。

答案 1 :(得分:0)

您正在将整数除法与双精度混合,这可能会导致未执行的结果。

声明应为

return 4d/3d*((1d/2d*Lengtus)+(2d/5d*Actus));

在原始陈述中,使用整数除法计算4/3,得到值1。更重要的是,1/2(结果:0)和2/5(也为零)的返回值为0.0D