Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Hey guys so I have the method
public void addQuestion(Question question)
{
}
I have created an ArrayList in the class section
private ArrayList<Question> quizQuestion;
and I have initialised the ArrayList in the constructor by typing
quizQuestion = new ArrayList<Question>();
What do I type in the method above so I can add questions to the Question ArrayList. :)
public void addQuestion(Question question)
{
quizQuestion.add(question);
}
public void addQuestion(Question question)
{
quizQuestion.add(question);
}
Not sure, what you really want :)
but if you just want to add parameter Question to arraylist quizQuestion
quizQuestion.add(question);
I hope this helps...
Keep Leanrning :)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 days ago.
Improve this question
My probleme is how to change a global class variable in a void function. I need to conserve the changes of my classe. How can I do that ?
//for example
Class Animal{
B b = null;
void Treatement(B b)
{
try{
b = new Class B()
b.name = "toto";
}
catch(Exception e)
{
throw new Exception(e.getMessage());
}
}
}
}
The probleme is I can not find a solution for this example because my variable has to be as parametre and need to save it for other fonctions when an exception is raised.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a method:
public void dealDmg(int hp) {
this.hp = hp;
this.hp -= this.dmg;
}
But when i use it as dmg_dealer.dealDmg(dmg_receiver.hp);, it doesn't work properly as in the dmg_receiver's hp is not decreased, but the dmg_dealer's hp becomes of the same amount as of the dmg_receiver, and then dmg_dealer's hp gets reduced by the dmg amount. How can I change a body of the method so that it works in such a way?
You need to pass in the dmg_receiver object to the method instead of dmg_receiver.hp, that way you can update hp in dmg_receiver as well. The updated method should look like below:
public void dealDmg(DmgReceiver dmg_receiver) {
this.hp = dmg_receiver.hp;
dmg_receiver.hp -= this.dmg;
}
If the object represented by this is dealing damage to another object, the dealDmg needs to the object being dealt damage to (assuming that dmg is a member):
public void dealDmg(Unit other) {
other.hp -= this.dmg;
}
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Why does java.lang.Exception not provide a setter for the message and allow setting it only via the constructor (e.g. super(_msg))?
For example:
public BadParameterException(QueryParameter _param, String _valStr) {
this.param = _param;
this.valAsStr = _valStr;
}
public BadParameterException(QueryParameter _param, String _valStr, String _msg) {
this(_param, _valStr);
/* This is not possible */ super.setMessage(_msg);
}
instead, I have to do this:
public BadParameterException(QueryParameter _param, String _valStr, String _msg) {
super(_msg);
this.param = _param;
this.valAsStr = _valStr;
}
Because an Exception is a snapshot of a situation. It's not supposed to change it's state.
Since the message can only be set through the constructor, it's basically final and cannot be changed afterwards. That's how it was designed.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can i parse this json with GSON to my model?
Thanks for help.
{
"Kod":"XU100",
"Son Değer":"83.947",
"En Düşük":"83.947",
"En Yüksek":"86.355"
},
Would be like:
#SerializedName("Kod")
private String kod;
#SerializedName("Son Değer")
private String sonDeger;
#SerializedName("En Düşük")
private String enDusuk;
#SerializedName("En Yüksek")
private String enYuksek;
//Getters and Setters
And then:
YourClass yourClass = gson.fromJson(json, YourClass.class);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
What would the same code in c++ look like, or the closest thing to it?
public class Skill{
public Skill(String name){
}
public static Map<String, Skill> getSkills(){
Map<String, Skill> skills = new Map<String, Skill>();
skills.add("Endurance", new Skill());
return skills;
}
}
std::map<std::string,Skill*> skills;
skills["Endurance"] = new Skill();