Hi all,
I have created a Mobile Number Generator.
Here are the requirements:
- Number always starts with 07
- Number must be 11 Digits long
- Remaining 9 digits to be generated 0-9
- Output to be the Complete Number as a String of Length 11.
Here is the Code:
package latesttasks; // Mobile phone number generator // Ask customer how many numbers they would like generated. // Requirements: start with 07, 11 numbers, no repeats. import java.util.Random; public class Task4 { public static void main(String[] args) { String numStart = "07"; String numRemainder; String numComplete; String sd3, sd4, sd5, sd6, sd7, sd8, sd9, sd10, sd11; Random rand = new Random(); int d3 = rand.nextInt(10); int d4 = rand.nextInt(10); int d5 = rand.nextInt(10); int d6 = rand.nextInt(10); int d7 = rand.nextInt(10); int d8 = rand.nextInt(10); int d9 = rand.nextInt(10); int d10 = rand.nextInt(10); int d11 = rand.nextInt(10); sd3 = Integer.toString(d3); sd4 = Integer.toString(d4); sd5 = Integer.toString(d5); sd6 = Integer.toString(d6); sd7 = Integer.toString(d7); sd8 = Integer.toString(d8); sd9 = Integer.toString(d9); sd10 = Integer.toString(d10); sd11 = Integer.toString(d11); numRemainder= ""+sd3+""+sd4+""+sd5+""+sd6+""+sd7+""+sd8+"" +sd9+""+sd10+""+sd11+""; numComplete = ""+numStart+""+numRemainder+""; System.out.println(numComplete); } }
I would really like some advice on this.
First of all, the program seems to work but to me it looks really 'beginner like' and unprofessional.
For example am i converting the integers to strings correctly ? Is there a quicker or more recommended way to do this rather than typing it all out twice.
Also i don't like the way i am joining the String together as one. the quotation and + marks just to simply join each digit together looks really ametuer(ish). It kind of looks like cheating and unprofessional.
So are there better, alternative ways i should be:
- Generating the 9 random digits
- Converting the Integers to Strings
- Joining the Strings together to make the final String
- Or Maybe should the output even be a String ? Maybe it could be outputted as an int ?
Many thanks for your suggestions and feedback.