8——java中关于接口的练习

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

package li;

public interface ComputerWeight {
	
	double computerWeight();
	
	void printName();
	
	double printPrice();

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

package li;

public interface ComputerCompany {
	
	String computerName();
	void printFunction();

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

package li;

public class FlashMemory implements ComputerWeight,ComputerCompany 
{
    public double computerWeight()
    {
    	double weigh = 2.2;
    	return weigh;
    }
	
	public void printName()
	{
		System.out.println ("lenovo");
	}
	
	public double printPrice()
	{
		double price  = 5899;
		return price;
	}

	public String computerName() 
	{
		String s = "lenovo";
		return s;
	}

	public void printFunction()
	{
		System.out.println("请注意保护好您的电脑!");
	}

}
/*(4)用一个程序执行入口Test测试上述对象。*/


package li;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
        FlashMemory fm = new FlashMemory();
        double weight,price;
        String name;
        weight = fm.computerWeight();
        price = fm.printPrice();
        name = fm.computerName();
        System.out.println("该品牌电脑的名字为: "+name);
        System.out.println(name+"的重量为: "+weight+"kg.");
        System.out.println(name+"的价格为: "+price+"RMB.");
        fm.printFunction();
	}

}




            
阅读更多
个人分类: 关于JAVA
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭