package cn.com.training.student;
/*
综合案例32(对象操作)
训练描述:
• 需求说明:创建三个图书类对象,找出价格最高的图书并打印该图书的所有信息。
• 设计“图书类”Book,要求有以下属性:
图书编号:
书名:
价格:
操作步骤描述
略
*/
public class Training31MainApp {
public static void main(String[] agrs){
Book book = new Book();
book.book1Num = "001";
book.book1Name = "Java基础";
book.book1Price = 50;
book.book2Num = "002";
book.book2Name = "高等数学";
book.book2Price = 60;
book.book3Num = "003";
book.book3Name = "Android移动开发基础";
book.book3Price = 65;
book.getMax();
}
}
package cn.com.training.student;
public class Book {
String book1Num;
String book1Name;
int book1Price;
String book2Num;
String book2Name;
int book2Price;
String book3Num;
String book3Name;
int book3Price;
void getMax(){
if(book3Price>book2Price && book2Price>book1Price) {
System.out.println("图书编号:"+book3Num);
System.out.println("书名:"+book3Name);
System.out.println("价格:"+book3Price+"元");
}
}
}
package cn.com.training.student;
/*
综合案例33(对象操作)
训练描述:
分析以下需求,并用代码实现
手机类Phone
属性:
品牌brand
价格price
行为:
打电话call()
发短信sendMessage()
玩游戏playGame()
要求:
1.按照以上要求定义类,属性要私有,生成空参、有参构造,setter和getter方法
2.定义测试类,在main方法中创建该类的对象并给属性赋值(演示两种方法:setter方法和构造方法)
3.调用三个成员方法,打印格式如下:
正在使用价格为998元的小米品牌的手机打电话....
正在使用价格为998元的小米品牌的手机发短信....
正在使用价格为998元的小米品牌的手机玩游戏....
操作步骤描述
略
*/
public class Training32MainApp {
public static void main(String[] agrs){
Phone ph = new Phone();
ph.setBrand("红米K40");
ph.setPrice(2699);
System.out.print(" 正在使用价格为"+ph.getPrice()+"元的"+ph.getBrand());
call();
System.out.print(" 正在使用价格为"+ph.getPrice()+"元的"+ph.getBrand());
sendMessage();
System.out.print(" 正在使用价格为"+ph.getPrice()+"元的"+ph.getBrand());
playGame();
}
static void call(){
System.out.println("打电话....");
}
static void sendMessage(){
System.out.println("发短信....");
}
static void playGame(){
System.out.println("玩游戏....");
}
}
package cn.com.training.student;
public class Phone {
private String brand;
private int price;
public String getBrand(){
return this.brand;
}
void setBrand(String brand){
this.brand = brand;
}
public int getPrice(){
return this.price;
}
void setPrice(int price){
this.price = price;
}
}