在XP系统有完整的内容显示,第九次作业

第五遍作业,

1

package kk;

public class circle {
     private double radius;

        // 构造方法,有参构造
        public circle(double radius) {
            this.radius = radius;
        }
        //方法的重载,参数不同
        // 构造方法,无参构造
        public circle() {
            this.radius = 1;
        }

        // 求圆面积的方法
        public double getArea() {
            return radius * radius * Math.PI;

        }

        // 求圆周长的方法
        public double getPerimeter() {
            return 2 * Math.PI * radius;
        }
        public void setRadius(double newRadius) {
            this.radius=newRadius;
        }
}
package kk;

public class Dmc {
      public static void main(String[] args) {
            circle circle1=new circle();
            double area=circle1.getArea();
            System.out.println(area);
            circle circle2=new circle(10);
            System.out.println(circle2.getArea());
            System.out.println(circle1.getPerimeter());
            System.out.println(circle2.getPerimeter());
            double ridius=10;
            double areaCircle=Math.PI*ridius*ridius;
            System.out.println(areaCircle);
            circle2.setRadius(5);
            System.out.println(circle2.getArea());

        }
}

  永利集团304com 1

2
 
package kk;

public class Scircle {
     private double radius;
        public Scircle() {
            this.radius=1;
        }
        public Scircle(double radius){
            this.radius=radius;
        }
        public double getArea() {
            return Math.PI*radius*radius;
        }
        public double getPerimeter() {
            return 2*Math.PI*radius;
        }
        public static void main(String[] args) {
            Scircle cir1=new Scircle();
            System.out.println("The area of the circle of radius "+cir1.radius+" is "+cir1.getArea());
            Scircle cir2=new Scircle(10);
            System.out.println("The area of the circle of radius "+cir2.radius+" is "+cir2.getArea());
        }
}

  永利集团304com 2

 3
 
 
 
package kk;
public class TV {
    public int channel=1;
    public int volumeLevel=1;
    public boolean on=false;
    public void turnOn() {
        on =true;
        System.out.println("地址为"+new TV());
        System.out.println("号的电视已经打开");
    }
    public void turnOff() {
        on=false;
        System.out.println("电视已经关闭");
    }
    public int getChannel() {
        return channel;
    }
    public void setChannel(int channel) {
        if(on) {
            System.out.println("电视机已开,可开始调台");
            if(channel>=1&&channel<=120) {
                this.channel = channel;
                System.out.println("频道已经调到 "+channel+" 号台");
            }else {
                System.out.println("你要调的频道不存在");
            }
        }else {
            System.out.println("电视机关着的时候不能调台");
        }
    }
    public int getVolumeLevel() {
        return volumeLevel;
    }
    public void setVolumeLevel(int volumeLevel) {
        if(on) {
            System.out.println("电视机已开,声音大小可调");
            if(volumeLevel>=1&&volumeLevel<=7) {
                this.volumeLevel = volumeLevel;
                System.out.println("声音的大小设置成 "+volumeLevel);
            }
            else {
                System.out.println("音量大小超过范围");
            }
        }else {
            System.out.println("电视机关着的时候不能调声音");
        }

    }
    public void channelUp() {
        if(on&&channel<120) {
            channel++;
        }
    }
    public void channelDown() {
        if(on&&channel>1) {
            channel--;
        }
    }
    public void volumeUp() {
        if(on&&volumeLevel<7) {
            volumeLevel++;
        }
    }
    public void volumeDown() {
        if(on&&volumeLevel>1) {
            volumeLevel--;
        }
    }


}
package kk;

public class CTV {
     public static void main(String[] args) {
       TV tv1=new TV();
       tv1.turnOn();
       tv1.setChannel(77);
       tv1.setVolumeLevel(9);      
       TV tv2=new TV();
       tv2.turnOn();
       System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
       tv2.channelUp();
       System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
       tv2.channelUp();
       System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
       tv2.channelUp();
       System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
       tv2.volumeUp();
       System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
       tv2.volumeUp();
       System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
       tv2.volumeUp();
       System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);

   }

}

  永利集团304com 3

1package kk;public class circle {
private double radius; // 构造方法,有参构造 public circle(double radius)
{ this.radius = radius; } //方法的重载,参…

在XP系统有完全的从头到尾的经过展现,
一个C++程序能在XP系统一体化地彰显全体内容,但在WIN8和WIN10不能够全部地展示
#include
#include
#include
#define PI 3.1415
using namespace std;
//radius 半径,length 长度 width宽度 heighr 高度

class shape//基类
{
永利集团304com,public:
virtual double area()=0;//定义纯虚函数

virtual double volume()=0;//定义纯虚函数
virtual double GALAXY Tab()=0;//定义纯虚函数
virtual double zhouchang()=0;//定义纯虚函数
};
class circle:public shape//圆形
{
protected:
double radius;
public:
circle{radius=r;}
virtual double area(){return PI*radius*radius;}
virtual double zhouchang(){return PI*;}
virtual double volume(){return 0;}
virtual double surface(){return 0;}
};
class sphere:public circle//圆球
{
public:
sphere:circle{radius=r;}
double volume(){return *PI*radius*radius*radius;}
double surface(){return 4*PI*radius*radius;}
};
class cylinder:public circle//圆柱
{
protected:
double height;
public:
cylinder(double r,double h):circle{height=h;}
double volume(){return PI*radius*radius*height;}
double surface(){return PI*radius*radius*2+2*radius*PI*height;}
};
class cone:public cylinder//圆锥
{
public:
cone(double r,double h):cylinder{}
double volume(){return PI*radius*radius*height*;}
double surface(){return
PI*radius*radius+PI*radius*sqrt(radius*radius+height*height);}
};
class Rectangle:public shape//长方形
{
protected:
double length,width;
public:
Rectangle(double l,double w){length=l,width=w;}
double area(){return length*width;}
double zhouchang(){return 2*(length+width);}
virtual double volume(){return 0;}
virtual double surface(){return 0;}
};
class coboid:public Rectangle//长方体
{
protected:
double height;
public:
coboid(double l,double w,double h):Rectangle{height=h;}
double volume(){return length*width*height;}
double surface(){return
length*width*2+length*height*2+width*height*2;}
};
int main()
{
int x;
double r,l,w,h;
shape *shape1 = 0 ;
while
{

发表评论

电子邮件地址不会被公开。 必填项已用*标注