当前位置: 首页 > news >正文

Java面向对象练习(1.手机类)(2024.7.4)

        手机类

package Phone;public class Phone {private String brand;private int price;private String color;public Phone(){}public Phone(String brand, int price, String color){this.brand = brand;this.price = price;this.color = 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 String getBrand(){return brand;}public int getPrice(){return price;}public String getColor(){return color;}public void call(Phone phone){System.out.printf("正在使用价值%d的%s%s手机打电话\n", phone.getPrice(),phone.getColor(), phone.getBrand());}public void sendMessage(Phone phone){System.out.printf("正在使用价值%d的%s%s手机发短信\n", phone.getPrice(),phone.getColor(), phone.getBrand());}
}

           测试

package Phone;
import java.util.Scanner;
public class PhoneTest {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入手机的品牌");String brand = sc.next();System.out.println("请输入手机的价格");int price = sc.nextInt();System.out.println("请输入手机的颜色");String color = sc.next();Phone phone = new Phone(brand, price, color);phone.call(phone);phone.sendMessage(phone);}
}

 

http://www.lryc.cn/news/394939.html

相关文章:

  • 智慧生活新篇章,Vatee万腾平台领航前行
  • Spring Cloud Gateway报sun.misc.Unsafe.park(Native Method)
  • select single , select endselect
  • 后端学习(一)
  • 【活动行】参与上海两场线下活动,教育生态行业赛总决赛活动和WAIC人工智能大会活动 - 上海活动总结
  • conda 安装设置
  • 用PlantUML和语雀画UML类图
  • uniapp微信小程序电子签名
  • MetaPoint_速读
  • 数据库逆向工程工具reverse_sql
  • 四大内网穿透利器对比
  • 【LeetCode】每日一题:跳跃游戏 II
  • SpringBoot拦截器
  • uniapp中实现跳转链接到游览器(安卓-h5)
  • WPF UI 界面布局 魔术棒 文字笔记识别 技能提升 布局功能扩展与自定义 继承Panel的对象,测量与排列 系列七
  • 文件格式是.pb应该怎么查看?
  • android2024 gradle8 Processor和ksp两种编译时注解实现
  • elementui的table的@selection-change阻止事件改变
  • 空间数据采集与管理:为什么选择ArcGISPro和Python?
  • 案例精选 | 聚铭综合日志分析系统为江苏省电子口岸构建高效安全的贸易生态
  • TCP粘包
  • 数据泄露态势(2024年5月)
  • 二手闲置平台小程序的设计
  • 协程libgo的使用
  • 什么叫低频晶振?低频晶振最低频率能达到多少?低频晶振封装尺寸有哪些?
  • Splunk Enterprise 任意文件读取漏洞(CVE-2024-36991)
  • 零基础STM32单片机编程入门(九)IIC总线详解及EEPROM实战含源码视频
  • 数据库的操作
  • 常见的认证方式
  • DolphinScheduler部署安装or基础介绍(一)