Java study notes, learning notes
Class and object (concept Demo)
Object-Oriented java C ++ encapsulate inherited multi-state object
Process-oriented C struct
1. Get user input 2. logical judgment 3. Calculation output result
Process-oriented C struct content: pointer struct header file
Class is the basis of Object-Oriented Programming Language
Class? As long as a human computer is a group of common things (with common characteristics and actions ),
Set/template
The description describes the entire class. (Describing common actions and features is not responsible for the implementation of specific definitions)
The object constructs a specific reference from the set/template (assign values/describe some specific values or operations)
Call through an object (static)
Association
Private
Public is recommended.
Job:
// The Back-to-contract mode of the primary key game
// Each round of Dema and ice are attacked by each other. Dema is attacked by ice, and Dema is attacked by ice.
// Keep hitting a side with a blood volume lower than 0!
Summary:
Class description: several classes. One execution class.
Description class property Method
Execution class: main function call Code Business Process Control
It is a bridge between functions and the outside world.
Next course constructor this
// Demand analysis: the status of the XX car on the road shows the forward and backward parking
// Draw distance from the road status of a car with a noun brand according to your needs
// 1. Which nouns can be classified into one category until they cannot be classified. 2. Which nouns belong to which terms?
// Automobile: brand model status Road: nouns are either Class, attribute, or redundant
// The method (function) where the verb moves forward and backward)
// Car: Parking after driving
// Create a class: Car class
// Market research-Demand Analysis-Outline Design-detailed design-code writing-test-Demo-> launch
// Automotive: brand model Status
// Only the attribute method can be directly written in the code segment of the class.
Public class Car {
// Attribute (a global variable) the attribute name should be meaningful as much as possible
// Attribute is the term used to describe the feature.
String brand; // The naming rules of brand attributes are the same as those of variables in lower case.
String model; // model qualifier data type attribute name (analyzed)
String statu;
Int length; // mileage
//************************************** *********************
// The method is the verb that describes the action.
// * Qualifier * return value type method name (parameter list) {code segment}
Public void drive (){
// Length ++;
System. out. print (brand + "brand" + model + "model:" + statu + "status! ");
}
Public void ahead (){
Length ++;
System. out. print (brand + "brand" + model + "model:" + statu + "status! ");
}
Public void back (){
Length --;
System. out. print (brand + "brand" + model + "model:" + statu + "status! ");
}
Public void stop (){
System. out. print (brand + "brand" + model + "model:" + statu + "status! ");
}
}
/* Assignments of selecting shanzhi education 2nd
* Class and Object
* Dema Implementation of the cold ice and Dema Combat Games
* Instructor Bear
* Student Cao Kun
* 2015-6-6
*/
/* Requirement Analysis
* Dema vs ice vs. the cold ice
* Each round of Dema and ice are attacked by each other. Dema is attacked by ice, and Dema is attacked by ice.
* Keep hitting a side with a blood volume lower than 0!
*/
Public class Dema {
// Define the attributes and methods of the class
Private String dname;
Private int dblood; // life value
Private int dattackpower; // damage caused by an attack to the other party's life
Public void setDName (String dname ){
This. dname = dname;
}
Public String getDName (){
Return this. dname;
}
Public void setDBlood (int dblood ){
This. dblood = dblood;
}
Public int getDBlood (){
Return this. dblood;
}
Public void setDAttackpower (int dattackpower ){
This. dattackpower = dattackpower;
}
Public int getDAttackpower (){
Return this. dattackpower;
}
Public void DAttack (Hanbing hanbing ){
Hanbing. setHBlood (hanbing. getHBlood ()-this. getDAttackpower ());
// System. out. println ("name:" + this. getDName () + "named" + hangbing. getHName () + "an attack by a cold ice warrior, resulting in a cold ice warrior" + hanbing. getHName () + "Lost Life Value:" + this. getDAttackpower () + ", Ice Warrior:" + dema. getHName () + "remaining lifecycle values:" + hbpower );
}
}
/* Assignments of selecting shanzhi education 2nd
* Class and Object
* Hanbing Implementation of the Combat Games between ice and Dema
* Instructor Bear
* Student Cao Kun
* 2015-6-6
*/
/* Requirement Analysis
* Dema vs ice vs. the cold ice
* Each round of Dema and ice are attacked by each other. Dema is attacked by ice, and Dema is attacked by ice.
* Keep hitting a side with a blood volume lower than 0!
*/
Public class Hanbing {
// Define the attributes and methods of the class
Private String hname;
Private int hblood; // life value
Private int hattackpower; // damage caused by an attack to the other party's life
Public void setHName (String hname ){
This. hname = hname;
}
Public String getHName (){
Return this. hname;
}
Public void setHBlood (int hblood ){
This. hblood = hblood;
}
Public int getHBlood (){
Return this. hblood;
}
Public void setHAttackpower (int hattackpower ){
This. hattackpower = hattackpower;
}
Public int getHAttackpower (){
Return this. hattackpower;
}
Public void HAttack (Dema dema ){
Dema. setDBlood (dema. getDBlood ()-this. getHAttackpower ());
// System. out. println ("name:" + this. the cold ice warrior of getHName () + "is named" + dema. getDName () + "an attack by a attach of the dema warrior, resulting in the" + dema. getDName () + "Lost Life Value:" + this. getHAttackpower () + ", dema Warrior:" + dema. getDName () + "remaining lifecycle values:" + demapower );
}
}
/* Assignments of selecting shanzhi education 2nd
* Class and Object
* Implementation of the combat game execution class of cold ice and Dema
* Instructor Bear
* Student Cao Kun
* 2015-6-6
*/
/* Requirement Analysis
* Dema vs ice vs. the cold ice
* Each round of Dema and ice are attacked by each other. Dema is attacked by ice, and Dema is attacked by ice.
* Keep hitting a side with a blood volume lower than 0!
*/
Public class Manager {
Public static void main (String args []) {
Hanbing hb = new Hanbing ();
Dema dm = new Dema ();
Hb. setHName ("James ");
Hb. setHBlood (1000 );
Hb. setHAttackpower (95 );
Dm. setDName ("Li Si ");
Dm. setDBlood (900 );
Dm. setDAttackpower (108 );
While (true ){
Hb. HAttack (dm );
System. out. println ("Ice Warrior:" + hb. getHName () + "to the defma Warrior:" + dm. getDName () + "an attack, resulting in the" + dm. getDName () + "loss lifecycle:" + hb. getHAttackpower () + ", Dema Warrior:" + dm. getDName () + "remaining lifecycle:" + dm. getDBlood ());
If (hb. getHBlood () <= 0 | dm. getDBlood () <= 0)
Break;
Dm. DAttack (hb );
System. out. println ("Dema Warrior:" + dm. getDName () + "give ice fighters:" + hb. getHName () + "an attack that causes ice fighters:" + hb. getHName () + "loss lifecycle:" + dm. getDAttackpower () + ", Ice Warrior:" + hb. getHName () + "remaining lifecycle:" + hb. getHBlood ());
If (hb. getHBlood () <= 0 | dm. getDBlood () <= 0)
Break;
}
If (hb. getHBlood () <= 0 ){
System. out. println ("Dema Warrior:" + dm. getDName () + "Victory! ");
} Else {
System. out. println ("Ice Warrior:" + hb. getHName () + "Victory! ");
}
}
}