943,692 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 665
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 30th, 2009
0

please help me.. [info inside]

Expand Post »
i have a problem for this program .
how can i use the program in the middle..
i tried to put it IN .. but many error exist..

please help me with my program .. thanks..

here's the output:
Enter Name: Simplicio
Enter Password: pOLOtAn
1 Capital constant letter/s
4 lower case consonant letter/s
0 capital Vowel letter/s
4lower case Vowel letter/s
Try Again?


java Syntax (Toggle Plain Text)
  1. import java.io.*;
  2. import java.awt.Graphics;
  3. import java.util.Random;
  4. import javax.swing.*;
  5. import java.util.Scanner;
  6.  
  7. public class midquiz
  8. {
  9. public static void main (String [] args) throws IOException
  10. {
  11. //try
  12. {
  13. Scanner input = new Scanner(System.in);
  14.  
  15. String name,pass,ans;
  16. String pass1="pOLOtAn";
  17. int len;
  18. char len1[];
  19. len1 = new char[20];
  20.  
  21.  
  22. do
  23. {
  24.  
  25. System.out.println ("Username must be 8 to 15 character only.");
  26. System.out.print("Enter Username:");
  27. name = input.nextLine();
  28. len = name.length();
  29.  
  30. if (len>= 8 && len<=15)
  31. {
  32. for (int b=0;b<1;b++)
  33. {
  34. System.out.print("Enter Password:");
  35. pass=input.nextLine();
  36. if(pass.equals(pass1))
  37. {
  38. System.out.print("Alphabetical Order of your name is:");
  39. for (int c=0;c<len;c++)
  40. {
  41. len1[c]=name.charAt(c);
  42. }
  43.  
  44. //for(int d=1;d<len;d++)
  45. //{
  46. // if (let[c]>let[d])
  47. // {
  48. // char temp=let[c];
  49. // let[c]=let[d];
  50. // let[d]= temp;
  51. // }
  52. // }
  53.  
  54. for (int c=0;c<len;c++)
  55. {
  56. System.out.println(len1[c]+"");
  57. }
  58. }
  59. else
  60. {
  61. System.out.println("You Have Enter Wrong PassWord ");
  62. System.exit(0);
  63. }
  64.  
  65.  
  66. }
  67.  
  68.  
  69. }
  70. else
  71. {
  72. System.out.println("ILLEGAL USER! GOODBYE....");
  73. System.exit (0);
  74. }
  75.  
  76.  
  77. System.out.println("\n Try Again? [Yes/No]:");
  78. ans=input.nextLine();
  79.  
  80. }while (ans.equalsIgnoreCase ("Yes"));
  81.  
  82. }
  83.  
  84. }
  85. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
MonicaClare is offline Offline
27 posts
since Jul 2009
Jul 30th, 2009
0

Re: please help me.. [info inside]

what exactly is the problem? it is a little unclear to me...
Reputation Points: 85
Solved Threads: 64
Practically a Master Poster
sillyboy is offline Offline
686 posts
since Mar 2007
Jul 30th, 2009
0

Re: please help me.. [info inside]

Click to Expand / Collapse  Quote originally posted by sillyboy ...
what exactly is the problem? it is a little unclear to me...
uuhhmm..

the main problem of this program is..

i can't use the middle part of the code ,,

there is something wrong ..

it cannot run when i use the middle part of my program ..

hhmm.. sorry for my unclear explanation ..

please help me.. for this.. thanks alot..
Reputation Points: 10
Solved Threads: 0
Light Poster
MonicaClare is offline Offline
27 posts
since Jul 2009
Jul 30th, 2009
0

Re: please help me.. [info inside]

it doesn't look like your code is written to do too much...

it runs fine, but fine depends on what you want it to do. if you are referring to the alphabetical ordering of characters, well it isn't happening because all you are doing is print the characters of the username in chronological order.

does that help?
Reputation Points: 85
Solved Threads: 64
Practically a Master Poster
sillyboy is offline Offline
686 posts
since Mar 2007
Jul 30th, 2009
0

Re: please help me.. [info inside]

It doesn't work because you declared a variable, "c", inside of a for loop. When that for loop ended, that variable went out of scope (was destroyed). So in the next for loop where you tried to refer to "c", the compiler has no idea what you're talking about.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Jul 30th, 2009
0

Re: please help me.. [info inside]

Click to Expand / Collapse  Quote originally posted by sillyboy ...
it doesn't look like your code is written to do too much...

it runs fine, but fine depends on what you want it to do. if you are referring to the alphabetical ordering of characters, well it isn't happening because all you are doing is print the characters of the username in chronological order.

does that help?
i want it to be like the said output ..
how will i do it?

please help me..
Reputation Points: 10
Solved Threads: 0
Light Poster
MonicaClare is offline Offline
27 posts
since Jul 2009
Jul 30th, 2009
0

Re: please help me.. [info inside]

See my post above yours. Then declare "c" on the correct scope level (i.e. declare it outside of the for loop). Then see if you're still getting errors. Post any errors you're getting.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Jul 30th, 2009
0

Re: please help me.. [info inside]

.. can you suggest or show me some code that suit for my program?

hhmm.. just asking for your consideration ..

im really sorry ..
Reputation Points: 10
Solved Threads: 0
Light Poster
MonicaClare is offline Offline
27 posts
since Jul 2009
Jul 31st, 2009
1

Re: please help me.. [info inside]

Here you go. It's a bit rough, but it does what you wanted.
The main reason it's tough to understand is because you didn't
split all your code into separate methods. If you had defined different things using individual methods and then strung it all together in main then everything would be a lot more readable.

java Syntax (Toggle Plain Text)
  1. import java.util.Scanner;
  2.  
  3. public class midquiz {
  4. // Variables
  5. private static String name;
  6. private static String passInput;
  7. private static String ans;
  8. private static CharSequence userPass="PasswOrd";
  9. private static int length;
  10. private static int passLength;
  11. private static int upperVowel = 0;
  12. private static int upperConsonant = 0;
  13. private static int lowerVowel = 0;
  14. private static int lowerConsonant = 0;
  15.  
  16. public static void main (String [] args) {
  17. Scanner input = new Scanner(System.in);
  18.  
  19. // Prompt for username
  20. System.out.print("Enter Username: ");
  21. name = input.nextLine();
  22. length = name.length();
  23.  
  24. // Check appropriate length
  25. if (length < 8 || length > 15) {
  26. System.out.print("Username must be between 8 and 15 characters in length.");
  27. return;
  28. } else;
  29. // If name appropriate, then continue
  30. // Prompt for password
  31. System.out.print("Enter Password: ");
  32. passInput = input.nextLine();
  33.  
  34. // Verify password
  35. if (passInput.contentEquals(userPass)) {
  36. System.out.println("Password valid.");
  37.  
  38. // If password is correct:
  39. for (;;) {
  40. passLength = passInput.length();
  41. upperVowel = 0;
  42. upperConsonant = 0;
  43. lowerVowel = 0;
  44. lowerConsonant = 0;
  45.  
  46. // Count the number of uppercase and number of lowercase consonants and vowels.
  47. for (int i = 0; i < passLength; ++i) {
  48.  
  49. Character letter = new Character(passInput.charAt(i));
  50. boolean isUpperCase = Character.isUpperCase(letter);
  51. boolean isLowerCase = Character.isLowerCase(letter);
  52. if (isUpperCase == true) {
  53.  
  54. // Identifying vowels
  55. if ( letter.equals('A') || letter.equals('E') ||
  56. letter.equals('I') || letter.equals('O') ||
  57. letter.equals('U')) {
  58. // If it's a vowel then increase capitalized vowel count
  59. ++upperVowel;
  60.  
  61. // ...otherwise, increase capitalized consonant count
  62. } else {
  63. ++upperConsonant;
  64. }
  65.  
  66. } else if (isLowerCase == true){
  67.  
  68. // Identifying vowels
  69. if (letter == 'a' || letter == 'e' ||
  70. letter == 'i' || letter == 'o' ||
  71. letter == 'u' ) {
  72. // If it's a vowel then increase lowercase vowel count
  73. ++lowerVowel;
  74.  
  75. // ...otherwise, increase lowercase consonant count
  76. } else {
  77. ++lowerConsonant;
  78. }
  79.  
  80. } else {
  81. // If you wanted to count digits as well, you could add that here.
  82. }
  83. }
  84.  
  85. System.out.println("There are " +upperVowel+ " uppercase vowels.");
  86. System.out.println("There are " +upperConsonant+ " uppercase consonants.");
  87. System.out.println("There are " +lowerVowel+ " lowercase vowels.");
  88. System.out.println("There are " +lowerConsonant+ " lowercase consonants.");
  89.  
  90. System.out.println("Try again (Re-count)? [Yes/No]: ");
  91. ans = input.nextLine();
  92. if (ans.equalsIgnoreCase("no")) {
  93. System.exit(0);
  94. }
  95. else if (ans.equalsIgnoreCase("yes")) {
  96.  
  97. } else {
  98. System.out.println("Invalid choice. Try again?");
  99. }
  100.  
  101. }
  102. }
  103.  
  104. else;
  105. // If password is incorrect:
  106. System.out.println("Invalid password.");
  107. System.out.println("Try Again? [Yes/No]:");
  108. ans=input.nextLine();
  109. // If no
  110. if (ans.equalsIgnoreCase("no")) {
  111. System.exit(0);
  112. }
  113. else;
  114.  
  115. // Whatever you want it to do.
  116.  
  117.  
  118. }
  119.  
  120. }
Last edited by Godstryke; Jul 31st, 2009 at 1:36 pm.
Reputation Points: 66
Solved Threads: 2
Newbie Poster
Godstryke is offline Offline
24 posts
since Jul 2009
Jul 31st, 2009
0

Re: please help me.. [info inside]

um.... why?

don't do the homework of others.
Reputation Points: 85
Solved Threads: 64
Practically a Master Poster
sillyboy is offline Offline
686 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Sorting problem once again....
Next Thread in Java Forum Timeline: how to evaluate if it is EVEN or ODD number?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC