Results 1 to 9 of 9
Thread: Java Help in storing a Buffer
- 10-15-2012, 12:11 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 13
- Rep Power
- 0
Java Help in storing a Buffer
Need help adding a buffer. Please see below:
1 – Read reference string
A reference string will be read from the keyboard and stored in a buffer. Each value of the reference string will be verified and validated (or rejected).
The user will be first asked to enter the length of the reference string, and then the string itself will be entered.
2 – Generate reference string
A reference string will be randomly generated; the length of the reference string will be given by the user interactively. The string will be stored in a buffer.
Using options 1 and 2 more than once will result in overwriting the old reference string.
3 – Display current reference string
Will display the stored reference string; if there is no reference string stored yet, an error message will be displayed.
Java Code:import java.util.Random; import java.util.Scanner; public class simulator { public static void main (String[] args) { int str_len=0; StringBuilder buffer = new StringBuilder(str_len); Scanner input = new Scanner(System.in); int choice; choice=menu(input); do { switch (choice) { //Exits Program case 0: System.out.println("This program will exit!"); System.exit(0); break; //Enter length/reference value of string case 1: //simulator test= new simulator(); System.out.println("Please enter length of string "); str_len=input.nextInt(); System.out.println("Please enter reference string "); for (int i=0; i<=str_len-1;i++) { int[] count = new int[str_len]; count[i] = input.nextInt(); if (count[i]<0||count[i]>9) { System.out.println(count[i] + " is Rejected"); }//ends if else if (count[i]>0||count[i]<9) { System.out.println(count[i] + " is Validated"); //StringBuilder validate = new StringBuilder(count); }//ends if }//ends for break; case 2: //int str_len; //simulator test2= new simulator(str_len3); System.out.println("Please enter length of string "); str_len=input.nextInt(); //Math.random(); Random random = new Random(); for (int i=1; i<=str_len; i++) { System.out.println(random.nextInt(15)); }//ends for //StringBuilder validate2 = new StringBuilder(str_len); System.out.println("validate is " + buffer); break; //display reference string case 3: break; }//ends switch choice=menu(input); } while(choice!=0); }//ends main //menu public static int menu(Scanner input) { int n; System.out.println("MENU"); System.out.println("0 - Exit "); System.out.println("1 - Read reference string "); System.out.println("2 - Generate reference string "); System.out.println("3 - Display current reference string "); n=input.nextInt(); return n; }//ends menu }//ends class
- 10-24-2012, 11:54 PM #2
Re: Java Help in storing a Buffer
Sounds like a homework dump. Please ask specific questions.
- 10-25-2012, 04:08 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 13
- Rep Power
- 0
Re: Java Help in storing a Buffer
So how can I get case 2 see the string in case 1 and so forth?
- 10-25-2012, 05:23 PM #4
Re: Java Help in storing a Buffer
When I read the #2 description, it implies to me that the string should be generated randomly and not given by the user in step 1. The only thing the user does is specify the length.
- 10-25-2012, 05:42 PM #5
Member
- Join Date
- Sep 2010
- Posts
- 13
- Rep Power
- 0
Re: Java Help in storing a Buffer
ok but case 3, says to display the current string. I have yet to figure that out. I cannot display the current string in 1 or 2 because the strings are local to those cases and cannot be accessed outside of those cases..
- 10-25-2012, 05:45 PM #6
Re: Java Help in storing a Buffer
Do they have to be local?
- 10-25-2012, 06:44 PM #7
Member
- Join Date
- Sep 2010
- Posts
- 13
- Rep Power
- 0
Re: Java Help in storing a Buffer
No they do not have to be local.
- 10-25-2012, 08:26 PM #8
Re: Java Help in storing a Buffer
Then make them instance variables. Then you can always retrieve whatever the current state of the variable is.
- 10-25-2012, 10:31 PM #9
Member
- Join Date
- Sep 2010
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
JAVA storing objects
By santa in forum New To JavaReplies: 24Last Post: 02-24-2012, 02:53 PM -
Java Sound Buffer Size
By morris4019 in forum New To JavaReplies: 0Last Post: 06-10-2011, 12:51 AM -
java rmi buffer error
By ans2104 in forum NetworkingReplies: 1Last Post: 03-06-2010, 12:09 AM -
Storing Images into java through beans
By LovJava in forum New To JavaReplies: 7Last Post: 02-12-2010, 09:13 AM -
Communicating Java Server and C client using char buffer
By tryit0704 in forum NetworkingReplies: 2Last Post: 08-27-2008, 03:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks