我是Java的初学者,但是我很难理解为什么我的“ Inflate”和“ getVolume”方法不起作用。我确定它们只是简单的问题,但我仍然需要一些帮助,以便我可以修复自己的代码并加以改进!
import java.util.Scanner;
public class Balloon
{
public static void main(String[] args)
{
Scanner multiplier = new Scanner(System.in);
System.out.println("How much should the radius be increased by? ");
double amount = multiplier.nextDouble();
double radius = 0;
public void Inflate(double amount);
{
double newRadius = radius + amount;
}
public double getVolume();
{
double sVolume = (4/3)*Math.PI*(newRadius*newRadius*newRadius);
System.out.print(sVolume);
}
}
}
答案 0 :(得分:0)
我想Ballon是可以膨胀的物体,并且具有一定的半径状态,而且可以获取体积。
这里的主要方法只是测试气球是否正常工作
public class Balloon {
private double radius = 0;
public static void main(String[] args) {
Scanner multiplier = new Scanner(System.in);
System.out.println("How much should the radius be increased by? ");
Balloon balloon=new Balloon();
double amount = multiplier.nextDouble();
balloon.inflate(amount);
double volume = balloon.getVolume();
System.out.print(volume);
}
public void inflate(double amount) {
radius = radius + amount;
}
public double getVolume() {
double sVolume = (4 / 3) * Math.PI * (Math.pow(radius, 3));
return sVolume;
}
}