您的位置:首页 > 编程语言 > C#

C#上机 第八周 任务2 接口的练习

2012-10-18 00:27 597 查看
/*
* 程序头部注释开始
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:接口的练习
* 作    者:薛广晨
* 完成日期:2012  年 10 月  18  日
* 版 本号:x1.0

* 对任务及求解方法的描述部分
* 输入描述:
* 问题描述:    (1)封装一类接口ComputerWeight,该接口中有3个功能:double computrWeight,void printName,double printPrice。

(2)封装一类接口ComputerCompany,该接口有2个功能:String computerName,void printFunction。

(3)封装一类对象FlashMemory实现上述两类接口。

(4)用一个程序执行入口Test测试上述对象。
* 程序输出:
* 程序头部的注释结束
*/

//ComputerWeight 接口
//(1)封装一类接口ComputerWeight,该接口中有3个功能:double computrWeight,void printName,double printPrice。
package myinterfance;

public interface ComputerWeight {
public double computrWeight = 10;
public void printName();
public void printPrice();
}

//ComputerCompany接口
//(2)封装一类接口ComputerCompany,该接口有2个功能:String computerName,void printFunction。
package myinterfance;

public interface ComputerCompany {
public String computerName = "dell";
public void printFunction();

}

//FlashMemory类
package myinterfance;

public class FlashMemory implements ComputerWeight, ComputerCompany{
public void printName(){
System.out.println("The computer name is " +computerName);
}
public void printPrice(){
System.out.println("The computer Price is 6000 yuan");
}

public void printFunction(){
System.out.println("Achieve print function");

}

}

//测试类MyTest
package myinterfance;

public class MyTest {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
FlashMemory fm = new FlashMemory();

fm.printName();
fm.printPrice();
fm.printFunction();
}

}

运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息