1.声明一个商品类父类,拥有编号,名称,和价格三个属性和 一个jiazhi()方法,在构造方法中对其进行赋值,打印所有商品 都有自己的价值。声明子类水果类,继承自商品类,重写jiazhi 方法,打印水果的价值是补充营养,声明电子类,继承自商品 类,重写jiazhi方法,打印电子类的价值是方便生活,声明苹 果,香蕉,vivo手机,小米手机,实例化各自的对象并打印其 jiazhi方法?/*命名要有具体的意义,比如用拼音或英文便于别人与自己看懂,查错。以上是使得逻辑上更简,更清晰。使得逻辑上或其他方面更简,更清晰就是Java oop等方法思想的作用好处。我写代码等事的原则方法是能简则简的原则。
*/
package a;
public class Student {
public static void main(String[] args) {
pingGuo p=new pingGuo("1","苹果", 1.5);
p.jiazhi();
xiangJiao x=new xiangJiao("2","香蕉", 1.6);
x.jiazhi();
boluo b=new boluo("3","菠萝", 1.7);
b.jiazhi();
boluo h=new boluo("3","华为手机", 3000);
h.jiazhi();
}
}
class shangPin{
public static String bianHao;
public String name;
public static double jaGe;
public shangPin(String bianHao,String name,double jaGe){
this.bianHao=bianHao;
this.jaGe=jaGe;
this.name=name;
}
public void jiazhi(){
System.out.println(this.name+"价格为"+this.jaGe);
System.out.println(this.name+"编号为"+this.bianHao);
System.out.println(this.name+"名字为"+this.name);
}
}
class shuiGuo extends shangPin{
public shuiGuo(String bianHao, String name, double jaGe) {
super(bianHao, name, jaGe);
// TODO Auto-generated constructor stub
}
public String waiGuan;
public void jiazhi(){
System.out.println(this.name+"价格为"+this.jaGe);
System.out.println(this.name+"编号为"+this.bianHao);
System.out.println(this.name+"名字为"+this.name);
}
}
class dianzi extends shangPin{
public dianzi(String bianHao, String name, double jaGe) {
super(bianHao, name, jaGe);
// TODO Auto-generated constructor stub
}
public String waiGuan;
public void jiazhi(){
System.out.println(this.name+"价格为"+this.jaGe);
System.out.println(this.name+"编号为"+this.bianHao);
System.out.println(this.name+"名字为"+this.name);
}
}
class pingGuo extends shuiGuo{
public pingGuo(String bianHao,String name,double jaGe) {
super(bianHao,name, jaGe);
System.out.println(this.name+"价值为令人聪明");
}
}
class xiangJiao extends shuiGuo{
public xiangJiao(String bianHao,String name,double jaGe) {
super(bianHao,name,jaGe);
System.out.println(this.name+"价值为令人通便");
}
}
class boluo extends shuiGuo{
public boluo (String bianHao,String name,double jaGe) {
super(bianHao,name,jaGe);
System.out.println(this.name+"价值为令人爽快");
}
}
//2.声明一个人物模型类,拥有人物名称,攻击力,防御力,和 技能(查询自身数据),
//声明一个战士类继承人物模型类,战 士拥有自己的技能1(技能伤害为100+自身攻击力的120%),
//声 明法师类继承自人物模型类,法师拥有自己的两个技能,技能1
//(技能伤害为200+自身攻击力80%),
//技能2(自身防御力提升 20%),实例化三个英雄,分别调用自己的每个技能
package a;
public class Student {
public static void main(String[] args) {
liuBei l=new liuBei("刘备",100,100);
l.zhi();
l.faShiJiNengYi();
l.faShiJiNengEr();
guanYu g=new guanYu ("关羽",101,102);
g.zhi();
g.jiNengY();
zhangFei z=new zhangFei("张飞",104,105);
z.zhi();
z.jiNengY();
}
}
class renWuMoXing{
public String name;
public double gongJiLi;
public double fangYuLi;
public renWuMoXing(String name,double gongJiLi,double fangYuLi){
this.name=name;
this.gongJiLi=gongJiLi;
this.fangYuLi=fangYuLi;//有红色部分才可以接收到数据,并调用
}
public void zhi(){
System.out.println(this.name+"攻击力为"+gongJiLi);//this用
System.out.println(this.name+"防御力"+fangYuLi);
}
}
class zhanShi extends renWuMoXing{
public zhanShi(String name,double gongJiLi,double fangYuLi) {
super(name, gongJiLi,fangYuLi);
// TODO Auto-generated constructor stub
}
}
class faShi extends renWuMoXing{
public faShi(String name,double gongJiLi,double fangYuLi) {
super(name, gongJiLi,fangYuLi);
/*TODO Auto-generated constructor stub(指的是自动生成的构造函数。
这串英文在使用eclipse这样的Java集成开发环境时开发环境自动帮使用者写的,意思是告诉使用者这些代码是自动生成的,不是自己编写的,起到一个提示的作用,实际意义不大。)*/
}
}
class liuBei extends faShi{
public liuBei(String name,double gongJiLi,double fangYuLi) {
super(name, gongJiLi,fangYuLi);
}
public void faShiJiNengYi(){
System.out.println(this.name+"法师技能一名:王剑 , 技能伤害:"+(200+0.8*gongJiLi));
}
public void faShiJiNengEr(){
System.out.println(this.name+"法师技能二名:王权 , 防御力提升"+fangYuLi*0.2);
}
}
class guanYu extends zhanShi{
public guanYu(String name,double gongJiLi,double fangYuLi) {
super(name, gongJiLi,fangYuLi);
}
public void jiNengY(){
System.out.println(this.name+"战士技能一名:将刀 , 技能伤害:"+(this.gongJiLi*1.2+100));
}
}
class zhangFei extends zhanShi{
public zhangFei(String name,double gongJiLi,double fangYuLi) {
super(name, gongJiLi,fangYuLi);
}
public void jiNengY(){
System.out.println(this.name+"战士技能一名:将斧 , 技能伤害:"+(this.gongJiLi*1.2+100));
}
}