早教吧作业答案频道 -->其他-->
习题:建立一个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类,有...的网友还看了以下:
一道初二数学有关n的H运算求教规定规定正整数n的H运算是:(1)当n为奇数时,H=3n+13;(2 2020-05-14 …
如果各角都相等的多边形的每一个内角都是它外角的n倍,则这个多边形的边数为用含n的式子表示 2020-06-03 …
请教catalan数网上对catalan数的通项有两种说法一种说catalan数满足递归式:h(n 2020-06-28 …
刘谦的表演风靡全球,小明同学也学起刘谦发明了一个魔术和,其中规定:正整数n的“H”运算;①当n为奇 2020-07-01 …
规定正整数n的“H运算”是:①当n为奇数时,H=3n+13;②当n为偶数时,H=n*1/2*1/2 2020-07-19 …
规定:正整数n的“H运算”是①当n为奇数时,H=3n+13;②当n为偶数时,H=n×12×12×… 2020-07-20 …
关于不定方程的几道题目~1.满足方程x^2+y^2=z^3的正整数组(x,y,z)有多少组?2.求 2020-08-02 …
规定:正整数n的“h运算”是:1、当n为奇数时,H=3n+13;2、当n为偶数时,H=n/2/2.. 2020-11-17 …
数7经过100次“H运算”得到的结果是多少?规定:正整数n的“H运算”:①当n为奇数时,H=3n+1 2020-11-19 …
为什么求陡崖的相对高度要用(n-1)×d≦H<(n+1)×d其中d为等高距n表示重合的等高线条数?这 2020-11-19 …