Java language is a language, in my opinion when programming in order to realize various functions are mainly based on object, for programming classes and objects, first of all should know what is the object, what is the class of objects is the so-called: in real life as long as it is a concrete object or a specific thing is the so-called Everything is an object of a object. The class is a class of things, according to the object of similar characteristics and classifies the similar behaviors, the wider the scope of the class while after be instantiated according to a specific thing, classes in the corresponding program is: class is in the program according to the characteristics of the object in life and behavior, according to the definition of the fixed format of program templates, application class is composed of two parts: 1. The attributes: is defined by the characteristics of the object; : 2. The method is defined by the conduct of the object to define the class, need instance into concrete object can implement specific methods, specific syntax for instantiation objects: the name of the class object name=new class name (); Call the properties and methods of specific syntax is: object name. The property name object name. The method name (parameter type parameter names... ); Writing classes and objects carried out program is divided into the following steps: 1, find out the characteristics of the object in the scene and the objects and actions, for example, the following simple a scene like this: "altman and PK little monsters, until the end of the blood to zero by a party fighting, who output victory!" There are two objects, altman and little monsters, respectively corresponding to the different characteristics and behavior, including altman characteristics: HP, name (Ottoman), damage behavior: combat (little monsters) features of little monsters: HP, name (little monsters), damage behavior: combat (Ottoman) 2, according to the characteristics of the object and behavior to define the class (properties and methods) altman, & gt; Ult classes; Little monsters - & gt; Gri classes; The class format is as follows: public class class name {//attribute format public data type attribute name; The format of the object name//method. The method name (parameter type parameter names... ); Writing classes and objects carried out program is divided into the following steps: 1, find out the characteristics of the object in the scene and the objects and actions, for example, the following simple a scene like this: "altman and PK little monsters, until the end of the blood to zero by a party fighting, who output victory!" There are two objects, altman and little monsters, respectively corresponding to the different characteristics and behavior, including altman characteristics: HP, name (Ottoman), damage behavior: combat (little monsters) features of little monsters: HP, name (little monsters), damage behavior: combat (Ottoman) 2, according to the characteristics of the object and behavior to define the class (properties and methods) altman, & gt; Ult classes; Little monsters - & gt; Gri classes; The class format is as follows: public class class name {//attribute format public data type attribute name; The format of the//method public return value type method name (data type parameter name,... Code) {}} (3) defines the entrance to the main function of program, the main function of instantiation objects, and calls the method attribute, (in this case I write main function Manager class)
In this scenario first define Ult and Gri class respectively, they all contain name (String type), blood volume (int); Manager class instantiation Ult and Gri the class object, give their health and damage after the Manager class defined in the fight method makes every time after the attack monsters and altman's HP are reduced; Then add the if conditional sentence to judge whether meet the conditions of the HP to 0 in the scene; Then instantiated in the entry function in monsters and altman two objects respectively, give the name and the initial value of the health; Finally while implementing the cycle until the blood below zero output, after one party program ended