OPP作业

1,定义一个水果类(fruit),水果类中的有
【属性】:颜色(color)、价格(price)、重量(weigth),
再定义一个<测试类>,
创建一个苹果(apple)的对象, 颜色是"红色",价格是5.5,重量10g。
然后再创建一个香蕉(banana)的对象,颜色是"黄色",价格是4.2,重量5g。
最后输出:
苹果的颜色、价格、重量、
香蕉的颜色、价格、重量、

 1 package org.hanqi.pn0120;
 2 
 3 public class Fruit {
 4     
 5       private String  color;
 6       
 7       private double price;
 8       
 9       private double weigth;
10 
11     public String getColor() {
12         return color;
13     }
14 
15     public void setColor(String color) {
16         this.color = color;
17     }
18 
19     public double getPrice() {
20         return price;
21     }
22 
23     public void setPrice(double price) {
24         this.price = price;
25     }
26 
27     public double getWeigth() {
28         return weigth;
29     }
30 
31     public void setWeigth(double weigth) {
32         this.weigth = weigth;
33     }
34 
35     public Fruit(String color, double price, double weigth) {
36         super();
37         this.color = color;
38         this.price = price;
39         this.weigth = weigth;
40     }
41       
42     public static void main(String[] args)
43     {
44         Fruit apple=new Fruit( "红色",5.5,10);
45         
46         System.out.println("苹果的颜色是"+apple.getColor()+",价格是"+apple.getPrice()+",重量是"+apple.getWeigth()+"g");
47         
48         Fruit banana=new Fruit("黄色",4.2,5);
49         
50         System.out.println("香蕉的颜色是"+banana.getColor()+",价格是"+banana.getPrice()+",重量是"+banana.getWeigth()+"g");
51     }
52 
53 }
Fruit

2、定义一个人类,人类中有以下属性:姓名(name),性别(sex),年龄(age),再定义一个测试类
创建一个"张三"的对象
姓名:张三
性别:男
年龄:20
创建一个"李四"的对象
姓名:李四
性别:女
年龄:21
最后输出张三与李四的信息

 1 package org.hanqi.pn0120;
 2 
 3 public class People {
 4     
 5     private String name;
 6     
 7     private String sex;
 8     
 9     private int age;
10 
11     public String getName() {
12         return name;
13     }
14 
15     public void setName(String name) {
16         this.name = name;
17     }
18 
19     public String getSex() {
20         return sex;
21     }
22 
23     public void setSex(String sex) {
24         this.sex = sex;
25     }
26 
27     public int getAge() {
28         return age;
29     }
30 
31     public void setAge(int age) {
32         this.age = age;
33     }
34 
35     public People(String name, String sex, int age) {
36         super();
37         this.name = name;
38         this.sex = sex;
39         this.age = age;
40     }
41     
42     public static void main(String[] args){
43         
44         People people1=new People("张三","男",20);
45         
46         System.out.println("姓名:"+people1.getName()+"\n性别:"+people1.getSex()+"\n年龄:"+people1.getAge());
47         
48         System.out.println();
49         
50         People people2=new People("李四","女",21);
51         
52         System.out.println("姓名:"+people2.getName()+"\n性别:"+people2.getSex()+"\n年龄:"+people2.getAge());
53         
54     }
55 }
People

3、定义一个桌子类,属性有:材料、编号、价格,再定义一个测试类,在测试类中分别创建两张桌子,分别给他们赋值,最后输出

 1 package org.hanqi.pn0120;
 2 
 3 public class Desk {
 4     
 5        private String cailiao;
 6        
 7        private int binahao;
 8        
 9        private double price;
10 
11     public String getCailiao() {
12         return cailiao;
13     }
14 
15     public void setCailiao(String cailiao) {
16         this.cailiao = cailiao;
17     }
18 
19     public int getBinahao() {
20         return binahao;
21     }
22 
23     public void setBinahao(int binahao) {
24         this.binahao = binahao;
25     }
26 
27     public double getPrice() {
28         return price;
29     }
30 
31     public void setPrice(double price) {
32         this.price = price;
33     }
34 
35     public Desk(String cailiao, int binahao, double price) {
36         super();
37         this.cailiao = cailiao;
38         this.binahao = binahao;
39         this.price = price;
40     }
41        
42        
43     public static void  main(String[] args)
44     {
45         Desk  desk1=new Desk("红木",13,146.6);
46         
47         System.out.println("桌子的材料是"+desk1.getCailiao()+",编号是"+desk1.getBinahao()+",价格是"+desk1.getPrice()+"¥。");
48         
49         Desk  desk2=new Desk("榆木",92,54.2);
50         
51         System.out.println("桌子的材料是"+desk2.getCailiao()+",编号是"+desk2.getBinahao()+",价格是"+desk2.getPrice()+"¥。");
52         
53     }
54 }
Desk

4,写一个传奇游戏中的猪类,类中有属性:颜色(color)、重量(weight)、攻击力(attack)、准确度(accuracy)。再写一个测试类,生成一个猪的对象,将此猪的颜色值为“白色(white)”,重量为5,攻击力为50点,准确度为0.8。要求输出此猪的信息格式为:一只白色的猪,重量5,攻击为50点血,准确度为0.8,我好怕怕呀!

 1 package org.hanqi.pn0120;
 2 
 3 public class Pig {
 4     
 5     private String color;
 6     
 7     private double weight;
 8     
 9     private int attack;
10     
11     private double accuracy;
12 
13     public String getColor() {
14         return color;
15     }
16 
17     public void setColor(String color) {
18         this.color = color;
19     }
20 
21     public double getWeight() {
22         return weight;
23     }
24 
25     public void setWeight(double weight) {
26         this.weight = weight;
27     }
28 
29     public int getAttack() {
30         return attack;
31     }
32 
33     public void setAttack(int attack) {
34         this.attack = attack;
35     }
36 
37     public double getAccuracy() {
38         return accuracy;
39     }
40 
41     public void setAccuracy(double accuracy) {
42         this.accuracy = accuracy;
43     }
44 
45     public Pig(String color, double weight, int attack, double accuracy) {
46         super();
47         this.color = color;
48         this.weight = weight;
49         this.attack = attack;
50         this.accuracy = accuracy;
51     }
52 
53     public static void main(String[] args) {
54         
55         Pig pig=new Pig("白色",5,50,0.8);
56         
57         System.out.println("一只"+pig.getColor()+"的猪,重量"+pig.getWeight()+","
58         + "为"+pig.getAttack()+"点血,准确度为"+pig.getAccuracy()+",我好怕怕呀!");
59         
60     }
61 
62 }
Pig

 

转载于:https://www.cnblogs.com/arxk/p/5252332.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OPP(Object Push Profile)是一种无线通信协议,主要用于在蓝牙技术实现设备之间的物体传输。OPP协议基于传统的客户端/服务器模型,并支持设备之间的对象传送。 在OPP协议,发送方设备被称为客户端,接收方设备被称为服务器。客户端可以向服务器发送请求,请求传输特定的对象。服务器可以接受请求并根据请求来发送对象。对象可以是文件、联系人、图片等等。 OPP协议使用了OBEX(Object Exchange)协议作为其基础协议。 OBEX协议是一种用于无线设备之间对象交换的协议,它提供了一个通用的框架,使得不同设备之间可以方便地交换数据。OBEX协议支持基于客户端/服务器的通信模型,支持连接管理、对象传输和会话管理等功能。 OPP协议使用OBEX协议在蓝牙通信链路进行对象的传输。当一个设备想要传输一个对象给另一个设备时,它首先会建立蓝牙连接,然后使用OPP协议发送一个请求,请求服务器传输该对象。服务器收到请求后,会根据请求的内容将对象传输给客户端。 OPP协议在实际被广泛应用于各种蓝牙设备之间的数据传输。例如,手机之间可以使用OPP协议传输文件、图片和联系人信息,蓝牙耳机可以使用OPP协议接收音频文件等。通过使用OPP协议,不同设备间的数据交换和共享变得更加简单和高效。 总之,OPP是一种使用OBEX作为基础协议的无线通信协议,用于在蓝牙设备之间实现对象的传输。其主要应用于各种蓝牙设备之间的数据交换,提供了一种简单、方便和高效的方式来共享和传输对象。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值