//制作圆类
package cn.wzx.www; public class Circle { private double radius; public Circle(){ this.radius=1; } public Circle(double radius){ this.radius=radius; } public double getArea(){ return radius*radius*Math.PI; } public double getPerimeter(){ return 2*radius*Math.PI; } public void setRadius(double newRadius) { this.radius=newRadius; } }
package cn.wzx.www; public class Democirle { public static void main(String[] args) { // TODO 自动生成的方法存根 Circle circle1=new Circle(); System.out.println(circle1.getArea()); Circle circle2=new Circle(10); System.out.println(circle2.getArea()); Circle circle3=new Circle(); System.out.println(circle3.getPerimeter()); Circle circle4=new Circle(10); System.out.println(circle4.getPerimeter()); circle2.setRadius(2); System.out.println(circle2.getPerimeter()); } }
package cn.wzx.www; public class Simplecircle { private double radius; public Simplecircle(){ this.radius=1; } public Simplecircle(double radius){ this.radius=radius; } public double getArea(){ return radius*radius*Math.PI; } public double getPerimeter(){ return 2*radius*Math.PI; } public void setRadius(double newRadius) { this.radius=newRadius; } public static void main(String[] args) { // TODO 自动生成的方法存根 Circle circle1=new Circle(); System.out.println(circle1.getArea()); Circle circle2=new Circle(5); System.out.println(circle2.getArea()); Circle circle3=new Circle(); System.out.println(circle3.getPerimeter()); Circle circle4=new Circle(10); System.out.println(circle4.getPerimeter()); circle2.setRadius(2); System.out.println(circle2.getPerimeter()); } }
电视机
package cn.wzx.www; public class TestTV { public static void main(String[] args) { // TODO 自动生成的方法存根 TV tv1=new TV(); tv1.turnOn(); tv1.setChannel(6); tv1.setChannel(121); tv1.setVolumeLevel(5); tv1.setVolumeLevel(9); //tv1.turnOff(); //tv1.setChannel(6); //tv1.setVolumeLevel(5); TV tv2=new TV(); tv2.turnOn(); System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel); tv2.channelUp(); tv2.volumeUp(); System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel); } }