Java 实际参数列表和形式参数列表的长度不同

Java 实际参数列表和形式参数列表的长度不同,java,Java,我不断得到建造师largeCylinder=新圆柱体标签、高度、半径;与我的类中设置的参数不同 主要问题: import java.util.Scanner; public class CylinderApp { public static void main(String[] args) { //////////////////////////////////////// String label; double radius, height;

我不断得到建造师largeCylinder=新圆柱体标签、高度、半径;与我的类中设置的参数不同

主要问题:

import java.util.Scanner;
public class CylinderApp {
   public static void main(String[] args) {
   ////////////////////////////////////////
      String label;
      double radius, height;
      Scanner scanz = new Scanner(System.in);
   ///////////////////////////////////////
      Cylinder largeCylinder;
   ///////////////////////////////////////
      System.out.println("Enter label, radius, and height for a cylinder.");
      System.out.print("label: ");
      label = scanz.nextLine();
      System.out.print("radius: ");
      radius = Double.parseDouble(scanz.nextLine());
      System.out.print("height: ");
      height = Double.parseDouble(scanz.nextLine());
   /////////////////////////////////
     largeCylinder = new Cylinder(label, height, radius);
     System.out.println(largeCylinder);
   }
}
气缸等级:

import java.text.DecimalFormat;
/* amazing.
*/
public class Cylinder {
/* amazing.
*/
   private String label;
   private double height; /* height of cylinder. */
   private double radius; /* radius of cylinder. */
   public static final double PI = Math.PI; /*constant Pi. */
   private double diameter;
   private double circumference;
   private double area; 
   private double volume;
   private DecimalFormat df = new DecimalFormat("#,##0.0##");

////////////////////////////////////////
 public boolean setLabel(String labelIn){
 if (label == null)
      {
         return false;
      }
      else
      {
         label = labelIn;
         label = label.trim();
         return true;
      }
   }
 public String getLabel() {
      return label;
   }
   public void setHeight(double heightIn) {
      height = heightIn;
   }
   public double getHeight() {
      return height;
   }
   public void setRadius(double radiusIn) {
      radius = radiusIn;
   }
   public double getRadius() {
      return radius;
   }
   public double diameter() {
      return radius * 2;
   }
   public double circumference() {
      return 2 * PI * getRadius();
   }
   public double area() {
      return ((2 * PI * radius * height) + (2 * PI * Math.pow(radius, 2))); 
   }
   public double volume() {
      return PI * Math.pow(radius, 2) * height;
   }


   /////////////////////////////////////

   /////////////////////////////////////
   public String toString() {
      return "\n" + "\"" + getLabel() + "\"" + " is a cylinder with radius = " 
         + df.format(getRadius()) + " units and height = " 
         + df.format(getHeight()) + ",\n" 
         + " which as a diameter = "
         + df.format(diameter()) + " units, circumference = " 
         + df.format(circumference()) + " units,\n"
         + " area = " + df.format(area()) + " square units, and volume = " 
         + df.format(volume())
         + " cubic units."; 
   }
}

我不明白为什么它说当标签、半径和高度都在圆柱体中设置时,参数不匹配。class

当您在主类中调用此行时:

largeCylinder = new Cylinder(label, height, radius);
得到一个错误bcz在Cynlinder类中没有执行此操作的构造函数。事实上,cynlinder类中根本没有构造函数

将此内容放入您的圆柱体类中,然后重试:

public Cylinder(String constructLabel, double constructHeight, double constructRadius) {
    // required constructor class
    label = constructLabel;
    height = constructHeight;
    radius = constructRadius;
}
现在创建对象并执行以下操作以计算圆柱体:

System.out.println(largeCylinder);
你还可以说:

largeCylinder = new Cylinder();
largeCylinder.setLabel(label);
largeCylinder.setRadius(radius);
largeCylinder.setHeight(height);
System.out.println(largeCylinder);

Cylinder类似乎没有一个带有签名标签、高度、半径的构造函数,如果我在主类new Cylinderlabel中设置,然后转到Cylinder.setHeightheight;和圆柱体。设置半径半径半径;它给了我同样的错误,它似乎也没有一个带有签名字符串的构造函数。你可以看看一个教程,找出什么是构造函数吗?或者你可以看看这个问题:OP不需要println中的.toString调用。它被隐式调用。即使我把大缸=新缸;largeCylinder.setLabellabel;大圆柱。设定半径半径;大气缸。设置高度高度;系统输出打印大气缸;程序可以运行,但是,setLabel的布尔值总是为null。布尔值方法不可能返回null。setLabel方法只返回true/false。不过,GETLABEL方法将返回一个可以为null的字符串。显示您的代码,其中您将获得布尔方法的null返回。