自用备份,有需要可以点个赞,相互学习,欢迎大佬指教。。。
1.请把手机类写成一个标准类,然后创建对象测试功能。
手机类:
成员变量:
品牌:String brand;
价格:int price;
颜色:String color;
成员方法:
针对每一个成员变量给出对应的getXxx()/setXxx()方法。
最后定义测试:
创建一个对象,先通过getXxx()方法输出成员变量的值。这一次的结果是:null---0---null
然后通过setXxx()方法给成员变量赋值。再次输出结果。这一次的结果是:三星---2999---土豪金
2.需求:
定义一个员工类,自己分析出几个成员,
然后给出成员变量,构造方法,getXxx()/setXxx()方法,
以及一个显示所有成员信息的方法。并测试。
分析:
员工
成员变量:
员工编号,姓名,年龄,性别,工种
构造方法:
无参构造方法
成员方法:
getXxx()/setXxx()
show();
(1)class Phone{ private String brand; private int price; private String color; public String getBrand(){ return brand; } public int getPrice(){ return price; } public String getColor(){ return color; } public void setBrand(String brand){ this.brand=brand; } public void setPrice(int price){ this.price=price; } public void setColor(String color){ this.color = color; } public void show(){ System.out.println(getBrand()+"---"+getPrice()+"---"+getColor()); } }
(2)public class PhoneTest { public static void main(String[] args) { Phone p =new Phone(); p.show(); System.out.println("--------------------------------"); p.setBrand("三星"); p.setPrice(2999); p.setColor("土豪金"); p.show(); } }