Home > Back-end >  Code depth resolution small white all don't know much about the guide please bosses
Code depth resolution small white all don't know much about the guide please bosses

Time:10-11

 
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Class Money {//Money as an object, to determine whether the original Money
String currency="RMB";
A double value=https://bbs.csdn.net/topics/0;
Public Money (String currency, a double value)//the parameter value given to attribute currency currency value
{
Enclosing currency=currency;
This value=https://bbs.csdn.net/topics/value;
}
Public Money (double value)
{
This (" RMB ", value);
}
}

The class Sample {
Public static void main (String [] args) {
List Hands=new ArrayList<> (a);//used to shuffle the deck hand
Money zhangsan=new Money (100);//zhang money
Money lisi=new Money (100);//bill money
Hands. The add (zhangsan);//hand took the zhang SAN money (hands [0] zhang SAN's hand)
Hands. The add (lisi);//hand took the bill money (hands [1] is equivalent to the hands of li si)
The Collections. Shuffle (hands);//after pushing hands again shuffle (like money)
Money shoukuanyuan=hands. Get (1);//cashier once took li si money
System. The out. Printf (" zhang SAN li si money money? % s \ n ", hands get (0)==lisi?" Is not ":" ");
System. The out. Printf (" the cashier hand money whether the original bill? % s \ n ", shoukuanyuan==lisi?" Is not ":" ");
System. The out. Printf (" zhang SAN zhang SAN's original money money? % s \ n ", hands get (0)==zhangsan?" Is not ":" ");
}
}

Public Money (double value)
{
This (" RMB ", value);
} the constructor what do you mean???????
A double value=https://bbs.csdn.net/topics/0; And the


CodePudding user response:

Public Money (double value) call Public Money (String currency, a double value)
the structure
A double value=https://bbs.csdn.net/topics/0; The value set an initial value of 0

CodePudding user response:

These two methods are all Money class constructor
Public Money (String currency, a double value)//the parameter value given to attribute currency currency value
{
Enclosing currency=currency;
This value=https://bbs.csdn.net/topics/value;
}
Public Money (double value)
{
This (" RMB ", value);
}

CodePudding user response:

This way, Alt + left mouse button in the code you will find that this method, it is for this class of Money (String currency, a double value) method, and set up value=https://bbs.csdn.net/topics/0, with $0 is the default initialization, personal feel, the second write this constructor calls the first constructor a bit redundant,

CodePudding user response:

reference 3 floor の lazy cat replies:
this way, Alt + left mouse button in the code you will find that this method, it is for this class of Money (String currency, a double value) method, and set the value=https://bbs.csdn.net/topics/0, with $0 is the default initialization, personal feel, the second write this constructor calls the first constructor a bit redundant,

This is a big writing then I am here to thank you, I will try to delete can see under the optimization
  • Related