using a getter and setter function viable for account? The Next CEO of Stack OverflowWhat's the difference between a method and a function?Does functional programming replace GoF design patterns?What is the difference between an abstract function and a virtual function?Why use getters and setters/accessors?What's the pythonic way to use getters and setters?Getter and Setter?org.springframework.orm.hibernate3.HibernateQueryException - HibernateTemplateUsing @property versus getters and settersProperty getters and settersJava conventions for accessible data. (Public accessors & Getters/Naming)
What's the point of interval inversion?
What does "Its cash flow is deeply negative" mean?
WOW air has ceased operation, can I get my tickets refunded?
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
Science fiction (dystopian) short story set after WWIII
How to start emacs in "nothing" mode (`fundamental-mode`)
Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?
Why does standard notation not preserve intervals (visually)
I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin
How to use tikz in fbox?
What happens if you roll doubles 3 times then land on "Go to jail?"
Was a professor correct to chastise me for writing "Prof. X" rather than "Professor X"?
Why is there a PLL in CPU?
What is meant by a M next to a roman numeral?
Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables
How do scammers retract money, while you can’t?
How to count occurrences of text in a file?
How easy is it to start Magic from scratch?
Is HostGator storing my password in plaintext?
How can I open an app using Terminal?
The King's new dress
How do I construct this japanese bowl?
Rotate a column
How should I support this large drywall patch?
using a getter and setter function viable for account?
The Next CEO of Stack OverflowWhat's the difference between a method and a function?Does functional programming replace GoF design patterns?What is the difference between an abstract function and a virtual function?Why use getters and setters/accessors?What's the pythonic way to use getters and setters?Getter and Setter?org.springframework.orm.hibernate3.HibernateQueryException - HibernateTemplateUsing @property versus getters and settersProperty getters and settersJava conventions for accessible data. (Public accessors & Getters/Naming)
I am doing a program that involve creating an account, I need to create so that it will scan specific data to carry out an assigned command. is the getter and setter function suitable for it?
public class Account {
//data
private int userId;
private String password;
private char type;
public Account(int userId, String password, char type)
this.userId = userId;
this.password = password;
this.type = type;
public int getUserId()
return userId;
public void setUserId(int userId)
this.userId = userId;
public String getPassword()
return password;
public void setPassword(String password)
this.password = password;
public char getType()
return type;
public void setType(char type)
this.type = type;
//methods
public boolean verifyLogin(int usrid , String pass)
if((usrid == userId) & (pass == password))
return true;
else
return false;
java oop getter-setter
add a comment |
I am doing a program that involve creating an account, I need to create so that it will scan specific data to carry out an assigned command. is the getter and setter function suitable for it?
public class Account {
//data
private int userId;
private String password;
private char type;
public Account(int userId, String password, char type)
this.userId = userId;
this.password = password;
this.type = type;
public int getUserId()
return userId;
public void setUserId(int userId)
this.userId = userId;
public String getPassword()
return password;
public void setPassword(String password)
this.password = password;
public char getType()
return type;
public void setType(char type)
this.type = type;
//methods
public boolean verifyLogin(int usrid , String pass)
if((usrid == userId) & (pass == password))
return true;
else
return false;
java oop getter-setter
2
it wouldn't be logic to change the userId, so you should remove the setUserId, in your verifyLogin, you should compare pass using the equals method instead of the == operator. As for your question, could you please describe more clearly exactly what you are asking?
– Stultuske
Mar 8 at 12:51
In your implementation getter and setter do absolutely nothing. I do not know what the obsession is for universities to ask encapsulation for all methods. If you would do a check for example, if password matches old password, then do not allow to set it, it makes sense. Otherwise, what is the point of encapsulating it, if you could use direct field access?
– Atizs
Mar 8 at 12:54
Why do you think it won't be suitable ?
– vincrichaud
Mar 8 at 12:58
You should use && instead of & in verifyLogin method.
– Corentin
Mar 8 at 13:26
well it is needed to put those getter and setters for some of the key methods, but you are right in the sense that I shouldent apply encapsulation to all of my methods. i will keep that in mind.
– Satu Student
Mar 11 at 13:58
add a comment |
I am doing a program that involve creating an account, I need to create so that it will scan specific data to carry out an assigned command. is the getter and setter function suitable for it?
public class Account {
//data
private int userId;
private String password;
private char type;
public Account(int userId, String password, char type)
this.userId = userId;
this.password = password;
this.type = type;
public int getUserId()
return userId;
public void setUserId(int userId)
this.userId = userId;
public String getPassword()
return password;
public void setPassword(String password)
this.password = password;
public char getType()
return type;
public void setType(char type)
this.type = type;
//methods
public boolean verifyLogin(int usrid , String pass)
if((usrid == userId) & (pass == password))
return true;
else
return false;
java oop getter-setter
I am doing a program that involve creating an account, I need to create so that it will scan specific data to carry out an assigned command. is the getter and setter function suitable for it?
public class Account {
//data
private int userId;
private String password;
private char type;
public Account(int userId, String password, char type)
this.userId = userId;
this.password = password;
this.type = type;
public int getUserId()
return userId;
public void setUserId(int userId)
this.userId = userId;
public String getPassword()
return password;
public void setPassword(String password)
this.password = password;
public char getType()
return type;
public void setType(char type)
this.type = type;
//methods
public boolean verifyLogin(int usrid , String pass)
if((usrid == userId) & (pass == password))
return true;
else
return false;
java oop getter-setter
java oop getter-setter
edited Mar 8 at 13:09
Yassin Hajaj
14.5k72961
14.5k72961
asked Mar 8 at 12:49
Satu StudentSatu Student
1
1
2
it wouldn't be logic to change the userId, so you should remove the setUserId, in your verifyLogin, you should compare pass using the equals method instead of the == operator. As for your question, could you please describe more clearly exactly what you are asking?
– Stultuske
Mar 8 at 12:51
In your implementation getter and setter do absolutely nothing. I do not know what the obsession is for universities to ask encapsulation for all methods. If you would do a check for example, if password matches old password, then do not allow to set it, it makes sense. Otherwise, what is the point of encapsulating it, if you could use direct field access?
– Atizs
Mar 8 at 12:54
Why do you think it won't be suitable ?
– vincrichaud
Mar 8 at 12:58
You should use && instead of & in verifyLogin method.
– Corentin
Mar 8 at 13:26
well it is needed to put those getter and setters for some of the key methods, but you are right in the sense that I shouldent apply encapsulation to all of my methods. i will keep that in mind.
– Satu Student
Mar 11 at 13:58
add a comment |
2
it wouldn't be logic to change the userId, so you should remove the setUserId, in your verifyLogin, you should compare pass using the equals method instead of the == operator. As for your question, could you please describe more clearly exactly what you are asking?
– Stultuske
Mar 8 at 12:51
In your implementation getter and setter do absolutely nothing. I do not know what the obsession is for universities to ask encapsulation for all methods. If you would do a check for example, if password matches old password, then do not allow to set it, it makes sense. Otherwise, what is the point of encapsulating it, if you could use direct field access?
– Atizs
Mar 8 at 12:54
Why do you think it won't be suitable ?
– vincrichaud
Mar 8 at 12:58
You should use && instead of & in verifyLogin method.
– Corentin
Mar 8 at 13:26
well it is needed to put those getter and setters for some of the key methods, but you are right in the sense that I shouldent apply encapsulation to all of my methods. i will keep that in mind.
– Satu Student
Mar 11 at 13:58
2
2
it wouldn't be logic to change the userId, so you should remove the setUserId, in your verifyLogin, you should compare pass using the equals method instead of the == operator. As for your question, could you please describe more clearly exactly what you are asking?
– Stultuske
Mar 8 at 12:51
it wouldn't be logic to change the userId, so you should remove the setUserId, in your verifyLogin, you should compare pass using the equals method instead of the == operator. As for your question, could you please describe more clearly exactly what you are asking?
– Stultuske
Mar 8 at 12:51
In your implementation getter and setter do absolutely nothing. I do not know what the obsession is for universities to ask encapsulation for all methods. If you would do a check for example, if password matches old password, then do not allow to set it, it makes sense. Otherwise, what is the point of encapsulating it, if you could use direct field access?
– Atizs
Mar 8 at 12:54
In your implementation getter and setter do absolutely nothing. I do not know what the obsession is for universities to ask encapsulation for all methods. If you would do a check for example, if password matches old password, then do not allow to set it, it makes sense. Otherwise, what is the point of encapsulating it, if you could use direct field access?
– Atizs
Mar 8 at 12:54
Why do you think it won't be suitable ?
– vincrichaud
Mar 8 at 12:58
Why do you think it won't be suitable ?
– vincrichaud
Mar 8 at 12:58
You should use && instead of & in verifyLogin method.
– Corentin
Mar 8 at 13:26
You should use && instead of & in verifyLogin method.
– Corentin
Mar 8 at 13:26
well it is needed to put those getter and setters for some of the key methods, but you are right in the sense that I shouldent apply encapsulation to all of my methods. i will keep that in mind.
– Satu Student
Mar 11 at 13:58
well it is needed to put those getter and setters for some of the key methods, but you are right in the sense that I shouldent apply encapsulation to all of my methods. i will keep that in mind.
– Satu Student
Mar 11 at 13:58
add a comment |
2 Answers
2
active
oldest
votes
Your getters and setters look fine for accessing the data of this class.
Something you need to be very careful with is how you check if the password is correct.
In your implementation you use pass == password
for comparing two strings. This is NOT correct and you should rather use pass.equals(password)
.
add a comment |
It looks fine, but you need to rethink if Setters for some values are necessary. In example it is not very common use case that UserID will change somehow. If you want to keep it persistant, setter is not necessary. Set it once in constructor.
Additionally you can take a look on the Lombok Project and @Getter & @Setter annotation. It will minimalize your code to 3 lines.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063590%2fusing-a-getter-and-setter-function-viable-for-account%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your getters and setters look fine for accessing the data of this class.
Something you need to be very careful with is how you check if the password is correct.
In your implementation you use pass == password
for comparing two strings. This is NOT correct and you should rather use pass.equals(password)
.
add a comment |
Your getters and setters look fine for accessing the data of this class.
Something you need to be very careful with is how you check if the password is correct.
In your implementation you use pass == password
for comparing two strings. This is NOT correct and you should rather use pass.equals(password)
.
add a comment |
Your getters and setters look fine for accessing the data of this class.
Something you need to be very careful with is how you check if the password is correct.
In your implementation you use pass == password
for comparing two strings. This is NOT correct and you should rather use pass.equals(password)
.
Your getters and setters look fine for accessing the data of this class.
Something you need to be very careful with is how you check if the password is correct.
In your implementation you use pass == password
for comparing two strings. This is NOT correct and you should rather use pass.equals(password)
.
answered Mar 8 at 13:16
JonaswgJonaswg
1559
1559
add a comment |
add a comment |
It looks fine, but you need to rethink if Setters for some values are necessary. In example it is not very common use case that UserID will change somehow. If you want to keep it persistant, setter is not necessary. Set it once in constructor.
Additionally you can take a look on the Lombok Project and @Getter & @Setter annotation. It will minimalize your code to 3 lines.
add a comment |
It looks fine, but you need to rethink if Setters for some values are necessary. In example it is not very common use case that UserID will change somehow. If you want to keep it persistant, setter is not necessary. Set it once in constructor.
Additionally you can take a look on the Lombok Project and @Getter & @Setter annotation. It will minimalize your code to 3 lines.
add a comment |
It looks fine, but you need to rethink if Setters for some values are necessary. In example it is not very common use case that UserID will change somehow. If you want to keep it persistant, setter is not necessary. Set it once in constructor.
Additionally you can take a look on the Lombok Project and @Getter & @Setter annotation. It will minimalize your code to 3 lines.
It looks fine, but you need to rethink if Setters for some values are necessary. In example it is not very common use case that UserID will change somehow. If you want to keep it persistant, setter is not necessary. Set it once in constructor.
Additionally you can take a look on the Lombok Project and @Getter & @Setter annotation. It will minimalize your code to 3 lines.
answered Mar 8 at 13:27
Adam MacierzyńskiAdam Macierzyński
209112
209112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063590%2fusing-a-getter-and-setter-function-viable-for-account%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
it wouldn't be logic to change the userId, so you should remove the setUserId, in your verifyLogin, you should compare pass using the equals method instead of the == operator. As for your question, could you please describe more clearly exactly what you are asking?
– Stultuske
Mar 8 at 12:51
In your implementation getter and setter do absolutely nothing. I do not know what the obsession is for universities to ask encapsulation for all methods. If you would do a check for example, if password matches old password, then do not allow to set it, it makes sense. Otherwise, what is the point of encapsulating it, if you could use direct field access?
– Atizs
Mar 8 at 12:54
Why do you think it won't be suitable ?
– vincrichaud
Mar 8 at 12:58
You should use && instead of & in verifyLogin method.
– Corentin
Mar 8 at 13:26
well it is needed to put those getter and setters for some of the key methods, but you are right in the sense that I shouldent apply encapsulation to all of my methods. i will keep that in mind.
– Satu Student
Mar 11 at 13:58