第三次作业

心得:熟能生巧,深有体会,但是我又发现写着写着自己只会用一种方法,不会去拓展,真的是学着学着就慌了。其实学这么久以来,觉得Java也不是特别难理解,只不过是自己动手太少。关键还是效率太低了,别人很快就能弄好的,我就连一个简简单单的都要弄好久好久,然后就觉得自己不行。总的来说,自己选择的路,要脚踏实地地好好走。对于我来说理解起来真的挺困难。

 1 package zy;
 2 public class Monkey {
 3     String s;
 4     public Monkey(String s)
 5     {
 6         this.s=s;
 7     }
 8     public void speak()
 9     {
10         System.out.println("咿咿呀呀......");
11     }
12 }
13 package zy;
14 
15 public class People extends Monkey {
16     public People(String s) {
17         super(s);
18     }
19 public void speak() {
20     System.out.print("小样的,不错嘛'+s+'会讲话了!");
21 }
22 public void think() {
23     System.out.print("别说话!"+"认真思考");
24 }
25 }
26 package zy;
27 
28 public class E {
29 public static void main(String[] args) {
30     Monkey m=new Monkey(" ");
31     m.speak();
32     People p=new People(" ");
33     p.speak();
34     p.think();
35     
36 }
37 }
 1 package Math;
 2 public class Rectangle {
 3     private int len;
 4     private int width;
 5     public Rectangle(int len, int width) {
 6         this.len = len;
 7         this.width = width;
 8     }
 9     public Rectangle() 
10     {
11         
12     }
13     public int getLen() {
14         return len;
15     }
16 
17     public void setLen(int len) {
18         this.len = len;
19     }
20 
21     public int getWidth() {
22         return width;
23     }
24 
25     public void setWidth(int width) {
26         this.width = width;
27     }
28 
29     public void show() {
30         
31         System.out.println("面积s为:"+len+"*"+width+"="+(len*width));
32     }
33 
34     
35 }
36 class Cuboid extends Rectangle{
37     private int height =10;
38     public Cuboid(int len,int width,int height) {
39         super(len, width);
40         this.height = height;
41     }
42     public Cuboid() {
43         // TODO Auto-generated constructor stub
44     }
45     public int V(int len, int width, int height) 
46     {
47         return len*width*height;
48     }
49     public int getLen() {
50         return super.getLen();
51     }
52     public void setLen(int len) {
53         super.setLen(len); 
54     }
55     public int getWidth() {
56         return super.getWidth();
57     }
58     public void setWidth(int width) {
59         super.setWidth(width);
60     }
61     public int getHeight() {
62         return height;
63     }
64     public void setHeight(int height) {
65         this.height = height;
66     }
67     
68     
69 }
70 package Math;
71 
72 
73 public class Test {
74     public static void main(String[] args) {
75         Rectangle R = new Rectangle(20,10);
76         System.out.println(R.getLen()+"    "+R.getWidth());
77         Cuboid A = new Cuboid(10, 2, 5);
78         Cuboid B = new Cuboid(2, 5, 8);
79         System.out.println("长方体体积V为:"+A.getLen()+"*"+A.getWidth()+"*"+A.getHeight()+"="+A.V(A.getLen(),A.getWidth() , A.getHeight()));
80         System.out.println("面积s为:"+A.getLen()+"*"+A.getWidth()+"="+(A.getLen()*A.getWidth()));
81         System.out.println("长方体体积V为:"+B.getLen()+"*"+B.getWidth()+"*"+B.getHeight()+"="+B.V(B.getLen(),B.getWidth() , B.getHeight()));
82         System.out.println("面积s为:"+B.getLen()+"*"+B.getWidth()+"="+(B.getLen()*B.getWidth()));
83     
84     }
85 }
 1 package math;
 2 
 3 public class Vehicle {
 4     private int wheels;
 5     private int weight;
 6     public Vehicle(int i, int j) {
 7         // TODO Auto-generated constructor stub
 8     }
 9     public int getWheels() {
10         return wheels;
11     }
12     public void setWheels(int wheels) {
13         this.wheels = wheels;
14     }
15     public int getWeight() {
16         return weight;
17     }
18     public void setWeight(int weight) {
19         this.weight = weight;
20     } 
21     }
22 package math;
23 
24  public    class Car extends Vehicle{
25         public Car(int wheels, int weight,int loader) {
26             super(wheels, loader);
27             this.loader=loader;
28              //TODO Auto-generated constructor stub
29         }
30         private int loader;
31 
32         public int getLoader() {
33             return loader;
34         }
35 
36         public void setLoader(int loader) {
37             this.loader = loader;
38         }
39     }
40 
41 package math;
42 class Truck extends Car{
43     public Truck(int wheels, int weight,int payload,int loader) {
44         super(wheels, weight,payload);
45         this.payload =payload;
46         this.getLoader();
47         // TODO Auto-generated constructor stub
48     }
49     private int payload;
50     public int getPayload() {
51         return payload;
52     }
53     public void setPayload(int payload) {
54         this.payload = payload;
55     }
56 
57 }
58 package math;
59 
60 public class VehicleTest {
61         public static void main(String[] args) {
62             Vehicle C=new Vehicle(4,200);
63             System.out.println(C.getWheels()+" "+C.getWeight());
64             Car B=new Car(4,100,8);
65             Truck W=new Truck(4,300,20,400);
66             System.out.println("小车B的全部信息为:"+B.getWheels()+B.getWeight()+B.getLoader());
67             System.out.println("卡车W的全部信息为:"+W.getWheels()+W.getWeight()+W.getLoader()+W.getPayload());
68         }
69 }

 

---恢复内容结束---

 1 package zy;
 2 public class Monkey {
 3     String s;
 4     public Monkey(String s)
 5     {
 6         this.s=s;
 7     }
 8     public void speak()
 9     {
10         System.out.println("咿咿呀呀......");
11     }
12 }
13 package zy;
14 
15 public class People extends Monkey {
16     public People(String s) {
17         super(s);
18     }
19 public void speak() {
20     System.out.print("小样的,不错嘛'+s+'会讲话了!");
21 }
22 public void think() {
23     System.out.print("别说话!"+"认真思考");
24 }
25 }
26 package zy;
27 
28 public class E {
29 public static void main(String[] args) {
30     Monkey m=new Monkey(" ");
31     m.speak();
32     People p=new People(" ");
33     p.speak();
34     p.think();
35     
36 }
37 }
 1 package Math;
 2 public class Rectangle {
 3     private int len;
 4     private int width;
 5     public Rectangle(int len, int width) {
 6         this.len = len;
 7         this.width = width;
 8     }
 9     public Rectangle() 
10     {
11         
12     }
13     public int getLen() {
14         return len;
15     }
16 
17     public void setLen(int len) {
18         this.len = len;
19     }
20 
21     public int getWidth() {
22         return width;
23     }
24 
25     public void setWidth(int width) {
26         this.width = width;
27     }
28 
29     public void show() {
30         
31         System.out.println("面积s为:"+len+"*"+width+"="+(len*width));
32     }
33 
34     
35 }
36 class Cuboid extends Rectangle{
37     private int height =10;
38     public Cuboid(int len,int width,int height) {
39         super(len, width);
40         this.height = height;
41     }
42     public Cuboid() {
43         // TODO Auto-generated constructor stub
44     }
45     public int V(int len, int width, int height) 
46     {
47         return len*width*height;
48     }
49     public int getLen() {
50         return super.getLen();
51     }
52     public void setLen(int len) {
53         super.setLen(len); 
54     }
55     public int getWidth() {
56         return super.getWidth();
57     }
58     public void setWidth(int width) {
59         super.setWidth(width);
60     }
61     public int getHeight() {
62         return height;
63     }
64     public void setHeight(int height) {
65         this.height = height;
66     }
67     
68     
69 }
70 package Math;
71 
72 
73 public class Test {
74     public static void main(String[] args) {
75         Rectangle R = new Rectangle(20,10);
76         System.out.println(R.getLen()+"    "+R.getWidth());
77         Cuboid A = new Cuboid(10, 2, 5);
78         Cuboid B = new Cuboid(2, 5, 8);
79         System.out.println("长方体体积V为:"+A.getLen()+"*"+A.getWidth()+"*"+A.getHeight()+"="+A.V(A.getLen(),A.getWidth() , A.getHeight()));
80         System.out.println("面积s为:"+A.getLen()+"*"+A.getWidth()+"="+(A.getLen()*A.getWidth()));
81         System.out.println("长方体体积V为:"+B.getLen()+"*"+B.getWidth()+"*"+B.getHeight()+"="+B.V(B.getLen(),B.getWidth() , B.getHeight()));
82         System.out.println("面积s为:"+B.getLen()+"*"+B.getWidth()+"="+(B.getLen()*B.getWidth()));
83     
84     }
85 }
 1 package math;
 2 
 3 public class Vehicle {
 4     private int wheels;
 5     private int weight;
 6     public Vehicle(int i, int j) {
 7         // TODO Auto-generated constructor stub
 8     }
 9     public int getWheels() {
10         return wheels;
11     }
12     public void setWheels(int wheels) {
13         this.wheels = wheels;
14     }
15     public int getWeight() {
16         return weight;
17     }
18     public void setWeight(int weight) {
19         this.weight = weight;
20     } 
21     }
22 package math;
23 
24  public    class Car extends Vehicle{
25         public Car(int wheels, int weight,int loader) {
26             super(wheels, loader);
27             this.loader=loader;
28              //TODO Auto-generated constructor stub
29         }
30         private int loader;
31 
32         public int getLoader() {
33             return loader;
34         }
35 
36         public void setLoader(int loader) {
37             this.loader = loader;
38         }
39     }
40 
41 package math;
42 class Truck extends Car{
43     public Truck(int wheels, int weight,int payload,int loader) {
44         super(wheels, weight,payload);
45         this.payload =payload;
46         this.getLoader();
47         // TODO Auto-generated constructor stub
48     }
49     private int payload;
50     public int getPayload() {
51         return payload;
52     }
53     public void setPayload(int payload) {
54         this.payload = payload;
55     }
56 
57 }
58 package math;
59 
60 public class VehicleTest {
61         public static void main(String[] args) {
62             Vehicle C=new Vehicle(4,200);
63             System.out.println(C.getWheels()+" "+C.getWeight());
64             Car B=new Car(4,100,8);
65             Truck W=new Truck(4,300,20,400);
66             System.out.println("小车B的全部信息为:"+B.getWheels()+B.getWeight()+B.getLoader());
67             System.out.println("卡车W的全部信息为:"+W.getWheels()+W.getWeight()+W.getLoader()+W.getPayload());
68         }
69 }

 

---恢复内容结束---

posted on 2019-05-17 16:23  小张~  阅读(151)  评论(1编辑  收藏  举报

导航