传递方法信息

时间:2014-11-30 20:25:53

标签: java

任何人都可以帮我解决这个问题吗?

import java.util.*;
         public class PaintCalculator
          {
            public static void main(String[] args)
            {
              double length;
              double width;
              double height;

              Scanner input = new Scanner(System.in);

              System.out.print("Enter the length in feet: ");   
               length = input.nextDouble();
              System.out.print("Enter the width in feet: ");    
               width = input.nextDouble();
              System.out.print("Enter the height in feet: ");   
               height = input.nextDouble();

              System.out.println();
              PtinSqFt(length,width,height);

              System.out.println("The Cost of a " + length + "- by " + width + "-foot room with a  " + height +   "-foot ceilings is " + newAmount + "$");              
           }

      public static double PtinSqFt(double v1, double v2, double v3)
     {
       double GoP = v1*v2*v3;
       double newAmount;
       newAmount = GallonsOfPaint(GoP)*32;       
       System.out.println("The wall area for the room is " + GoP + " Square Feet!");
       System.out.println("You will need " + GallonsOfPaint(GoP) + " gallons of paint!");
       System.out.println("The Cost of a " + v1 + "- by " + v2 + "-foot room with a " + v3 + "-  foot ceilings is " + newAmount + "$");
       return newAmount;
   }



 public static double GallonsOfPaint(double GoP)
     {
     final double SQFT_OF_RM = 350;
     double newgallons = (GoP/SQFT_OF_RM);
     return newgallons;

      } 

 }  

当我尝试从我的PtinSqFt方法中提取返回信息时,它将无法编译?

1 个答案:

答案 0 :(得分:1)

如果您希望稍后在PtinSqFt(length,width,height);语句中使用println,则需要将PtinSqFt(length,width,height); 的返回值存储在变量中。

所以改变这个

double newAmount = PtinSqFt(length,width,height);

{{1}}

它应该有用。