Jessica Egart

Greenhorn
+ Follow
since Mar 14, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jessica Egart

Hey guys,

Thanks for all your help! I figured it out and it's running fine!

in the end, this is what i ended up with:
import java.util.Scanner;

public class Q2 {

/**
* @param args
*/
public static void main(String[] args) {
Scanner enterFirstName= new Scanner (System.in);
String firstName;

System.out.println("Car Registration Number Generator");
System.out.println("");

System.out.println("Please enter your first name:");
firstName= enterFirstName.next();

int nameLength= firstName.length();
int letterOneNumber= 0+ (int) (Math.random()*nameLength);
int letterTwoNumber= 0+ (int) (Math.random()*nameLength);
int letterThreeNumber= 0+ (int) (Math.random()*nameLength);

char letterOne= firstName.charAt(letterOneNumber);
char letterTwo= firstName.charAt(letterTwoNumber);
char letterThree= firstName.charAt(letterThreeNumber);

String letterOneRego= Character.toString(letterOne);
String letterTwoRego= Character.toString(letterTwo);
String letterThreeRego= Character.toString(letterThree);

String letterOneRegistration= letterOneRego.toUpperCase();
String letterTwoRegistration= letterTwoRego.toUpperCase();
String letterThreeRegistration= letterThreeRego.toUpperCase();

String registrationLetters= letterOneRegistration + letterTwoRegistration + letterThreeRegistration;
int licensePlateNumber = 100 + (int) (Math.random()*999);

System.out.println("Your registration number is: " + registrationLetters + " " + licensePlateNumber);

Thanks again for all your help!
12 years ago

Jk Robbins wrote:This must be a late assignment since I see you posted at 12:58 am and you were either back on or still on at 7:43 am. Ouch. I admire your diligence.



haha... not quite... its not due till Sunday, but i want to try and get it out of the way so I can do some work on my ecomonics...

We actually haven't been taught about the java.random.class, but after re-reading the question I noticed it said "Use either Math.random() or an instance of the Random class from java.util to generate the random numbers you require.", so I guess I can use either?

I've still got the same as above, because whenever I add something new, i test it, and if it doesn't work, delete it... Needless to say, I've deleted about a hundred different things...


Jess
12 years ago
Hi all,

Thanks for all your replies...

I just realised i should use the java.math class rather than the java.random class...
However, it still hasn't gotten much further....

We were just told to generate a program that could be used with any name the user inputs, no matter how short or long... Duplicates are fine...

I've been working on it for a while now, and it's doing my head in!


Jess
12 years ago
it's from any 3 letters in their name...


Jess
12 years ago
Hi, i'm relatively new to Java programming and have been asked to design a program that generates a "License plate" number.

the three letters of the license plate are generated from the user's input of their first name, and the three numbers are a randomly generated integer between 100 and 999.
I know how to generate the random integer, but am having terrible trouble generating the random letters.

Here's what I have so far:

Any help would be much appreciated!

Thanks,
12 years ago