First time Java Quiz

Source: Internet
Author: User

Define a King Glory member class Moba,
Its private data members have a blood volume of blood (initially 100), Attack Fire (initial 15), Defense defend (initial 10), sum of members already created (initialized to 0),
Public function members include eating eat (), Sport Sport (), Sleeping sleep (), getting the number getsum (), the former defeating the latter defeat (Moba A,moba b) "defeat rule: the former seizes the latter all, the latter clearing 0"
Among them, eat to make blood volume plus 50, exercise to attack damage plus 10, sleep to make defensive force plus 2.

The main function has been given, please write this class according to the main function.
public static void Main (string[] args) {
Moba m1=new Moba ();
System.out.println (Moba.getsum ());
System.out.println (m1.blood+ "" +m1.fire+ "" +m1.defend ");

Moba m2=new Moba ();
for (int i=0;i<15;i++) {
if (i<=6) {
M2.sport ();
}
if (i<=10) {
M2.sleep ();
}
else if (i<14) {
M2.eat ();
}
}
System.out.println (Moba.getsum ());
System.out.println (m2.blood+ "" +m2.fire+ "" +m2.defend ");
Moba.defeat (M1,M2);
System.out.println (m1.blood+ "" +m1.fire+ "" +m1.defend ");
System.out.println (m2.blood+ "" +m2.fire+ "" +m2.defend ");
}


Correct result:
1
100 15 10
2
250 85 32
350 100 42
0 0 0

// Here are the official answers .

Public class Hello {

Public Static class moba{

Private int blood=100;

Private int fire=15;

Private int defend=10;

Private Static int sum= 0;

Public void eat () {

blood+=50;

}

Public void Sport () {

fire+=10;

}

Public void sleep () {

defend+=2;

}

Moba () {

sum+ +;

}

Public Static int getsum () {

return sum;

}

Public Static void defeat (Moba A,moba b) {

A.blood+=b.blood;

A.fire+=b.fire;

A.defend+=b.defend;

B.blood=0;

B.defend=0;

b.fire=0;

}

};

The comment section is not given

Public Static void Main (string[] args) {

Moba m1=New Moba ();

System. out. println (Moba. Getsum());

System. out. println (m1.blood+ "" +m1.fire+ "" +m1.defend ");

Moba m2=New Moba ();

for (int i=0;i<15;i++) {

if (i<=6) {//7 times 7*10+ (original) 10

M2.sport ();

}

if (i<=10) {//11 times 11*2+ (original) 15

M2.sleep ();

}

Else if (I<14) {//3 times 3*50+ (original) 100

M2.eat ();

}

}

System. out. println (Moba. Getsum());

System. out. println (m2.blood+ "" +m2.fire+ "" +m2.defend ");

Moba. defeat (M1,M2);

System. out. println (m1.blood+ "" +m1.fire+ "" +m1.defend ");

System. out. println (m2.blood+ "" +m2.fire+ "" +m2.defend ");

}

}

Output answer

1

100 15 10

2

250 85 32

350 100 42

0 0 0

First time Java Quiz

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.