1 public class L1106 {
2
3 public static void main(String[] args) {
4 // TODO Auto-generated method stub
5 TestDemo circle1 = new TestDemo();
6 double area=circle1.getArea();
7 System.out.println(area);
8 TestDemo circle2=new TestDemo(10);
9 System.out.println(circle2.getArea());
10 System.out.println(circle1.getPerimeter());
11 System.out.println(circle2.getPerimeter());
12 double ridius=10;
13 double areaCircle=Math.PI*ridius*ridius;
14 System.out.println(areaCircle);
15 circle2.setRadius(5);
16 System.out.println(circle2.getArea());
17 }
18
19 }
1 public class TestDemo {
2
3 private double radius;
4
5 public TestDemo(double radius) {
6 this.radius = radius;
7 }
8 public TestDemo() {
9 this.radius = 1.0;
10 }
11 public double getArea() {
12 return Math.PI * radius * radius;
13 }
14 public double getPerimeter() {
15 return 2 * Math.PI * radius;
16 }
17 public void setRadius(double newRadius) {
18 this.radius = newRadius;
19 }
20 }
1 package cn.TV;
2 import java.util.Scanner;
3 public class L {
4 public int channel = 1;
5 public int volume = 50;
6 public boolean power = false;
7
8 public void powerOn() {
9 power = true;
10 System.out.println("欢迎使用LLTV,电视机已启动!");
11 }
12 public void powerOff() {
13 power = false;
14 System.out.println("Loading...");
15 System.out.println("**关机**");
16 }
17 public int getChannel() {
18 return channel;
19 }
20 public void setChannel(int channel) {
21 if(power) {
22 if(channel >= 1 && channel <= 100) {
23 this.channel = channel;
24 System.out.println("正在收看LLTV:" + channel );
25 }else {
26 System.out.println("您并未购买此频道信号!");
27 }
28 }else {
29 System.out.println("请检查您的电视信号接收线是否正常!");
30 }
31 }
32 public void channelUp() {
33 if(power && channel < 100)
34 channel++;
35 else System.out.println("+++无信号+++");
36 }
37 public void channelDown() {
38 if(power && channel > 1)
39 channel--;
40 else System.out.println("---无信号---");
41 }
42 public void volumeUp() {
43 if(power && volume < 100) {
44 volume++;
45 System.out.println("当前音量为:" + volume + "%!");
46 }else System.out.println("音量已达最大值");
47 }
48 public void volumeDown() {
49 if(power && volume > 0) {
50 volume--;
51 if(volume == 0)
52 System.out.println("电视机已静音!");
53 }
54
55 }
56 public static void main(String[] args) {
57 // TODO Auto-generated method stub
58 Scanner input = new Scanner(System.in);
59 L lltv = new L();
60 lltv.powerOn();
61 System.out.print("手动输入频道序号:");
62 int temp = Integer.valueOf(input.nextLine());;
63 lltv.setChannel(temp);
64 lltv.getChannel();
65 lltv.volumeUp();
66 lltv.volumeDown();
67 }
68 }