473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

java sentence generator

2
Hi, I'm stuck at the very beginning of my current assignment. I just need a little help getting started, and then I know how to do everything else.

ask user:
"Please enter your name followed by a positive integer between 1 and 9999 enclosed in parentheses, such as Cupid(1442)."

how do i use substring to take out just the name that they enter, so that it starts at the first letter they enter, and ends at the (?

also

how do i use the input integer (1442) as a seed for my random number generator?

Random rand = new Random(number);
randNum = rand.nextInt(9);


thanks in advance...this is a description of the assignment in case what I have said is not clear:

"Use JOptionPane to design a simple English language sentence generator with a random component, so that the user never knows quite what to expect for the output sentence, unless one “special” name is entered. This sentence generator should read expressions composed of a person’s name followed by a positive integer between 1 and 9999 enclosed in parentheses, such Cupid(1442). For output, it should produce a complete sentence about the person, such as “Cupid is a great Java programmer!” The procedure for completing the sentence is as follows:

The program should pass the input integer as a “seed” to a pseudo-random number generator object (see below).
The random number generator will use the seed to produce a single-digit integer between 0 and 9 as output.
Write your program so that the sentence completion is based upon the output random integer, or a match with the “special” name.
To reduce the number of sentences that you have to code, you may use one sentence completion for multiple random integers or “special” name match, as shown in the examples below:

Random number is 0, 1, or 2: “ is new to Java, and so his code is sometimes off target.”
Random number is 3, 4, or 5: “ is right on the mark with his Java conditional statements.”
Random number is 6, 7, or 8: “ really knows how to pair up a great algorithm with great code!”
Input name matches defined “special” name, or random number is 9: “, you’re the best!”"
Feb 13 '08 #1
4 6534
BigDaddyLH
1,216 Expert 1GB
how do i use substring to take out just the name that they enter, so that it starts at the first letter they enter, and ends at the (?

also

how do i use the input integer (1442) as a seed for my random number generator?

Random rand = new Random(number);
randNum = rand.nextInt(9);
  1. Have you read the API for substring? In fact, scan the API for String for other handy methods.
  2. Yes, that's how you can use Random.

For starters, write a test program:
Expand|Select|Wrap|Line Numbers
  1. public class Test {
  2.     public static void main(String[] args) {
  3.         String input = "Cupid(1442)";
  4.         ...
  5.         String name = ...
  6.         int seed = ...
  7.         System.out.println(name);
  8.         System.out.println(seed);
  9.     }
  10. }
Don't cheat and assume fixed sizes for the parts!
Feb 13 '08 #2
wohast
2
thanks for the reply...

Expand|Select|Wrap|Line Numbers
  1.  
  2. public static void main(String[] args)
  3.  
  4.   {
  5.     String inputString;
  6.     String firstName;
  7.  
  8.     inputString = JOptionPane.showInputDialog
  9.                ("Please enter your name followed by a positive integer between 1 and 9999 enclosed in parentheses, such as Cupid(1442).");
  10.     firstName = inputString.substring(0, 
  11.     }
  12. }
  13.  
inputString.substring(0, *******)

obviously the name that they input is going to start at 0 and will finish at the (.
what i am trying to figure out is if there is anything i can put in place of the stars so that it will end reading the name at the open parentheses.
Feb 13 '08 #3
BigDaddyLH
1,216 Expert 1GB
obviously the name that they input is going to start at 0 and will finish at the (.
what i am trying to figure out is if there is anything i can put in place of the stars so that it will end reading the name at the open parentheses.
Have you scanned through the API of String for a likely method yet?

And come to think of it, are you aware of the existence of the API? http://java.sun.com/javase/6/docs/api/
Feb 13 '08 #4
Hi, I'm stuck at the very beginning of my current assignment. I just need a little help getting started, and then I know how to do everything else.

ask user:
"Please enter your name followed by a positive integer between 1 and 9999 enclosed in parentheses, such as Cupid(1442)."

how do i use substring to take out just the name that they enter, so that it starts at the first letter they enter, and ends at the (?

also

how do i use the input integer (1442) as a seed for my random number generator?

Random rand = new Random(number);
randNum = rand.nextInt(9);


thanks in advance...this is a description of the assignment in case what I have said is not clear:

"Use JOptionPane to design a simple English language sentence generator with a random component, so that the user never knows quite what to expect for the output sentence, unless one “special” name is entered. This sentence generator should read expressions composed of a person’s name followed by a positive integer between 1 and 9999 enclosed in parentheses, such Cupid(1442). For output, it should produce a complete sentence about the person, such as “Cupid is a great Java programmer!” The procedure for completing the sentence is as follows:

The program should pass the input integer as a “seed” to a pseudo-random number generator object (see below).
The random number generator will use the seed to produce a single-digit integer between 0 and 9 as output.
Write your program so that the sentence completion is based upon the output random integer, or a match with the “special” name.
To reduce the number of sentences that you have to code, you may use one sentence completion for multiple random integers or “special” name match, as shown in the examples below:

Random number is 0, 1, or 2: “ is new to Java, and so his code is sometimes off target.”
Random number is 3, 4, or 5: “ is right on the mark with his Java conditional statements.”
Random number is 6, 7, or 8: “ really knows how to pair up a great algorithm with great code!”
Input name matches defined “special” name, or random number is 9: “, you’re the best!”"
HEY WHAT'S UP
HAVE YOU ALREADY FINISHED YOUR PROGRAM? SEND ME YOUR EMAIL MAYBE WE CAN HELP EACH OTHER. IM DOING THE SAME PROGRAM RIGHT NOW :S
Feb 17 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

114
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
5
by: Robert Oschler | last post by:
Preamble: - I know this is the Python forum - I know about (and have used) Jython I already posted this question in comp.lang.java. But after a week I have still not received a single reply....
20
by: Ilias Lazaridis | last post by:
" A cooperation between Sun Microsystems and IBM&Co. in conjunction with liberal & high evolutive communities would result in an nearly unbeatable programming platform. My evaluation has shown:...
30
by: Richard | last post by:
Level: Java newbie, C experienced Platform: Linux and Win32, Intel Another programmer and I are working on a small project together. He's writing a server process in Java that accepts input...
0
by: Limpor | last post by:
Hello, I am new to learning java, and i am trying to build the class for a calculation card game, unfortunately i can't get the public Card top() and Card takeTop() method in the Stock class. Can...
8
by: Passer By | last post by:
Has any created or not of examples of random sentence generators using n-gram models (or other models might be interesting). I know of one example from a course at MIT, but besides that nothing....
1
by: hostel | last post by:
HTML PAGE <html> <body> <form action="second.jsp" method="get"> YOur name <input type=text name="name"> <input type=submit > </form> </body> </html>
1
by: Leiram | last post by:
I am trying to write a game where there is 13 stones and you play against the computer to make sure that you don't take the last stone. You or the computer (depending on the turn) is allowed to take...
7
by: schrum312005 | last post by:
Hey guys, I'm a college student in my first programming class and I'm having trouble with an assignment. The requirements to the assignment can be found here:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.