/**键盘录入长方形的长和宽,计算长方形的周长和面积,请使用面向对象的方式解决!
*长方形的面积等于长乘宽
*/长方形的周长是(长+宽)*2
新建两个Class文件一个作为测试类,一个作为方法类(CFX)
方法类代码
package com.qf.demo05;
public class CFX {
//定义两个变量分别记录长和宽
private int length;
private int width;
public CFX() {
}
//建立SET和GET利用set传入数值
public CFX(int length, int width) {
this.length = length;
this.width = width;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
//方法公式如下
public int getZhouChang() {
return(length+width)*2;
}
public int getMiamJi() {
return(length*width);
}
}
新建一个测试类(Test)
package com.qf.demo05;
import java.util.Scanner;
public class Test {
public static void main(Strin