早教吧作业答案频道 -->其他-->
习题:建立一个shape类,有circle和rect子类。建立一个shape类,有circle和rect子类.Shape类有zhouchang()和area()两种方法.(正方形)squ为rect子类,rect与cha()用于比较长宽的差。
题目详情
习题:建立一个shape类,有circle和rect子类。
建立一个shape类,有circle和rect子类. Shape 类有zhouchang()和area()两种方法.(正方形)squ为rect子类,rect与cha()用于比较长宽的差。
建立一个shape类,有circle和rect子类. Shape 类有zhouchang()和area()两种方法.(正方形)squ为rect子类,rect与cha()用于比较长宽的差。
▼优质解答
答案和解析
package javasky;
public abstract class Shape {
private double dLong = 0.00;
private double width = 0.00;
private double height = 0.00;
public double getDLong() {
return dLong;
}
public void setDLong(double long1) {
dLong = long1;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public void girth() {
}
public void area() {
}
}
package javasky;
public class Circle extends Shape { private final static double PI=3.14;
@Override
public void area() {
System.out.println( this.getDLong());
}
@Override
public void girth() {
System.out.println( this.getDLong());
}
}
package javasky;
public class Rect extends Shape {
@Override
public void area() {
System.out.println("面积为:"+this.getDLong()*this.getWidth());
}
@Override
public void girth() {
System.out.println("周长为:"+(double)2*this.getDLong()+(double)2*this.getWidth());
}
public void cha(){
//用于比较长宽的差,若长大于宽输出“长比宽大”,否则输出“宽比长大”。(正方形)
double result = this.getDLong()-this.getWidth();
String shape="长为"+this.getDLong()+"长为"+this.getWidth();
String str="";
if(result>0){
str="此图形为长方形。";
}else{
str="长等于宽,此图形为正方形。";
}
System.out.println(shape+str);
}
public Rect(double dlong,double width) {
System.out.println("赋初始值");
this.setDLong(dlong);
this.setWidth(width);
}
}
package javasky;
public class T {
public static void main(String[] args) {
Rect rect = new Rect(2.00,2.00);
rect.cha();
}
}
public abstract class Shape {
private double dLong = 0.00;
private double width = 0.00;
private double height = 0.00;
public double getDLong() {
return dLong;
}
public void setDLong(double long1) {
dLong = long1;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public void girth() {
}
public void area() {
}
}
package javasky;
public class Circle extends Shape { private final static double PI=3.14;
@Override
public void area() {
System.out.println( this.getDLong());
}
@Override
public void girth() {
System.out.println( this.getDLong());
}
}
package javasky;
public class Rect extends Shape {
@Override
public void area() {
System.out.println("面积为:"+this.getDLong()*this.getWidth());
}
@Override
public void girth() {
System.out.println("周长为:"+(double)2*this.getDLong()+(double)2*this.getWidth());
}
public void cha(){
//用于比较长宽的差,若长大于宽输出“长比宽大”,否则输出“宽比长大”。(正方形)
double result = this.getDLong()-this.getWidth();
String shape="长为"+this.getDLong()+"长为"+this.getWidth();
String str="";
if(result>0){
str="此图形为长方形。";
}else{
str="长等于宽,此图形为正方形。";
}
System.out.println(shape+str);
}
public Rect(double dlong,double width) {
System.out.println("赋初始值");
this.setDLong(dlong);
this.setWidth(width);
}
}
package javasky;
public class T {
public static void main(String[] args) {
Rect rect = new Rect(2.00,2.00);
rect.cha();
}
}
看了习题:建立一个shape类,有...的网友还看了以下:
1.a≠0,b≠0,则a/|a|+b/|b|的不同取值的个数为()A.3B.2C.1D.02.若|x 2020-03-31 …
基本不等式超费解130已知a>b>0,求a2+1/(a*b)+1/[a*(a-b)]的最小值.a2 2020-05-13 …
设集合A={1,a,b},B={a,a^2,ab}且A=B,求实数A,B的值因为集合需要满足互异性 2020-05-15 …
假设集合A满足以下条件:诺a∈A,a不等于1,则1-a分之1属于A若a属于A,则1-a分之一属于A 2020-07-03 …
以下叙述中不正确的是()A.表达式a&=b等价于a=a&bB.表达式a|=b等价于a=a|bC.表 2020-07-14 …
矩阵平方差设方阵A满足A²-A-2E=O,求A的逆矩阵.答案是1/2(A-E).为啥不是1/2E, 2020-07-18 …
线性代数矩阵A满足A*=A^T,如a11,a12,a13为三个相等的正数,则a11为多少?由AA* 2020-07-25 …
已知向量a≠e,|e|=1,满足:任意t∈R.已知向量a不等于e,|e|=1,对任意t属于R,恒有 2020-07-25 …
已知A={x|x=a+(根号2)*b,a,b属于N}(1)对任意x1,x2属于A,证明x1+x2属 2020-07-29 …
匀质铁链悬挂在天花板上,其中A点是最低点.C点是悬挂点,B点是介于A、C之间的某一点,关于这三点铁链 2020-11-20 …