面向对象系列教材 (一) 您所在的位置:网站首页 基金定投操作技巧 面向对象系列教材 (一)

面向对象系列教材 (一)

2023-03-20 16:33| 来源: 网络整理| 查看: 265

面向对象系列教材 (二)- Java类的属性 登录后可下载 工具版本兼容问题 本章节会引入面向对象的基本概念 (但是不会深入展开,仅仅是引入. 深入的学习会在后续的类和对象以及接口与继承 中展开)

相信你肯定玩过DOTA或者LOL,没玩过,也一定听说过身边有很多的朋友在玩这款游戏的

假设,我们要设计一个LOL这样的游戏,使用面向对象的思想来设计,应该怎么做?

本视频是解读性视频,所以希望您已经看过了本知识点的内容,并且编写了相应的代码之后,带着疑问来观看,这样收获才多。 不建议一开始就观看视频

7分55秒 本视频采用html5方式播放,如无法正常播放,请将浏览器升级至最新版本,推荐火狐,chrome,360浏览器。 如果装有迅雷,播放视频呈现直接下载状态,请调整 迅雷系统设置-基本设置-启动-监视全部浏览器 (去掉这个选项)。 chrome 的 视频下载插件会影响播放,如 IDM 等,请关闭或者切换其他浏览器

播放本视频会花费3个积分,您目前总共有点积分。再次播放不会花费额外积分 积分增加办法 或者一次性购买总计72个视频 登录后才能播放教学视频,点击登录 积分不够,您目前只有点积分,播放本教学视频需要3点积分 积分增加办法 或者一次性购买总计72个视频 账号未激活 激活后才能播放教学视频 请点击激活

步骤 1 : 设计英雄这个类    步骤 2 : 创建具体的英雄    步骤 3 : 类的第一个字母大写    步骤 4 : 练习-Item    步骤 5 : 答案-Item   

步骤 1 : 设计英雄这个类 edit 顶 折 纠 问 请先登录 LOL有很多英雄,比如盲僧,团战可以输,提莫必须死,盖伦,琴女所有这些英雄,都有一些共同的状态比如,他们都有名字,hp,护甲,移动速度等等这样我们就可以设计一种东西,叫做类,代表英雄这样一种事物类: 英雄(Hero)状态: 名字, 血量,护甲,移动速度

注: 本例用到了3种数据类型 分别是 String(字符串),float(浮点数), int(整数),本章只做简单的使用 ,就不展开了,关于变量知识的详细讲解,将在下个章节展开.注: 这个类没有主方法,不要试图运行它。 并不是所有的类都是有主方法的。

设计英雄这个类 public class Hero { String name; //姓名 float hp; //血量 float armor; //护甲 int moveSpeed; //移动速度 } public class Hero { String name; //姓名 float hp; //血量 float armor; //护甲 int moveSpeed; //移动速度 } 步骤 2 : 创建具体的英雄 edit 顶 折 纠 问 请先登录 类就像一个模板,根据这样一个模板,可以创建一个个的具体的英雄 一个个具体的英雄,就叫一个个的对象 new Hero() 就是java中创建一个英雄对象的意思 创建具体的英雄 public class Hero { String name; //姓名 float hp; //血量 float armor; //护甲 int moveSpeed; //移动速度 public static void main(String[] args) { Hero garen = new Hero(); garen.name = "盖伦"; garen.hp = 616.28f; garen.armor = 27.536f; garen.moveSpeed = 350; Hero teemo = new Hero(); teemo.name = "提莫"; teemo.hp = 383f; teemo.armor = 14f; teemo.moveSpeed = 330; } } 代码行数较多,请点击查看 public class Hero { String name; //姓名 float hp; //血量 float armor; //护甲 int moveSpeed; //移动速度 public static void main(String[] args) { Hero garen = new Hero(); garen.name = "盖伦"; garen.hp = 616.28f; garen.armor = 27.536f; garen.moveSpeed = 350; Hero teemo = new Hero(); teemo.name = "提莫"; teemo.hp = 383f; teemo.armor = 14f; teemo.moveSpeed = 330; } } 步骤 3 : 类的第一个字母大写 edit 顶 折 纠 问 请先登录 好的编程习惯会让代码看上去更清爽,易读,容易维护比如类的第一个字母大写Hero public class Hero { } public class Hero { } 步骤 4 : 练习-Item edit 顶 折 纠 问 请先登录  姿势不对,事倍功半! 点击查看做练习的正确姿势 设计出物品这种类 类名:Item 物品有如下属性: 名字 name 类型是字符串String 价格 price 类型是整型 int

创建(实例化)3件具体物品 名称 价格 血瓶 50 草鞋 300 长剑 350

步骤 5 : 答案-Item edit 顶 折 纠 问 请先登录 请先登录 在查看答案前,尽量先自己完成,碰到问题再来查看答案,收获会更多 在查看答案前,尽量先自己完成,碰到问题再来查看答案,收获会更多 在查看答案前,尽量先自己完成,碰到问题再来查看答案,收获会更多 查看本答案会花费3个积分,您目前总共有点积分。查看相同答案不会花费额外积分。 积分增加办法 或者一次性购买JAVA 基础总计0个答案 (总共需要0积分) 查看本答案会花费3个积分,您目前总共有点积分。查看相同答案不会花费额外积分。 积分增加办法 或者一次性购买JAVA 基础总计0个答案 (总共需要0积分) 账号未激活 账号未激活,功能受限。 请点击激活 本视频是解读性视频,所以希望您已经看过了本答案的内容,带着疑问来观看,这样收获才多。 不建议一开始就观看视频 2分16秒 本视频采用html5方式播放,如无法正常播放,请将浏览器升级至最新版本,推荐火狐,chrome,360浏览器。 如果装有迅雷,播放视频呈现直接下载状态,请调整 迅雷系统设置-基本设置-启动-监视全部浏览器 (去掉这个选项)。 chrome 的 视频下载插件会影响播放,如 IDM 等,请关闭或者切换其他浏览器

注: 创建Item这个类的时候,必须写在一个Item.java的文件里,不可以使用其他文件名,大小写也要保持一致,不能是item.java public class Item { String name; int price; public static void main(String[] args) { Item potion = new Item(); potion.name= "血瓶"; potion.price =50; Item shoe = new Item(); shoe.name= "草鞋"; shoe.price =300; Item sword = new Item(); sword.name= "长剑"; sword.price =350; } } public class Item { String name; int price; public static void main(String[] args) { Item potion = new Item(); potion.name= "血瓶"; potion.price =50; Item shoe = new Item(); shoe.name= "草鞋"; shoe.price =300; Item sword = new Item(); sword.name= "长剑"; sword.price =350; } } 文件内容比较器

把你的代码复制到下面区域。 如果在线比较不好用,请使用客户端比较软件: diffmerge 下载和使用教程

复制代码

代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢

分享连接

分享如下连接可增加积分,获取50%佣金 推

如果不方便发连接(如贴吧),可以使用如下由连接转换为的二维码. 鼠标在图片上右键,然后另存为即可 警告: 请勿使用挂机软件刷积分,刷积分不会导致任何注册量,很容易被识别。 一旦发现刷积分,即封号处理,请勿做吃力不讨好之事。 做练习的正确姿势 1. 自行完成练习 根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程 2. 带着疑问查看答案 完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路 3. 查看答案讲解视频 依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分 4. 再做一遍 理解后,再从头做一遍,把有疑问的地方都捋清楚 5. 总结 最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理 面向对象系列教材 (一)- Java中的类和对象-总结笔记 把这时的想法,思路,研究都记录下来,等全部学完了,再回过头来巩固和理解,学习效果就会很好,知识点掌握得也牢固. 点击查看我的笔记 总结 代码 保存中预计需要秒 保存完成 保存失败,请联系站长 收藏本知识点

有的同学收藏是为了进行标记,过段时间再来看不明白的地方,在此处可以记录哪里不明白. 单纯收藏的, 直接点击提交即可。

点击查看我的收藏 错误纠正专用

站长比较马虎,难免出现错别字,如果发现哪里文字有误,请提交错误,站长会尽快修改,谢谢

面向对象系列教材 (二)- Java类的属性 HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。

问答区域     删除提问已经提交成功,正在审核, 谢谢. 回复提问已经提交成功,正在审核, 谢谢. 2022-11-15 Hero无法解析为类型怎么解决 wei674682215

关于 JAVA 基础-面向对象-类和对象 的提问

问题 截图 代码 异常 Hero无法解析为类型怎么解决 加载中

17 个答案 lu010118 审核中 答案时间:2023-03-20 public class Item { String name; int price; public static void main(String[] args) { Item xueping=new Item(); xueping.name="血瓶"; xueping.price=50; Item caoxie=new Item(); caoxie.name="草鞋"; caoxie.price=300; Item changjian=new Item(); changjian.name="长剑"; changjian.price=350; } } yslkl20170615 跳转到问题位置 答案时间:2023-03-13 代码超过 5行,点击查看 package 面向对象; public class Item { String name; int price; public static void main(String[] args) { Item item = new Item(); item.name = "血瓶"; item.price = 50; Item item1 = new Item(); item.name = "草鞋"; item.price = 300; Item item2 = new Item(); item.name = "长剑"; item.price = 350; } } yslkl20170615 跳转到问题位置 答案时间:2023-03-13 代码超过 5行,点击查看 package 面向对象; public class Hero { String name;// 姓名 float hp;// 血量 float armor;// 护甲 int moveSpeed;// 移动速度 int killCount;// public void keng() { System.out.println("坑队友!"); } float getArmor() { return armor; } void addSpeed(int speed) { moveSpeed = moveSpeed + speed; } void legenderay(){ System.out.println("超声!"); } float getHp(){ return hp; } void recovery(float blood){ hp +=blood; } public static void main(String[] args) { Hero garen = new Hero(); garen.name = "盖伦"; garen.hp = 616.28F; garen.armor = 27.536F; garen.moveSpeed = 350; garen.addSpeed(100); garen.keng(); Hero teemo = new Hero(); garen.name = "提莫"; garen.hp = 383F; garen.armor = 14F; garen.moveSpeed = 330; } } 怪异的羊 跳转到问题位置 答案时间:2023-02-25 代码超过 5行,点击查看 package com.cwj.object; import com.cwj.pojo.Cookie; public class CookieTest { public static void main(String[] args) { Cookie cookie=new Cookie(); // 曲奇饼干 cookie.setName("曲奇饼干"); cookie.setPrice(100); Cookie cookie2=new Cookie(); cookie2.setName("苏打饼干"); cookie2.setPrice(66); Cookie cookie3=new Cookie(); cookie3.setName("威化饼干"); cookie3.setPrice(200); } } 出招非我愿 跳转到问题位置 答案时间:2023-02-13 public class Item { String name; int price; public static void main(String[] args) { Item xueping = new Item(); xueping.name = "血瓶"; xueping.price = 50; Item caoxie = new Item(); caoxie.name = "草鞋"; caoxie.price = 300; Item changjian = new Item(); changjian.name = "长剑"; changjian.price = 350; } } isNpy 跳转到问题位置 答案时间:2023-02-08 代码超过 5行,点击查看 public class Item { String name; int price; public static void main(String[] args) { Item xue = new Item(); xue.name = "血瓶"; xue.price = 50; Item cao = new Item(); cao.name = "草鞋"; cao.price = 300; Item chang = new Item(); chang.name = "长剑"; chang.price = 350; System.out.println("名称" + "\t" + "价格"); System.out.println(xue.name + "\t" + xue.price); System.out.println(cao.name + "\t" + cao.price); System.out.println(chang.name + "\t" + chang.price); } } 代号9527 跳转到问题位置 答案时间:2023-01-31 public class Item { String name; int price; public static void main(String[] args) { Item test1 = new Item(); test1.name = "血瓶"; test1.price = 50; Item test2 = new Item(); test2.name = "草鞋"; test2.price = 300; Item test3 = new Item(); test3.name = "长剑"; test3.price = 350; System.out.println("物品名称"+"\t"+"物品价格"); System.out.println(test1.name+"\t\t"+test1.price); System.out.println(test2.name+"\t\t"+test2.price); System.out.println(test3.name+"\t\t"+test3.price); } } javaPlayer 跳转到问题位置 答案时间:2023-01-03 代码超过 5行,点击查看 public class Item { String name; int price; public static void main(String[] args) { Item bloodBottle = new Item(); bloodBottle.name = "Blood bottle"; bloodBottle.price = 50; Item strawSandals = new Item(); strawSandals.name = " Straw sandals"; strawSandals.price = 300; Item longSword = new Item(); longSword.name = "Long sword"; longSword.price = 350; } } 学习使我快乐999 跳转到问题位置 答案时间:2022-12-27 package java.javase.javase-demo.面向对象; public class mianixangduixiang { String name;//名称 int price;//价格 String effect;//作用 public static void main (String[]args){ mianixangduixiang xueping=new mianixangduixiang();//创建了血瓶 xueping.name="血瓶"; xueping.price=50; xueping.effect="回复血量100hp"; mianixangduixiang caoxie=new mianixangduixiang(); caoxie.name="草鞋"; caoxie.price=300; caoxie.effect="增加移动速度30"; mianixangduixiang changjian=new mianixangduixiang(); changjian.name="长剑"; changjian.price=500; changjian.effect="增加攻击力10"; System.out.println(); } 代码超过 5行,点击查看 package java.javase.javase-demo.面向对象; public class mianixangduixiang { String name;//名称 int price;//价格 String effect;//作用 public static void main (String[]args){ mianixangduixiang xueping=new mianixangduixiang();//创建了血瓶 xueping.name="血瓶"; xueping.price=50; xueping.effect="回复血量100hp"; mianixangduixiang caoxie=new mianixangduixiang(); caoxie.name="草鞋"; caoxie.price=300; caoxie.effect="增加移动速度30"; mianixangduixiang changjian=new mianixangduixiang(); changjian.name="长剑"; changjian.price=500; changjian.effect="增加攻击力10"; System.out.println(); } 莫諾 跳转到问题位置 答案时间:2022-12-26 练习-Item 创建(实例化)3件具体物品 名称 价格 血瓶 50 草鞋 300 长剑 350 代码超过 5行,点击查看 public class Item{ String name; //名字 int price; //价格 public static void main(String[] args){ Item Bloodbot = new Item(); Bloodbot.name = "血瓶"; Bloodbot.price = 50; Item Grassshoe = new Item(); Grassshoe.name = "草鞋"; Grassshoe.price = 300; Item Longsword = new Item(); Longsword.name = "长剑"; Longsword.price = 350; } } Bingod 跳转到问题位置 答案时间:2022-12-22 代码超过 5行,点击查看 class Item{//物品类 String name; int price; public static void main(String[]args){ Item bloodVial=new Item();//创建了血瓶 bloodVial.name="血瓶"; bloodVial.price=50; Item grassShoe=new Item();//创建了草鞋 grassShoe.name="草鞋"; grassShoe.price=300; Item longSword=new Item();//创建了长剑 longSword.name="长剑"; longSword.price=350; } } 天亮讲晚安 跳转到问题位置 答案时间:2022-12-20 代码超过 5行,点击查看 public class Item { //姓名 private String name; //价格 private int price; public static void main(String[] args) { Item blood = new Item(); blood.name = "血瓶"; blood.price = 50; Item shoes = new Item(); shoes.name = "草鞋"; shoes.price = 300; Item jian = new Item(); jian.name = "长剑"; jian.price = 350; } } M156427895 跳转到问题位置 答案时间:2022-12-11 package xu; public class Item { String name;//物品名字 int price;//物品价格 public static void main(String[] args) { Item xuping =new Item(); xuping.name="血瓶"; xuping.price=50; Item caoxie =new Item(); caoxie.name="草鞋"; caoxie.price=300; Item changjian =new Item(); changjian.name="长剑"; changjian.price=350; System.out.println("第一件物品:"+xuping.name+xuping.price+"元"); System.out.println("第二件物品:"+ caoxie.name+caoxie.price+"元"); System.out.println("第三件物品:"+changjian.name+changjian.price+"元"); }//end main }//end Item 猿某人 跳转到问题位置 答案时间:2022-12-09 public class Item { String name; int price; public static void main(String[] args){ Item xueping=new Item(); xueping.name="血瓶"; xueping.price=50; Item caoxie=new Item(); caoxie.name="草鞋"; caoxie.price=300; Item changjian=new Item(); changjian.name="长剑"; changjian.price=350; } } 代码超过 5行,点击查看 public class Item { String name; int price; public static void main(String[] args){ Item xueping=new Item(); xueping.name="血瓶"; xueping.price=50; Item caoxie=new Item(); caoxie.name="草鞋"; caoxie.price=300; Item changjian=new Item(); changjian.name="长剑"; changjian.price=350; } } 巴特 跳转到问题位置 答案时间:2022-12-06 Hero是一个类,你没有编这个类 类用class修饰 public class是主类 你编的是low主类里面的字段, 并没有编Hero类 胖水龙 跳转到问题位置 答案时间:2022-11-21 代码超过 5行,点击查看 public class Item{ String name; Int blood; } public static vaid main(string[] args){ Item xp = new Item(); xp.name = 血瓶; xp.price = 50; Item cx = new Item(); cx.name = 草鞋; cx.price = 300; Item cj = new Item(); cj.name = 长剑; cj.price = 350; } itniko 跳转到问题位置 答案时间:2022-11-18 public class Item{ String name; Int price; } pbulic static void main(String[ ] args){ Item xuepin=new Item; xuepin.name="血瓶"; xuepin.price=50; Item caoxie=new Item; caoxie.name="草鞋"; caoxie.price=300; Item changjian=new Item; changjian.name="长剑"; changjian.price=350; } 代码超过 5行,点击查看 public class Item{ String name; Int price; } pbulic static void main(String[ ] args){ Item xuepin=new Item; xuepin.name="血瓶"; xuepin.price=50; Item caoxie=new Item; caoxie.name="草鞋"; caoxie.price=300; Item changjian=new Item; changjian.name="长剑"; changjian.price=350; }

请先登陆 回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢

删除提问已经提交成功,正在审核, 谢谢. 回复提问已经提交成功,正在审核, 谢谢. 2022-09-23 代码 小妖哪里跑

关于 JAVA 基础-面向对象-类和对象 的提问 package 练习; public class ltem { String name; int price; public static void main(String[] argm) { ltem xp = new ltem(); xp.name = 血瓶; xp.price = 50; ltem cx = new ltem(); cx.name = 草鞋; cx.price = 300; ltem cj = new ltem(); cj.name = 长剑; cj.price = 350; } }

14 个答案 怪异的羊 跳转到问题位置 答案时间:2023-02-23 添加了构造方法,如果考试,我肯定按照题目要求来 代码超过 5行,点击查看 public class Item { private String name; //姓名 private int price; //价格 public Item() { } public Item(String name, int price) { this.name = name; this.price = price; } public static void main(String[] args) { Item item1=new Item("血瓶",50); Item item2=new Item("草鞋",300); Item item3=new Item("长剑",350); } } jiangnanyis 跳转到问题位置 答案时间:2023-02-01 代码超过 5行,点击查看 public class Item { String name; int price; public static void main(String[] args) { Item bloodVial = new Item(); bloodVial.name = "血瓶"; bloodVial.price = 50; Item sandals = new Item(); sandals.name = "草鞋"; sandals.price = 300; Item sword = new Item(); sword.name = "长剑"; sword.price = 350; System.out.println(bloodVial.name+bloodVial.price); } } HBong 跳转到问题位置 答案时间:2023-01-29 代码超过 5行,点击查看 import java.util.Scanner; public class Item{ String name; int price; String howPay; public static void main(String[]args){ Item Apple=new Item(); Apple.name="苹果"; Apple.price=15; Apple.howPay="Cash"; Item Banana=new Item(); Banana.name="香蕉"; Banana.price=30; Banana.howPay="WechatPay"; Item Orange=new Item(); Orange.name="橘子"; Orange.price=30; Orange.howPay="Credit"; System.out.printf("类中有3个项目包括“Apple”、“Banana”、“Orange”,请选择:"); Scanner sc=new Scanner(System.in); String ChoseItem=sc.next(); switch (ChoseItem){ case "Apple": System.out.printf("名字:%s\n价格:%d\n支付方式:%s",Apple.name,Apple.price,Apple.howPay); break; case "Banana": System.out.printf("名字:%s\n价格:%d\n支付方式:%s",Banana.name,Banana.price,Banana.howPay); break; case "Orange": System.out.printf("名字:%s\n价格:%d\n支付方式:%s",Orange.name,Orange.price,Orange.howPay); break; default: break; } } } 左耳进右耳出 跳转到问题位置 答案时间:2023-01-06 public class Item { String name; int price; public static void main(String[] args) { Item blood = new Item(); blood.name = "血瓶"; blood.price = 50; System.out.println("装备名:"+blood.name+"\t"+blood.price+"金币"); Item straw = new Item(); straw.name = "草鞋" ; straw.price = 300; System.out.println("装备名:"+straw.name+"\t"+straw.price+"金币"); Item rapier = new Item(); rapier.name = "长剑"; rapier.price = 350; System.out.println("装备名:"+rapier.name+"\t"+rapier.price+"金币"); } } lanren9 跳转到问题位置 答案时间:2022-11-08 代码超过 5行,点击查看 public class Item{ String name;//名字 int price;//价格 public static void main(String args[]){ Item xueping = new Item(); xueping.name = "血瓶"; xueping.price = 50; Item caoxie = new Item(); caoxie.name = "草鞋"; caoxie.price = 300; Item changjian = new Item(); changjian.name = "长剑"; changjian.price = 350; } } ybysl 跳转到问题位置 答案时间:2022-11-02 //定义一个Hero的类 public class Hero { String name;//英雄的姓名 float hp;//血量 float armor;//护甲 int moveSpeed;//移动速度 int money;//金钱 //这是一个无参的构造方法 public Hero() { } //有参的构造方法 public Hero(String name, float hp, float armor, int moveSpeed) { this.name = name; this.hp = hp; this.armor = armor; this.moveSpeed = moveSpeed; } public static void main(String[] args) { //创建garen这个类 Hero garen = new Hero(); garen.name = "盖伦"; garen.hp = 616; garen.armor = 27; garen.moveSpeed = 350; System.out.println("英雄的名字="+garen.name); System.out.println("英雄的血量="+garen.hp); System.out.println("英雄的护甲="+garen.armor); System.out.println("英雄的移动速度="+garen.moveSpeed); //创建一个temo这个类 Hero temo = new Hero(); temo.name = "提莫"; temo.hp = 616; temo.armor = 27; temo.moveSpeed = 350; System.out.println("英雄的名字="+temo.name); System.out.println("英雄的血量="+temo.hp); System.out.println("英雄的护甲="+temo.armor); System.out.println("英雄的移动速度="+temo.moveSpeed); } } dyf-- 跳转到问题位置 答案时间:2022-11-02 代码超过 5行,点击查看 package practice; public class Item { String name; int price ; static public void main(String [] args) { Item item1=new Item(); item1.name="bloodBottle"; item1.price=50; Item item2=new Item(); item2.name="grassShoes"; item2.price=300; Item item3=new Item(); item3.name="sword"; item3.price=350; } Tt007 跳转到问题位置 答案时间:2022-10-27 public class Item { String name; int price; Item(String name,int price) { this.name=name; this.price=price; } void print() { System.out.println("name="+name+" "+"price="+price); } } class Main { public static void main(String[] args) { Item blood=new Item("血瓶",50); Item shoes = new Item("草鞋",300); Item saw = new Item("长剑",350); blood.print(); shoes.print(); saw.print(); } } 南苛 跳转到问题位置 答案时间:2022-10-26 package practice;//前端 class Item { String name; int price ; } public class five { public static void main(String[] args) { Item item1=new Item(); item1.name="bloodBottle"; item1.price=50; Item item2=new Item(); item2.name="grassShoes"; item2.price=300; Item item3=new Item(); item3.name="sword"; item3.price=350; } } bone_xxy 跳转到问题位置 答案时间:2022-10-23 代码超过 5行,点击查看 public class Item { String name; int price; public static void main(String[] args) { // TODO Auto-generated method stub Item bloodbottle = new Item(); bloodbottle.name = "血瓶"; bloodbottle.price = 50; Item shoes = new Item(); shoes.name = "草鞋"; shoes.price = 300; Item sward = new Item(); sward.name = "长剑"; sward.price = 350; } } he11oworld 跳转到问题位置 答案时间:2022-10-21 public class Item{ String name; int price; public static void main(String[] args) { Item xp = new Item(); xp.name = "血瓶"; xp.price = 50; Item cx = new Item(); cx.name = "草鞋"; cx.price = 300; Item cj = new Item(); cj.name = "长剑"; cj.price = 350; } } 5影 跳转到问题位置 答案时间:2022-10-17 代码超过 5行,点击查看 public class lx8 { public static void main(String[] args) { item i1=new item("血瓶",50); item i2=new item("草鞋",300); item i3=new item("长剑",350); System.out.println(i1.toString()); System.out.println(i2.toString()); System.out.println(i3.toString()); } } class item{ String name; int price; public item(String name, int price) { this.name = name; this.price = price; } @Override public String toString() { return "名称:"+name+";价格:"+price; } } llw乌哈怪 跳转到问题位置 答案时间:2022-10-11 package hero; public class Item { String name;//名称 int price;//价格 public static void main (String[] args){ Item xueping = new Item(); xueping.name = "血瓶"; xueping.price = 50; Item caoxie = new Item(); caoxie.name = "草鞋"; caoxie.price = 300; Item changjian = new Item(); changjian.name = "长剑"; changjian.price = 350; } } 5217 跳转到问题位置 答案时间:2022-10-05 代码超过 5行,点击查看 public class Item { String name;//名称 int price;//价格 public static void main(String[] args) { Item xueping = new Item(); xueping.name = "血瓶"; xueping.price = 50; Item caoxie = new Item(); caoxie.name = "草鞋"; caoxie.price = 300; Item changjian = new Item(); changjian.name = "长剑"; changjian.price = 350; } }

请先登陆 回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢 删除提问已经提交成功,正在审核, 谢谢. 回复提问已经提交成功,正在审核, 谢谢. 2022-09-14 本题回答 asdawc

关于 JAVA 基础-面向对象-类和对象 的提问

问题 截图 代码 异常 问题答案 public class Item { String name; int price; public static void main(String[] args){ Item hpBottle = new Item(); hpBottle.name = "血瓶"; hpBottle.price = 50; Item shoes = new Item(); shoes.name = "草鞋"; shoes.price = 300; Item longSword = new Item(); longSword.name = "长剑"; longSword.price = 350; } }

17 个答案 054941LZL_lp 跳转到问题位置 答案时间:2023-03-16 Item.java public class Item { public String name; public int price; } demo.java public class Demo { public static void main() { Item xueping = new Item(); xueping.name = "血瓶"; xueping.price = 50; System.out.println("name: " + xueping.name + "\t price: " + xueping.price); Item caoxie = new Item(); caoxie.name = "草鞋"; caoxie.price = 300; System.out.println("name: " + caoxie.name + "\t price: " + caoxie.price); Item changjian = new Item(); changjian.name = "长剑"; changjian.price = 350; System.out.println("name: " + changjian.name + "\t price: " + changjian.price); } } M156427895 跳转到问题位置 答案时间:2022-12-11 代码超过 5行,点击查看 package xu; public class Item { String name;//物品名字 int price;//物品价格 public static void main(String[] args) { Item xuping =new Item(); xuping.name="血瓶"; xuping.price=50; Item caoxie =new Item(); caoxie.name="草鞋"; caoxie.price=300; Item changjian =new Item(); changjian.name="长剑"; changjian.price=350; System.out.println("第一件物品:"+xuping.name+xuping.price+"元"); System.out.println("第二件物品:"+ caoxie.name+caoxie.price+"元"); System.out.println("第三件物品:"+changjian.name+changjian.price+"元"); }//end main }//end Item ybysl 跳转到问题位置 答案时间:2022-11-02 代码超过 5行,点击查看 //定义一个Hero的类 public class Hero { String name;//英雄的姓名 float hp;//血量 float armor;//护甲 int moveSpeed;//移动速度 int money;//金钱 //这是一个无参的构造方法 public Hero() { } //有参的构造方法 public Hero(String name, float hp, float armor, int moveSpeed) { this.name = name; this.hp = hp; this.armor = armor; this.moveSpeed = moveSpeed; } public static void main(String[] args) { //创建garen这个类 Hero garen = new Hero(); garen.name = "盖伦"; garen.hp = 616; garen.armor = 27; garen.moveSpeed = 350; System.out.println("英雄的名字="+garen.name); System.out.println("英雄的血量="+garen.hp); System.out.println("英雄的护甲="+garen.armor); System.out.println("英雄的移动速度="+garen.moveSpeed); //创建一个temo这个类 Hero temo = new Hero(); temo.name = "提莫"; temo.hp = 616; temo.armor = 27; temo.moveSpeed = 350; System.out.println("英雄的名字="+temo.name); System.out.println("英雄的血量="+temo.hp); System.out.println("英雄的护甲="+temo.armor); System.out.println("英雄的移动速度="+temo.moveSpeed); } } 南苛 跳转到问题位置 答案时间:2022-10-26 package practice; public class Item { String name; int price ; static public void main(String [] args) { Item item1=new Item(); item1.name="bloodBottle"; item1.price=50; Item item2=new Item(); item2.name="grassShoes"; item2.price=300; Item item3=new Item(); item3.name="sword"; item3.price=350; } } 关东 跳转到问题位置 答案时间:2022-10-17 代码超过 5行,点击查看 public class Item { String name; int price; public static void main(String[] args) { Item xueping = new Item(); xueping.name = "血瓶"; xueping.price = 50; Item caoxie = new Item(); caoxie.name = "草鞋"; caoxie.price = 300; Item changjian = new Item(); changjian.name = "长剑"; changjian.price = 350; } } rebirth_0703 跳转到问题位置 答案时间:2022-10-15 代码超过 5行,点击查看 public class Item { String name; int price; public static void main(String args[]){ Item i1=new Item(); i1.name="血瓶"; i1.price=50; Item i2=new Item(); i2.name="草鞋"; i2.price=300; Item i3=new Item(); i3.name="长剑"; i3.price=350; System.out.println("物品:"+i1.name); System.out.println("价格:"+i1.price); System.out.println(); System.out.println("物品:"+i2.name); System.out.println("价格:"+i2.price); System.out.println(); System.out.println("物品:"+i3.name); System.out.println("价格:"+i3.price); } } 守狞 跳转到问题位置 答案时间:2022-10-14 public class Item{ String name; int price; public static void main (String[] args){ Item bloodBottle=new Item(); bloodBottle.name="血瓶"; bloodBottle.price=50; Item strawSandals=new Item(); strawSandals.name="草鞋"; strawSandals.price=300; Item longSword=new Item(); longSword.name="长剑"; longSword.price=350; } } 敲不出代码 跳转到问题位置 答案时间:2022-10-02 class Item { String name; int price; void read(){ System.out.println("商品:"+name+",价格"+price); } } class Test { public static void main(String[] args) { Item bloodVials = new Item(); bloodVials.name = "血瓶"; bloodVials.price = 50; Item sandals = new Item(); sandals.name = "草鞋"; sandals.price = 300; Item sword = new Item(); sword.name = "长剑"; sword.price = 350; bloodVials.read(); sandals.read(); sword.read(); } } 湖南_1深情 跳转到问题位置 答案时间:2022-09-26 public class Hero { private String name; private float hp; private float armor; private int moveSpeed; public Hero(){} public Hero(String name, float hp, float armor, int moveSpeed) { this.name = name; this.hp = hp; this.armor = armor; this.moveSpeed = moveSpeed; } public String getName() { return name; } public float getHp() { return hp; } public float getArmor() { return armor; } public int getMoveSpeed() { return moveSpeed; } public void setName(String name) { this.name = name; } public void setHp(float hp) { this.hp = hp; } public void setArmor(float armor) { this.armor = armor; } public void setMoveSpeed(int moveSpeed) { this.moveSpeed = moveSpeed; } public static void main(String[] args) { Hero garen =new Hero("盖伦",616.28f,27.536f,350); Hero teemo = new Hero("提莫",383f,14f,330); Item item1 = new Item("血瓶",50); Item item2 = new Item("长剑",350); Item item3 = new Item("草鞋",300); } } class Item{ private String name; private int price; public Item(String name,int price) { this.name = name; this.price = price; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } } Yanshao5721 跳转到问题位置 答案时间:2022-09-26 设计出物品这种类 类名:Item 物品有如下属性: 名字 name 类型是字符串String 价格 price 类型是整型 int 创建(实例化)3件具体物品 名称 价格 血瓶 50 草鞋 300 长剑 350 代码超过 5行,点击查看 public class Item{ String name; int price; public static void main(String[] args){ Item Bloodbottle = new Item(); Bloodbottle.name = "血瓶"; Bloodbottle.price = 50; Item Strawsandals = new Item(); Strawsandals.name = "草鞋"; Strawsandals.price = 300; Item Longsword = new Item(); Longsword.name = "长剑"; Longsword.price = 350; } } 风很大 跳转到问题位置 答案时间:2022-09-24 public class demo7 { private String name; private int price; public static void main(String[] args) { demo7 xp=new demo7(); xp.name="血瓶"; xp.price=50; demo7 cx=new demo7(); cx.name="草鞋"; cx.price=300; demo7 tj=new demo7(); tj.name="长剑"; tj.price=350; } } zeros000 跳转到问题位置 答案时间:2022-09-24 代码超过 5行,点击查看 public class Item { String name; int price; public static void main(String[] args) { Item bloodVials = new Item(); bloodVials.name = "血瓶"; bloodVials.price = 50; Item sandals = new Item(); sandals.name = "草鞋"; sandals.price = 300; Item sword = new Item(); sword.name = "长剑"; sword.price = 350; } } 雨泽06 跳转到问题位置 答案时间:2022-09-22 public class ltem { String name; int price; public static void main(String[] args){ Item Bloodbottle = new Item(); Bloodbottle.name = "血瓶"; Bloodbottle.price = 50; Item Strawsandals = new Item(); Strawsandals.name = "草鞋"; Strawsandals.price = 300; Item Longsword = new Item(); Longsword.name = "长剑"; Longsword.price = 350; } } 罗启佳 跳转到问题位置 答案时间:2022-09-19 代码超过 5行,点击查看 public class Item { String name; int price; public static void main(String[] args) { Item xueping = new Item(); xueping.name="血瓶"; xueping.price=50; Item caoxie = new Item(); caoxie.name="草鞋"; caoxie.price=300; Item changjian = new Item(); changjian.name="长剑"; changjian.price=350; } } 昭昭困了 跳转到问题位置 答案时间:2022-09-19 代码超过 5行,点击查看 public class Ltem { String name; int price; public static void main(String[] args) { Ltem Xueping=new Ltem(); Ltem xieping = new Ltem(); xieping.name="血瓶"; xieping.price=50; Ltem caoxie =new Ltem(); caoxie.name="草鞋"; caoxie.price=300; Ltem changjian=new Ltem(); changjian.name="长剑"; changjian.price=350; } } Dissolute 跳转到问题位置 答案时间:2022-09-16 代码超过 5行,点击查看 public class item { String name; int price; public static void main(String[] args) { item xueping=new item(); xueping.name="血瓶"; xueping.price=50; item changjian=new item(); changjian.name="长剑"; changjian.price=250; item caoxie=new item(); caoxie.name="草鞋"; caoxie.price=250; } } 无bagel 跳转到问题位置 答案时间:2022-09-14 代码超过 5行,点击查看 public class Item { String name; int price; public static void main(String[] args) { Item xieping = new Item(); xieping.name="血瓶"; xieping.price=50; Item caoxie =new Item(); caoxie.name="草鞋"; caoxie.price=300; Item changjian=new Item(); changjian.name="长剑"; changjian.price=350;

请先登陆 回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢

删除提问已经提交成功,正在审核, 谢谢. 回复提问已经提交成功,正在审核, 谢谢. 2022-08-29 答 Josuke2pp

关于 JAVA 基础-面向对象-类和对象 的提问 public class Item { String name; int price; public static void main(String[] args){ Item Bloodbottle = new Item(); Bloodbottle.name = "血瓶"; Bloodbottle.price = 50; Item Strawsandals = new Item(); Strawsandals.name = "草鞋"; Strawsandals.price = 300; Item Longsword = new Item(); Longsword.name = "长剑"; Longsword.price = 350; } }

10 个答案 开八月 跳转到问题位置 答案时间:2023-01-30 public class Item { String name; int price; public static void main(String[] args) { Item xiePing=new Item(); xiePing.name="血瓶"; xiePing.price=50; Item caoXie=new Item(); caoXie.name="草鞋"; caoXie.price=300; Item changJian=new Item(); changJian.name="长剑"; changJian.price=350; } } Hyyyyz 跳转到问题位置 答案时间:2022-12-04 public class ltem { String name; int price; public static void main(String[] args) { ltem xueping = new ltem(); xueping.name = ("血瓶"); xueping.price = 50 ; ltem caoxie = new ltem(); caoxie.name = ("草鞋"); caoxie.price = 300 ; ltem changjian = new ltem(); changjian.name = ("长剑"); changjian.price = 350; } } 代码超过 5行,点击查看 public class ltem { String name; int price; public static void main(String[] args) { ltem xueping = new ltem(); xueping.name = ("血瓶"); xueping.price = 50 ; ltem caoxie = new ltem(); caoxie.name = ("草鞋"); caoxie.price = 300 ; ltem changjian = new ltem(); changjian.name = ("长剑"); changjian.price = 350; } } 德州king 跳转到问题位置 答案时间:2022-09-27 public class Item{ String name; int price; public static void main (String[] args){ Item Bloodbottle=new Item(); Bloodbottle.name="血瓶"; Bloodbottle.price=50; Item Strawsandals=new Item(); Strawsandals.name="草鞋"; Strawsandals.price=300; Item Longsword=new Item(); Longsword.name="长剑"; Longsword.price=350; } } 小妖哪里跑 跳转到问题位置 答案时间:2022-09-23 package 练习; public class ltem { String name; int price; public static void main(String[] argm) { ltem xp = new ltem(); xp.name = 血瓶; xp.price = 50; ltem cx = new ltem(); cx.name = 草鞋; cx.price = 300; ltem cj = new ltem(); cj.name = 长剑; cj.price = 350; } } sdfsd_hg 跳转到问题位置 答案时间:2022-09-21 代码超过 5行,点击查看 public class Ltem { String name; int price; public static void main(String[] ares){ Ltem xp= new Ltem(); xp.name="血瓶"; xp.price=50; Ltem cx= new Ltem(); cx.name="草鞋"; cx.price=300; Ltem cj= new Ltem(); cj.name="长剑"; cj.price=350; System.out.print(xp.name); } } Mome 跳转到问题位置 答案时间:2022-09-21 public class Item{ String name; int price; public static void(String[] agrs){ Item Xp = new Item(); Xp.name = "xieping"; Xp.price = 50; Item Cx = new Item(); Cx.name = "caoxie"; Cx.price = 300; Item Cj = new Item(); Cj.name = "changjian"; Cj.price = 350; } } how2j6578976 跳转到问题位置 答案时间:2022-09-18 package PracticeTest; public class Test02 { public static void main(String[] args) { Items item = new Items(); item.setName("Flower"); item.setPrice(20); } } class Items{ String name; int price; public void setName(String name){ this.name = name } public void setPrice(int price) { this.price = price; } public String getName() { return name; } public int getPrice() { return price; } } wilsonx 跳转到问题位置 答案时间:2022-09-13 代码超过 5行,点击查看 public class Item { String name; Integer price; public static void main(String[] args) { Item bloodBottle = new Item(); bloodBottle.name="血瓶"; bloodBottle.price=50; Item shoes = new Item(); shoes.name="草鞋"; shoes.price=300; Item sword = new Item(); sword.name = "长剑"; sword.price=350; } } 热巴巴巴巴 跳转到问题位置 答案时间:2022-09-06 public class Item { String name; int price; public static void main(String[] args) { Item bottle=new Item(); bottle.name="血瓶"; bottle.price=50; Item shoes=new Item(); shoes.name="草鞋"; shoes.price=300; Item sword=new Item(); sword.name="长剑"; sword.price=350; } } 代码超过 5行,点击查看 public class Item { String name; int price; public static void main(String[] args) { Item bottle=new Item(); bottle.name="血瓶"; bottle.price=50; Item shoes=new Item(); shoes.name="草鞋"; shoes.price=300; Item sword=new Item(); sword.name="长剑"; sword.price=350; } } 幻梦12138 跳转到问题位置 答案时间:2022-09-03 public class item{ String name; int price; public static void main(String args[]){ item Blood = new item(); Blood.name = "血瓶"; Blood.price = 50; item Strawsandals = new item(); Strawsandals.name = "草鞋"; Strawsandals.price = 300; item Longsword = new item(); Longsword.name = "长剑"; Longsword.price = 350; } }

请先登陆 回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢 删除提问已经提交成功,正在审核, 谢谢. 回复提问已经提交成功,正在审核, 谢谢. 2022-07-30 1 AZX6669

关于 JAVA 基础-面向对象-类和对象 的提问 package lei; public class Item { String name; int price; public static void main(String [] args) { Item bloodbottle=new Item(); bloodbottle.name="血瓶"; bloodbottle.price=50; Item Strawsandals=new Item(); Strawsandals.name="草鞋"; Strawsandals.price=100; Item Longsword=new Item(); Longsword.name="长剑"; Longsword.price=350; } }

8 个答案 小白变大佬 跳转到问题位置 答案时间:2022-11-13 代码超过 5行,点击查看 public class Item { private String name; private int price; public void setName(String name){ this.name=name; } public String getName(){ return name; } public void setPrice(int price){ this.price=price; } public int getPrice() { return price; } public void show(){ System.out.println(name+price); } } public class Main { public static void main(String[] args) { Item a=new Item(); a.setName("血瓶"); a.setPrice(50); a.show(); Item b=new Item(); b.setName("草鞋"); b.setPrice(300); b.show(); Item c=new Item(); c.setName("长剑"); c.setPrice(350); c.show(); } } 雷霆蛛丝 跳转到问题位置 答案时间:2022-09-04 public class Item{ String name; int price; public static void main(String args[]){ Item Bloodbottle = new Item(); Bloodbottle.name = "血瓶"; Bloodbottle.price = 50; Item Strawsandals = new Item(); Strawsandals.name = "草鞋"; Strawsandals.price = 300; Item Longsword = new Item(); Longsword.name = "长剑"; Longsword.price = 350; } } 不学习变垃圾 跳转到问题位置 答案时间:2022-08-30 代码超过 5行,点击查看 public class Item {//物品类 //物品的属性有名字,价格 String name; //名字 float price; //价格 public static void main(String[] args) {//主类 //创建三件具体物品 Item hpbottle = new Item(); //new调用物品类赋值给血瓶 hpbottle.name = "血瓶"; hpbottle.price = 50; Item grassshoes = new Item(); grassshoes.name = "草鞋"; grassshoes.price = 300; Item longsword = new Item(); longsword.name = "长剑"; longsword.price = 350; } } zhuzhulllll 跳转到问题位置 答案时间:2022-08-29 public class Ltem { String name; //名称 int price; //价格 public static void main(String[] args) { ltem bloodbottle = new ltem(); bloodbottle.name = "血瓶"; bloodbottle.price= 50; ltem strawsandals = new ltem(); strawsandals.name = "草鞋"; strawsandals.price = 300; ltem longsword = new ltem(); longsword.name = "长剑”; longsword.price = 350 } } zhuiYeah 跳转到问题位置 答案时间:2022-08-25 public class Item { String name; int price; public Item(String name, int price) { this.name = name; this.price = price; } public static void main(String[] args) { Item item1 = new Item("BloodVial", 50); Item item2 = new Item("GrassShoes", 300); Item item3 = new Item("LongSword", 350); } } 海蓝蓝心爽爽 跳转到问题位置 答案时间:2022-08-22 package com.weiliang; public class Item { private String name; private int price; public static void main(String[] args) { Item item = new Item(); item.name = "血瓶"; item.price = 50; Item item1 = new Item(); item1.name = "草鞋"; item1.price = 300; Item item2 = new Item(); item2.name = "长剑"; item2.price = 350; System.out.println(item.name + item.price); System.out.println(item1.name + item1.price); System.out.println(item2.name + item2.price); } } 花花hk 跳转到问题位置 答案时间:2022-08-10 public class Item { // 设计出物品这种类 // 类名:Item // 物品有如下属性: // 名字 name 类型是字符串String // 价格 price 类型是整型 int // // 创建(实例化)3件具体物品 // 名称 价格 // 血瓶 50 // 草鞋 300 // 长剑 350 String name;//姓名 int price;//价格 public static void main(String[] args) { Item bloodbottle = new Item(); bloodbottle.name="血瓶"; bloodbottle.price=50; Item strawsandals = new Item(); strawsandals.name="草鞋"; strawsandals.price=300; Item longsword = new Item(); longsword.name="长剑"; longsword.price=350; } } 陈子豪 跳转到问题位置 答案时间:2022-08-04 public class ltem { String name; int price; public static void main(String[]args) { ltem bloodbottle = new ltem(); bloodbottle.name = "血瓶"; bloodblttle.price = 50; ltem strawsandals = new ltem(); strawsandals.name = 草鞋; strawsandals.price = 300; ltem lonesword = new ltem(); lonesword.name = "长剑"; lonesword.price = 350; }

请先登陆 回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢

提问太多,页面渲染太慢,为了加快渲染速度,本页最多只显示几条提问。还有 197 条以前的提问,请 点击查看

提问之前请登陆 提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有