1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > java 多态应用 编写 LOL商店英雄购买

java 多态应用 编写 LOL商店英雄购买

时间:2020-12-29 11:22:05

相关推荐

java 多态应用 编写 LOL商店英雄购买

package dierzhou;import java.util.Scanner;class Heros{ String name;String Attribute;int price;public String getName() {//英雄return name;}public String getAttribute() {//属性return Attribute;}public int getPrice() {//英雄价格return price;}public void shanghai(){ //基础伤害}}class Ap extends Heros{@Overridepublic void shanghai() {// TODO Auto-generated method stubif(6000<this.price){System.out.println(this.name+"的基础伤害为150");}else if(3500<=this.price){System.out.println(this.name+"的基础伤害为145");}else if(450<=this.price){System.out.println(this.name+"的基础伤害为143");}}}class Ad extends Heros{@Overridepublic void shanghai() {// TODO Auto-generated method stubif(6000<this.price){System.out.println(this.name+"的基础伤害为152");}else if(3500<=this.price){System.out.println(this.name+"的基础伤害为146");}else if(450<=this.price){System.out.println(this.name+"的基础伤害为141");}}}class maste{ //多态public void toStr(Heros heros){heros.shanghai();}}public class LOL {public static void main(String[] args) {// TODO Auto-generated method stubmaste ma=new maste();System.out.println("*******|||LOL商店|||********");System.out.println("ap英雄有:沙皇 ¥6300 \t妖姬¥ 4800\t小法 ¥1350");Ap ap=new Ap();Scanner input=new Scanner(System.in);System.out.println("选择你要购买的ap英雄:");String h1=input.next();System.out.println("请进行付款:");int m1=input.nextInt();ap.name=h1;ap.price=m1;ap.Attribute="法师";System.out.println("恭喜你购买"+ap.getName()+"成功"+"\n付款金额为"+ap.getPrice()+"\n英雄属性:"+ap.getAttribute());ma.toStr(ap);//多态System.out.println("ad英雄有:蛮王 ¥6300 \t剑魔¥ 4800\t剑圣 ¥460");Ad ad=new Ad();System.out.println("选择你要购买的ad英雄");String h2=input.next();System.out.println("请进行付款:");int m2=input.nextInt();ad.name=h2;ad.price=m2;ad.Attribute="战士";System.out.println("恭喜你购买"+ad.getName()+"成功"+"\n付款金额为"+ad.getPrice()+"\n英雄属性:"+ad.getAttribute());ma.toStr(ad);}}

效果:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。