11.5作业

 

 

 1 package com.baidu;
 2 public class TestSimpleCircle {
 3     public static void main(String[] args) {
 4         SimpleCircle circle1 = new SimpleCircle();
 5         System.out.println("The area of the cricle of radius " + circle1.radius + " is " + circle1.getArea());
 6         
 7         SimpleCircle circle2 = new SimpleCircle(25);
 8         System.out.println("The area of the circle of radius " + circle2.radius + " is " + circle2.getArea());
 9         
10         SimpleCircle circle3 = new SimpleCircle(125);
11         System.out.println("The area of the circle of radius " + circle3.radius + " is " + circle3.getArea());
12         
13         System.out.println("The area of the circle of radius " + circle3.radius + " is " + circle3.getArea());
14         
15         circle2.radius = 100;
16         System.out.println("The area of the circle of radius " + circle2.radius + " is " + circle2.getArea());
17         circle2.setRadius(10);
18         System.out.println("The area of the circle of radius " + circle2.radius + " is " + circle2.getArea());
19         
20         SimpleCircle circle4 = new SimpleCircle(10);
21         System.out.println("The area of the circle of radius " + circle4.radius + " is " + circle4.getPerimeter());
22         
23         circle2.radius = 10;
24         System.out.println("The area of the circle of radius " + circle2.radius + " is " + circle2.getPerimeter());
25         System.out.println(circle2.getPerimeter());
26         
27         double area=circle1.getArea();
28         System.out.println(area);
29         
30         
31         
32     }
33 }
34 class SimpleCircle {
35     double radius;
36     SimpleCircle(){
37         radius = 1;
38     }
39     SimpleCircle(double newRadius){
40         radius = newRadius;
41     }
42     double getArea() {
43         return radius*radius*Math.PI;
44     }
45     double getPerimeter() {
46         return 2*radius*Math.PI;
47     }
48     void setRadius(double newRadius) {
49         radius = newRadius;
50     }
51 }

 

 

 


 


 1 package com.baidu;
 2 
 3 public class Tv {
 4     public static void main(String[] args) {
 5     //  TV tv1=new TV();
 6     //  tv1.turnOff();
 7     //  tv1.setChannel(30);
 8     //  tv1.setVolumeLevel(3);
 9       
10       Tv tv2=new Tv();
11       tv2.turnOn();
12       System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
13       tv2.channelUp();
14       System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
15       tv2.channelUp();
16       System.out.println("TV2's channel is "+tv2.channel

+" and volume is "+tv2.volumeLevel);
17       tv2.channelUp();
18       System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
19       tv2.volumeUp();
20       System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
21       tv2.volumeUp();
22       System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
23       tv2.volumeUp();
24       System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
25       
26       
27     }
28 
29     public int channel=1;
30     public int volumeLevel=1;
31     public boolean on=false;
32     
33     public Tv() {
34         
35     }
36     public void turnOn() {
37         on =true;
38         System.out.println("电视机已经打开了。");
39     }
40     public void turnOff() {
41         on=false;
42         System.out.println("电视机已经关闭了。");
43     }
44     public int getChannel() {
45         return channel;
46     }
47     public void setChannel(int channel) {
48         if(on) {
49             System.out.println("电视机已开,可以开始调台了。");
50             if(channel>=1&&channel<=120) {
51                 this.channel = channel;
52                 System.out.println("频道已经调到 "+channel+" 台");
53             }else {
54                 System.out.println("你要调的频道不存在。");
55             }
56         }else {
57             System.out.println("电视机关着的时候是不能调台的");
58         }
59     }
60     public int getVolumeLevel() {
61         return volumeLevel;
62     }
63     public void setVolumeLevel(int volumeLevel) {
64         if(on) {
65             System.out.println("电视机已开,声音大小可调了");
66             if(volumeLevel>=1&&volumeLevel<=7) {
67                 this.volumeLevel = volumeLevel;
68                 System.out.println("声音的大小设置成了 "+volumeLevel+" 大小");
69             }
70         }else {
71             System.out.println("电视机关着的时候是不能调声音的");
72         }
73         
74     }
75     public void channelUp() {
76         if(on&&channel<120) {
77             channel++;
78         }
79     }
80     public void channelDown() {
81         if(on&&channel>1) {
82             channel--;
83         }
84     }
85     public void volumeUp() {
86         if(on&&volumeLevel<7) {
87             volumeLevel++;
88         }
89     }
90     public void volumeDown() {
91         if(on&&volumeLevel>1) {
92             volumeLevel--;
93         }
94     }
95  }
96     

 

 


 

 1 package dengniu;
 2 public class Dp {
 3     public static void main(String args[]) {
 4         Person per1 = new Person("张三",30);
 5         Person per2 = new Person("张三",30);    
 6         if(per1.getName().equals(per2.getName())&&per1.getAge()==per2.getAge()) {
 7             System.out.println("是同一个人!");
 8         }
 9     }
10 }
11 
12         class Person {
13             private String name;
14             private int age;
15             public Person(String name,int age) {
16                 this.name = name;
17                 this.age = age;
18             }
19         
20         
21             
22             public boolean compare(Person per) {
23                 if(this.name.equals(per.name)&&this.age==per.age) {
24                     return true;
25                 }else {
26                         return false;
27                 }
28             }
29             
30 //        public void fun(Person temp) {
31 //            temp.name="李武";
32 //            temp.age=45;
33 //        }
34 //    
35         public String getName() {
36             return this.name;
37         }
38 
39         public int getAge() {
40             return this.age;
41         }
42     }
43 
44         
45 
46         
47     
48     
49 
50     

 

 


 1 package dengniu;
 2 
 3 public class DtaticDemo {
 4 
 5     public static void main(String[] args) {
 6         new DtaticDemo().fun();
 7     }
 8     public static void fun() {
 9         System.out.println("hellow every day!");
10 
11     }
12 
13 }

 

posted on 2017-11-09 22:21  马文奇  阅读(156)  评论(0编辑  收藏  举报

导航