7.6实战练习第一题
Yinliao类代码:
1 package org.hanqi.pn0120; 2 3 public class Yinliao { 4 5 private String mingcheng; 6 private double jiage; 7 public String getMingcheng() { 8 return mingcheng; 9 } 10 public void setMingcheng(String mingcheng) { 11 this.mingcheng = mingcheng; 12 } 13 public double getJiage() { 14 return jiage; 15 } 16 public void setJiage(double jiage) { 17 this.jiage = jiage; 18 } 19 public Yinliao(String mingcheng, double jiage) { 20 super(); 21 this.mingcheng = mingcheng; 22 this.jiage = jiage; 23 } 24 public void drink() 25 { 26 System.out.println("我要喝"+this.mingcheng); 27 System.out.println(this.mingcheng+"的价格是:"+this.jiage); 28 } 29 }
Test类中的代码:
1 package org.hanqi.pn0120; 2 3 public class Testdrink { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 Yinliao mydrink=new Yinliao("橙汁",3); 8 mydrink.drink(); 9 } 10 11 }