关于类的设计 想要设计一个图形的抽象类,有面积,周长的抽象方法,有颜色的属性;设计一个矩形类由图形类继承,输入长和宽,颜色,可得到周长与面积并输出颜色值;设计一个圆形类由图形类继承,输入半径以及颜色,可得到周长与面积并输出颜色值。不知怎么下手,求高手帮忙。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先谢谢啦...对了,全球蔓延很火的心理测试,我刚刚做完,腿还在发抖! 想知道为什么?测试一下就知道了,测试地址是 http://www.apesk.com/mbti/dati.asp 要敢于把自己的结果贴上来哦! package extend;import java.awt.Color;import java.lang.Math;abstract class MyGraphics{ protected Color color; public abstract double getArea(); public abstract double getPerimeter();}class MyRectangle extends MyGraphics{ private double length; private double width; public void setColor(Color color) { this.color = color; } public Color getColor() { return this.color; } public void setLength(double length) { this.length = length; } public void setWidth(double width) { this.width = width; } public double getArea() { return length*width; } public double getPerimeter() { return 2*(length+width); } }class MyCircle extends MyGraphics{ private double radius; public void setColor(Color color) { this.color = color; } public Color getColor() { return this.color; } public void setRadius(double radius) { this.radius = radius; } public double getArea() { return java.lang.Math.PI*radius*radius; } public double getPerimeter() { return 2*java.lang.Math.PI*radius; }}public class GraphicsTest { /** * Method main * * * @param args * */ public static void main(String[] args) { // TODO: Add your code here } } 抽象Shape类:abstract class Shap { public float getArea(); public float getCircumference(); protected float color;}矩形:class Rectangular extends Shape { public float width; public float height; public Rectangular(float width, float height, float color) { this.width = width; this.height = height; this.color = color; } public float getArea() { return this.widht * this.height; } public float getCircumference() { return 2 * (this.widht + this.height); }}以后的,参照这个看一下,自己也做做。 菜鸟求助 RPG 菜鸟求解,谢了 数组排列问题 怎样压缩文件,zip格式的,求代码!在线等... 数据库连接的简单问题 请问一个static返回值的问题!!!!! 有一道JAVA练习题,谁能帮忙写下。(书上没答案)谢谢了 关于byte 型的数据提问 谁来就就我这奇怪的程序,很简单 Java程序循环运行了一部分后,卡住了,之前控制台有内容输出,卡住之后没有内容输出,但显示程序还在运行 java 如何播放*.mp3文件??? 送分来了,在eclipse中怎么运行外部文件,怎么用导入导出功能
对了,全球蔓延很火的心理测试,我刚刚做完,腿还在发抖! 想知道为什么?测试一下就知道了,测试地址是 http://www.apesk.com/mbti/dati.asp 要敢于把自己的结果贴上来哦!
import java.lang.Math;abstract class MyGraphics{
protected Color color;
public abstract double getArea();
public abstract double getPerimeter();
}class MyRectangle extends MyGraphics{
private double length;
private double width;
public void setColor(Color color)
{
this.color = color;
}
public Color getColor()
{
return this.color;
}
public void setLength(double length)
{
this.length = length;
}
public void setWidth(double width)
{
this.width = width;
}
public double getArea()
{
return length*width;
}
public double getPerimeter()
{
return 2*(length+width);
}
}class MyCircle extends MyGraphics{
private double radius;
public void setColor(Color color)
{
this.color = color;
}
public Color getColor()
{
return this.color;
}
public void setRadius(double radius)
{
this.radius = radius;
}
public double getArea()
{
return java.lang.Math.PI*radius*radius;
}
public double getPerimeter()
{
return 2*java.lang.Math.PI*radius;
}
}public class GraphicsTest {
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
// TODO: Add your code here
}
}
abstract class Shap {
public float getArea();
public float getCircumference();
protected float color;
}矩形:
class Rectangular extends Shape {
public float width;
public float height; public Rectangular(float width, float height, float color) {
this.width = width;
this.height = height;
this.color = color;
}
public float getArea() {
return this.widht * this.height;
}
public float getCircumference() {
return 2 * (this.widht + this.height);
}
}
以后的,参照这个看一下,自己也做做。