How to append an entered Social Security number to xxx-xx-1111?How would you access Object properties from within an object method?How to round a number to n decimal places in JavaHow to append something to an array?Are getters and setters poor design? Contradictory advice seenHow to append text to an existing file in JavaHow do I append one string to another in Python?How do you append to a file in Python?Verifying if an input string is a correct Social Security NumberWhen the user types 'EXIT' the program should close and show all previous inputsMaking a getter that accesses another class in JAVA
Is there a push, in the United States, to use gender-neutral language and gender pronouns (when they are given)?
In the twin paradox does the returning twin also come back permanently length contracted flatter than the twin on earth?
This is a Noteworthy Riddle
Did Terry Pratchett ever explain the inspiration behind the Luggage?
How safe is the 4% rule if the U.S. goes back to the mean?
What is a "G.O.A.T" game?
Idiom for a situation or event that makes one poor or even poorer?
"A tin of biscuits" vs "A biscuit tin"
How do I copy an installed steam game on my PC to an external hard drive?
Fermat's polygonal number theorem
Is a list of the most common English words copyrightable?
Hero battle game
Which culture used no personal names?
Translation of: 美しいと思ってしまったのだ
Why does Principal Vagina say, "no relation" after introducing himself?
Split mile limits to the thousandth based on ID
Find number 8 with the least number of tries
Decrypting Multi-Prime RSA with e, N, and factors of N given
Code Golf Measurer © 2019
Encountering former, abusive advisor at a conference
Split telescope into two eyes
Why is Trump releasing or not of his taxes such a big deal?
Why isn't Hagrid removed from Hogwarts sooner in Harry's would-be 7th year?
Are dead worlds a good galactic barrier?
How to append an entered Social Security number to xxx-xx-1111?
How would you access Object properties from within an object method?How to round a number to n decimal places in JavaHow to append something to an array?Are getters and setters poor design? Contradictory advice seenHow to append text to an existing file in JavaHow do I append one string to another in Python?How do you append to a file in Python?Verifying if an input string is a correct Social Security NumberWhen the user types 'EXIT' the program should close and show all previous inputsMaking a getter that accesses another class in JAVA
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I am learning Java and am working on a program for a class. I've completed the bulk of the program so not much help is needed.
How can I convert a SSN (entered by scanner) from, 111-11-1111 to xxx-xx-1111?
I also need to validate that the format of the numbers entered is correct. There is a main class and an Astronaut class where I have getters and setters for the SSN. I already have a toString
override method to format it the way I want when I run the program.
@Override
public String toString()
super.toString();
System.out.println("SSN: " + ssn);
return "";
java append tostring
add a comment
|
I am learning Java and am working on a program for a class. I've completed the bulk of the program so not much help is needed.
How can I convert a SSN (entered by scanner) from, 111-11-1111 to xxx-xx-1111?
I also need to validate that the format of the numbers entered is correct. There is a main class and an Astronaut class where I have getters and setters for the SSN. I already have a toString
override method to format it the way I want when I run the program.
@Override
public String toString()
super.toString();
System.out.println("SSN: " + ssn);
return "";
java append tostring
1
What do you expectsuper.toString()
to achieve?
– PM 77-1
Mar 28 at 21:26
Aside from main question:toString()
shouldn't be responsible for printing anything, but generating String representation of an object which then can be used as client want, for instance it can be printed. Using that logic yoursuper.toString()
would be redundant because it would return some value which you are ignoring. If your superclass really generates values which you want to also print along with your Astronaut then you probably wanted something likeString parentStr = super.toString(); ...; return parentStr+other+elements;
– Pshemo
Mar 28 at 21:33
1
Anyway easiest way to replacing single characters with other characters would be converting string to char[], modifying that char[], and creatingnew String(modifiedCharArray)
. You could also use substring method to get only part which you are interested in and concatenate it with mask.
– Pshemo
Mar 28 at 21:35
I forgot to mention that the Astronaut is an extension of another class
– JavaLearner1234
Mar 28 at 22:02
add a comment
|
I am learning Java and am working on a program for a class. I've completed the bulk of the program so not much help is needed.
How can I convert a SSN (entered by scanner) from, 111-11-1111 to xxx-xx-1111?
I also need to validate that the format of the numbers entered is correct. There is a main class and an Astronaut class where I have getters and setters for the SSN. I already have a toString
override method to format it the way I want when I run the program.
@Override
public String toString()
super.toString();
System.out.println("SSN: " + ssn);
return "";
java append tostring
I am learning Java and am working on a program for a class. I've completed the bulk of the program so not much help is needed.
How can I convert a SSN (entered by scanner) from, 111-11-1111 to xxx-xx-1111?
I also need to validate that the format of the numbers entered is correct. There is a main class and an Astronaut class where I have getters and setters for the SSN. I already have a toString
override method to format it the way I want when I run the program.
@Override
public String toString()
super.toString();
System.out.println("SSN: " + ssn);
return "";
java append tostring
java append tostring
edited Mar 28 at 21:58
Steve
4,8351 gold badge8 silver badges31 bronze badges
4,8351 gold badge8 silver badges31 bronze badges
asked Mar 28 at 21:21
JavaLearner1234JavaLearner1234
11 bronze badge
11 bronze badge
1
What do you expectsuper.toString()
to achieve?
– PM 77-1
Mar 28 at 21:26
Aside from main question:toString()
shouldn't be responsible for printing anything, but generating String representation of an object which then can be used as client want, for instance it can be printed. Using that logic yoursuper.toString()
would be redundant because it would return some value which you are ignoring. If your superclass really generates values which you want to also print along with your Astronaut then you probably wanted something likeString parentStr = super.toString(); ...; return parentStr+other+elements;
– Pshemo
Mar 28 at 21:33
1
Anyway easiest way to replacing single characters with other characters would be converting string to char[], modifying that char[], and creatingnew String(modifiedCharArray)
. You could also use substring method to get only part which you are interested in and concatenate it with mask.
– Pshemo
Mar 28 at 21:35
I forgot to mention that the Astronaut is an extension of another class
– JavaLearner1234
Mar 28 at 22:02
add a comment
|
1
What do you expectsuper.toString()
to achieve?
– PM 77-1
Mar 28 at 21:26
Aside from main question:toString()
shouldn't be responsible for printing anything, but generating String representation of an object which then can be used as client want, for instance it can be printed. Using that logic yoursuper.toString()
would be redundant because it would return some value which you are ignoring. If your superclass really generates values which you want to also print along with your Astronaut then you probably wanted something likeString parentStr = super.toString(); ...; return parentStr+other+elements;
– Pshemo
Mar 28 at 21:33
1
Anyway easiest way to replacing single characters with other characters would be converting string to char[], modifying that char[], and creatingnew String(modifiedCharArray)
. You could also use substring method to get only part which you are interested in and concatenate it with mask.
– Pshemo
Mar 28 at 21:35
I forgot to mention that the Astronaut is an extension of another class
– JavaLearner1234
Mar 28 at 22:02
1
1
What do you expect
super.toString()
to achieve?– PM 77-1
Mar 28 at 21:26
What do you expect
super.toString()
to achieve?– PM 77-1
Mar 28 at 21:26
Aside from main question:
toString()
shouldn't be responsible for printing anything, but generating String representation of an object which then can be used as client want, for instance it can be printed. Using that logic your super.toString()
would be redundant because it would return some value which you are ignoring. If your superclass really generates values which you want to also print along with your Astronaut then you probably wanted something like String parentStr = super.toString(); ...; return parentStr+other+elements;
– Pshemo
Mar 28 at 21:33
Aside from main question:
toString()
shouldn't be responsible for printing anything, but generating String representation of an object which then can be used as client want, for instance it can be printed. Using that logic your super.toString()
would be redundant because it would return some value which you are ignoring. If your superclass really generates values which you want to also print along with your Astronaut then you probably wanted something like String parentStr = super.toString(); ...; return parentStr+other+elements;
– Pshemo
Mar 28 at 21:33
1
1
Anyway easiest way to replacing single characters with other characters would be converting string to char[], modifying that char[], and creating
new String(modifiedCharArray)
. You could also use substring method to get only part which you are interested in and concatenate it with mask.– Pshemo
Mar 28 at 21:35
Anyway easiest way to replacing single characters with other characters would be converting string to char[], modifying that char[], and creating
new String(modifiedCharArray)
. You could also use substring method to get only part which you are interested in and concatenate it with mask.– Pshemo
Mar 28 at 21:35
I forgot to mention that the Astronaut is an extension of another class
– JavaLearner1234
Mar 28 at 22:02
I forgot to mention that the Astronaut is an extension of another class
– JavaLearner1234
Mar 28 at 22:02
add a comment
|
2 Answers
2
active
oldest
votes
You can do something like this:
@Override
public String toString()
return "SSN: XXX-XX-" + ssn.substring(7);
add a comment
|
In order to validate that the number of digits entered is correct, you can use a regex expression. For example: ssn.matches("(\d-)?\d3-\d2-\d4")
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/4.0/"u003ecc by-sa 4.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%2f55407037%2fhow-to-append-an-entered-social-security-number-to-xxx-xx-1111%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
You can do something like this:
@Override
public String toString()
return "SSN: XXX-XX-" + ssn.substring(7);
add a comment
|
You can do something like this:
@Override
public String toString()
return "SSN: XXX-XX-" + ssn.substring(7);
add a comment
|
You can do something like this:
@Override
public String toString()
return "SSN: XXX-XX-" + ssn.substring(7);
You can do something like this:
@Override
public String toString()
return "SSN: XXX-XX-" + ssn.substring(7);
answered Mar 28 at 21:30
ipaveipave
4263 silver badges12 bronze badges
4263 silver badges12 bronze badges
add a comment
|
add a comment
|
In order to validate that the number of digits entered is correct, you can use a regex expression. For example: ssn.matches("(\d-)?\d3-\d2-\d4")
add a comment
|
In order to validate that the number of digits entered is correct, you can use a regex expression. For example: ssn.matches("(\d-)?\d3-\d2-\d4")
add a comment
|
In order to validate that the number of digits entered is correct, you can use a regex expression. For example: ssn.matches("(\d-)?\d3-\d2-\d4")
In order to validate that the number of digits entered is correct, you can use a regex expression. For example: ssn.matches("(\d-)?\d3-\d2-\d4")
answered Mar 28 at 21:49
AtroAtro
11 bronze badge
11 bronze badge
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%2f55407037%2fhow-to-append-an-entered-social-security-number-to-xxx-xx-1111%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
1
What do you expect
super.toString()
to achieve?– PM 77-1
Mar 28 at 21:26
Aside from main question:
toString()
shouldn't be responsible for printing anything, but generating String representation of an object which then can be used as client want, for instance it can be printed. Using that logic yoursuper.toString()
would be redundant because it would return some value which you are ignoring. If your superclass really generates values which you want to also print along with your Astronaut then you probably wanted something likeString parentStr = super.toString(); ...; return parentStr+other+elements;
– Pshemo
Mar 28 at 21:33
1
Anyway easiest way to replacing single characters with other characters would be converting string to char[], modifying that char[], and creating
new String(modifiedCharArray)
. You could also use substring method to get only part which you are interested in and concatenate it with mask.– Pshemo
Mar 28 at 21:35
I forgot to mention that the Astronaut is an extension of another class
– JavaLearner1234
Mar 28 at 22:02