第一、类名要大写(Test);
第二、可以有多个类,但是只能一个是public。
import java.util.*; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double oblength,obheight; Oblong myoblong; System.out.print("please enter the length"); oblength = sc.nextDouble(); System.out.print("please enter the height"); obheight = sc.nextDouble(); myoblong = new Oblong(oblength,obheight); System.out.println("length="+myoblong.getLength()); System.out.println("height="+myoblong.getHeight()); System.out.println("area="+myoblong.calculateArea()); System.out.println("perimeter="+myoblong.calculatePerimeter()); } }
class Oblong { private double length; private double height; public Oblong(double a,double b) { length = a; height = b; } public double getLength() { return length; } public double getHeight() { return height; } public double calculateArea() { return length * height; } public double calculatePerimeter() { return 2*(length + height); } }