inotgo.com


Tool version compatibility problem
This chapter introduces object-oriented The basic concept of ( But it won't go deep , Just introduce . In depth study will be in the follow-up Classes and objects as well as Interface and inheritance Expand in )

I'm sure you've played DOTA Or LOL, Never played , I must have heard that many friends are playing this game

hypothesis , We're going to design a LOL Such a game , use Object oriented design , What should I do ?
Correct

This video is interpretive , So I hope you have read the content of this knowledge point , And after writing the corresponding code , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning



7 branch 55 second
This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers



Step 1 : Design heroes   
Step 2 : Create concrete heroes   
Step 3 : The first letter of the class is capitalized   
Step 4 : practice -Item   
Step 5 : answer -Item   

LOL There are many heroes , Like blind monks , The regiment war can lose , Timo must die , Galen , Piano girl
All these heroes , They all have something in common
For example , They all have names ,hp, Armor , Moving speed, etc
So we can design something , Called class , On behalf of Heroes Such a thing
class : hero (Hero)
state : name , Blood volume , Armor , Moving speed

notes : This example uses 3 Data types namely String( character string ),float( Floating point number ), int( integer ), This chapter is only for simple use , It won't unfold , about variable Detailed explanation of knowledge , Will be in The next chapter open .
notes : This class has no main method , Don't try to run it . Not all classes have main methods .
 Design heroes
public class Hero { String name; // full name float hp; // Blood volume float armor; // Armor int moveSpeed; // Moving speed }
public class Hero {
	
	String name; // full name 
	
	float hp; // Blood volume 
	
	float armor; // Armor 
	
	int moveSpeed; // Moving speed 
}
Class is like a template , According to such a template , You can create specific heroes one by one
A specific hero , Just call them one by one Object
new Hero() namely java Creating a hero object in
 Create concrete heroes
public class Hero { String name; // full name float hp; // Blood volume float armor; // Armor int moveSpeed; // Moving speed public static void main(String[] args) { Hero garen = new Hero(); garen.name = " Galen "; garen.hp = 616.28f; garen.armor = 27.536f; garen.moveSpeed = 350; Hero teemo = new Hero(); teemo.name = " Timo "; teemo.hp = 383f; teemo.armor = 14f; teemo.moveSpeed = 330; } }
Step 3 :

The first letter of the class is capitalized

edit top fracture
Good programming habits will make the code look cleaner , readable , Easy to maintain
For example The first letter of the class is capitalized
Hero
public class Hero { }
public class Hero {

}
Step 4 :

practice -Item

edit top fracture   Wrong posture , get half the results with double the effort ! Click to see the correct posture for the exercise
Design this kind of object
Class name : Item
The item has the following attributes :
name name The type is string String
Price price The type is integer int

establish ( instantiation )3 A specific item
name Price
Blood bottle 50
Straw sandals 300
Long sword 350
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Account not activated Account not activated , Limited functionality . Please click activate
This video is interpretive , So I hope you have read the content of this answer , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning

2 branch 16 second This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers


notes : establish Item When this class , Must be written in a Item.java In your file , You cannot use other file names , Keep the case consistent , Can't be item.java
public class Item { String name; int price; public static void main(String[] args) { Item potion = new Item(); potion.name= " Blood bottle "; potion.price =50; Item shoe = new Item(); shoe.name= " Straw sandals "; shoe.price =300; Item sword = new Item(); sword.name= " Long sword "; sword.price =350; } }
public class Item {
	String name;
	int price;
	
	public static void main(String[] args) {
		Item potion = new Item();	
		potion.name= " Blood bottle ";
		potion.price =50;
		
		Item shoe = new Item();	
		shoe.name= " Straw sandals ";
		shoe.price =300;
		
		Item sword = new Item();	
		sword.name= " Long sword ";
		sword.price =350;
		
	}
}


The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .


Q & A area    
2021-11-02 All the codes ( Operable )
maozhanyang0929




Accurate output code : public class Hero { private String name; private int price; public static void main(String[] args) { Hero xp = new Hero(); xp.name = " Blood bottle "; xp.price = 50; Hero cx = new Hero(); cx.name = " Straw sandals "; cx.price = 300; Hero cj = new Hero(); cj.name = " Long sword "; cj.price = 350; System.out.println(" name " + " Price "); System.out.println(xp.name + " " + " " + xp.price); System.out.println(cx.name + " " + " " + cx.price); System.out.println(cj.name + " " + " " + cj.price); } }
public class Hero {
    private String name;
    private int price;

    public static void main(String[] args) {
        Hero xp = new Hero();
        xp.name = " Blood bottle ";
        xp.price = 50;

        Hero cx = new Hero();
        cx.name = " Straw sandals ";
        cx.price = 300;

        Hero cj = new Hero();
        cj.name = " Long sword ";
        cj.price = 350;

        System.out.println(" name   " + "   Price ");
        System.out.println(xp.name + "  " + "  " + xp.price);
        System.out.println(cx.name + "  " + "  " + cx.price);
        System.out.println(cj.name + "  " + "  " + cj.price);
    }
}
 
               


1 One answer

zxcvbnm00
Answer time :2021-11-07



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see





2021-09-10 Why add 28f and 536f
wfs




I don't know why I added 28f and 536f
garen.hp = 616.28f;
        garen.armor = 27.536f;
 
               


12 One answer

Introduction Xiaobai 123
Answer time :2021-11-06
public class lianxiti { public static void main (String[]args){ String name =" Galen "; int xueping=300; float xue=200.5f; int tiejian =200; } }

Cyanna
Answer time :2021-11-02
Pipi
Answer time :2021-10-24
FreedomSeeker
Answer time :2021-10-23
Hard working snail i
Answer time :2021-10-22
Spicy chicken with vegetables
Answer time :2021-10-22
A rabbit Cc
Answer time :2021-10-16
public class Item { String name; int price; public static void main(String[] args) { Item xp =new Item();{ xp.name=" Blood bottle "; xp.price=50; } Item cx =new Item();{ cx.name=" Straw sandals "; cx.price=300; } Item cj =new Item();{ cj.name=" Long sword "; cj.price=350; } } }

Toby_20091212
Answer time :2021-10-15
public class Item { String name; int price; public static void main(String[] args) { Item health = new Item(); health.name = " Blood bottle "; health.price = 50; Item shoes = new Item(); shoes.name = " Straw sandals "; shoes.price = 300; Item sword = new Item(); sword.name = " Long sword "; sword.price = 350; } }

tower
Answer time :2021-10-08
Code out of the world
Answer time :2021-09-21
stay 28 Add... After it f, That is 28f, Indicates that it will 28 This constant is cast to float This single precision floating-point type , Because it has been defined earlier :float armor, Definition armor The type of this constant is float float , Constants can only be assigned directly to variables of the corresponding type , That is float 28 Can be assigned to float armor This variable . There are three main expressions , Give an example according to the code in the text : First kind :garen.armor = 27.536f; Second :garen.armor = 27.536F; Third :garen.armor = (float) 27.536; The second... Is recommended , That is, the number is followed by the initial capital of the corresponding type

Harry Potter's magic wand
Answer time :2021-09-11
java Floating point numbers should be followed by f That means floating point numbers

yanwei22
Answer time :2021-09-10
What , It seems that these two values are designed as floating point , It's not marked on the picture above int integer



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see





2021-09-08 code
2021-09-01 This code is in eclpise After writing , Where can I run , I didn't know it for the first time
2021-08-16 punch the clock


Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 183 Previous questions , please Click to view

Please... Before asking questions land
The question has been submitted successfully , Auditing . Please My question Check the question record at , thank you
about JAVA Basics - object-oriented - Classes and objects Your questions

Try to provide Screenshot code and Abnormal information , Help to analyze and solve problems . You can also enter this station QQ Group communication : 496725845
Ask questions and try to provide complete code , Environment description , The more conducive to the recurrence of the problem , The faster your question can be answered .
Have questions about the code in the tutorial , Please provide which step , Which line is in doubt , This makes it easy to quickly locate the problem , Improve the speed at which questions are answered
In the thousands of questions that already exist , A considerable proportion , Because of the use of and webmaster Different versions of the development environment Resulting in , For example jdk, eclpise, idea, mysql,tomcat Wait, the version of the software is inconsistent .
Please use the same version as the webmaster , You can save yourself a lot of learning time . The webmaster sorted out the software versions used in teaching , It's all here , Convenient for everyone to download : /k/helloworld/helloworld-version/1718.html

Upload screenshot