[英]Why does my setLength/getLength and setWidth/getWidth not work
我的 setLength/getLength 和 setWidth/getWidth 不起作用。 显然是因为它找不到符号,但我不知道这意味着什么。
我尝试了一切,无论我多么努力,它似乎都不起作用
package practice;
import java.util.Scanner;
public class Oval {
private double width;
private double length;
public static void main(String[] args) {
Oval oval = new Oval();
oval.setLength(102.13);
System.out.println("the circle's length is: " + oval.getLength());
oval.setWidth(211.02);
System.out.printf("The circle's width is: " + oval.getWidth());
String str = "Given the length %, .4f and the width %, .4f,\n\t " + "the circle's area is %,.4f sq.ft\n";
System.out.printf(str, oval.getLength(), oval.getWidth, oval.getArea());
}
}
似乎您需要为实际的 get/set 方法创建单独的方法,因为您只有 main 方法,也许您可以在 main 方法之外执行一些操作,例如
public double getLength(){
return length;
}
public void setLength(double length){
this.length = length;
}
public double getWidth(){
return width;
}
public void setLength(double width){
this.width = width;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.