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 )
Correct
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 ?
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 .
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
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; } }
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 { }
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 )
The answer has been submitted successfully , Auditing . Please
My answer Check the answer record at , thank you
2021-09-10
Why add 28f and 536f
12 One answer
Introduction Xiaobai 123 Jump to the problem location 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 Jump to the problem location Answer time :2021-11-02 Pipi Jump to the problem location Answer time :2021-10-24 FreedomSeeker Jump to the problem location Answer time :2021-10-23 Hard working snail i Jump to the problem location Answer time :2021-10-22 Spicy chicken with vegetables Jump to the problem location Answer time :2021-10-22 A rabbit Cc Jump to the problem location 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 Jump to the problem location 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 Jump to the problem location Answer time :2021-10-08 Code out of the world Jump to the problem location 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 Jump to the problem location Answer time :2021-09-11
java Floating point numbers should be followed by f That means floating point numbers
yanwei22 Jump to the problem location 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
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
|