面向对象04-java基础

------------------------------------------------------------------Debug使用---------------------------------------------------------------------------

这一部分知识是在我实习时候的最大收获,具体操作也熟悉了,我总结打debug的具体步骤:打断点-----打debug as 当前程序——根据快捷键执行debug:

Step into(f5)------进入当前行的方法内部,一步一步的执行;

Step return(f7)------返回上一步执行的方法;

Step over(f6)-------执行当前行,但不执行细节;

Resume(f8)--------恢复执行,表示接着执行细节;

总结:这部分知识,最重要的是练习。

-------------------------------------------------------------作业题-------------------------------------------------------------------------

一、

1、person接口:

public interface Person {

public void setData(String name, String sex, String birthday);

public void getData();

}

2、Student实现:

public class Student implements Person {

private String name;

private String sex;

private String birthday;

private String sID;

private String specaility;

public String getsID() {

return sID;

}

 

public void setsID(String sID) {

this.sID = sID;

}

 

public String getSpecaility() {

return specaility;

}

 

public void setSpecaility(String specaility) {

this.specaility = specaility;

}

 

@Override

public void setData(String name, String sex, String birthday) {

this.name = name;

this.sex = sex;

this.birthday = birthday;

}

 

@Override

public void getData() {

System.out.println("name:" + this.name + " " + "sex:" + this.sex + " "

"birthday:" + this.birthday + " ""sID:" + this.sID

" ""specaility:" + this.specaility);

}

 

}

3、测试类:

public class Test {

 

public static void main(String[] args) {

Student s = new Student();

s.setsID("01");

s.setSpecaility("good");

s.setData("tom""男""2016-5-6");

s.getData();

}

 

}

4、运行结果:

name:tom sex:男 birthday:2016-5-6 sID:01 specaility:good

1、Geometry接口:

public interface Geometry {

public double getArea();

}

2、Pillar类:

package Day07;

 

public class Pillar {

private Geometry bottom;//底面积

private double higth;//高

//getter()和setter()方法

public double getHigth() {

return higth;

}

public Geometry getBottom() {

return bottom;

}

public void setBottom(Geometry bottom) {

this.bottom = bottom;

}

public void setHigth(double higth) {

this.higth = higth;

}

//构造函数,对成员变量赋值

public  Pillar(Geometry bottomdouble higth){

this.bottom = bottom;

this.higth = higth;

}

//成员方法,计算柱体的体积

public double getVol(){

return  this.bottom.getArea() * this.higth;

}

}

 

3、Circle类:

package Day07;

 

public class Circle implements Geometry {

private double r;

public Circle(double r){

this.r = r;

}

public double getR() {

return r;

}

public void setR(double r) {

this.r = r;

}

 

@Override

public double getArea() {

return Math.PI * this.r * this.r;

}

 

}

 

4、Rect类:

package Day07;

 

public class Rect implements Geometry {

private double width;

private double higth;

public Rect(double widthdouble higth){

this.width = width;

this.higth = higth;

}

public double getWidth() {

return width;

}

 

public void setWidth(double width) {

this.width = width;

}

 

public double getHigth() {

return higth;

}

 

public void setHigth(double higth) {

this.higth = higth;

}

 

@Override

public double getArea() {

return this.width * this.higth;

}

 

}

 

5、测试类:

package Day07;

 

public class Test01 {

 

public static void main(String[] args) {

Pillar p1 = new Pillar(new Circle(3), 5);

Pillar p2 = new Pillar(new Rect(3, 4), 5);

System.out.println("圆柱的体积:" + p1.getVol());

System.out.println("长方体的体积:" + p2.getVol());

}

 

}

 

6、运行结果:

圆柱的体积:141.3716694115407

长方体的体积:60.0

三、

1、水的类

public abstract class Water {

public void Water(){

}

}

2、缓冲接口

public interface Buffer {

public abstract String buffer();

}

 

3、过滤接口

public interface Filter {

public abstract String filter();

}

4、加热接口

public interface Warm {

public abstract String warm();

}

5、放糖接口

public interface Sugaring {

public abstract String sugaring();

}

 

6、纯净水1

public class Water1 extends Water implements Filter, Buffer {

 

@Override

public String buffer() {

return "缓冲";

}

 

@Override

public String filter() {

return "过滤";

}

 

}

7、纯净水2

public class Water2 extends Water implements Buffer {

 

@Override

public String buffer() {

return "缓冲";

}

 

}

 

8、纯净水3

public class Water3 extends Water implements Filter {

 

@Override

public String filter() {

return "过滤";

}

 

}

 

9、生产类

package Day07;

 

public class Product extends Water implements Filter, Buffer, Warm, Sugaring {

 

@Override

public String sugaring() {

return "放糖";

}

 

@Override

public String warm() {

return "加热";

}

 

@Override

public String buffer() {

return "缓冲";

}

 

@Override

public String filter() {

return "过滤";

}

 

}

 

10、测试类

package Day07;

 

public class TestProduct {

 

public static void main(String[] args) {

Product p = new Product();

Water1 w1 = new Water1();

Water2 w2 = new Water2();

Water3 w3 = new Water3();

System.out.println("纯净水1:" + w1.buffer() + " " + w1.filter());

System.out.println("纯净水2:" + w2.buffer());

System.out.println("纯净水3:" + w3.filter());

System.out.println("总体的生产线为:" + p.buffer() + "---->" 

p.filter() + "---->" + p.warm()

"---->" + p.sugaring());

}

 

}

 

11、运行结果

纯净水1:缓冲 过滤

纯净水2:缓冲

纯净水3:过滤

总体的生产线为:缓冲---->过滤---->加热---->放糖

 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值