这是我现在的代码:
import java.util.Scanner;
import java.util.*;
import java.io.File;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
public class IceCreamData
{
// method to calculation volume
public static void printCylinderVolume(double cylinderRadius, double cylinderHeight){
double cylinderVolume = Math.PI * Math.pow(cylinderRadius, 2) * cylinderHeight;
return cylinderVolume;
}
// method to calculate number of ice cream scoops
public static double printNumScoops(double cylinderVolume){
double numScoops = (cylinderVolume * 0.004329) * 30;
System.out.println("The number of scoops is " + cylinderVolume);
}
// the main method
public static double main(String[] args) throws FileNotFoundException, IOException
{
//input the file and scanner and output file
File input = new File("project4Data.txt");
Scanner in = new Scanner(input);
PrintWriter out = new PrintWriter("scoopResults.txt");
//declaring variables outside of while-loop in order to run
String iceName; // name of the ice cream
double cylinderRadius; // cylider radius
double cylinderHeight; // cylinder height
int expirationYear; // expiration year
我试图将柱面体积从 printCylinderVolume 方法返回到 main 方法,以便我可以在 printNumScoops 方法中使用它。现在我收到一条错误消息,指出圆柱体积是一个意外的返回值,另一个错误表明 printNumScoops 方法找不到圆柱体积。气缸体积是否在正确的位置初始化/声明,是否需要以不同的方式返回/存储在主方法中才能工作?
人到中年有点甜
心有法竹
相关分类