please help me.. [info inside]

Reply

Join Date: Jul 2009
Posts: 27
Reputation: MonicaClare is an unknown quantity at this point 
Solved Threads: 0
MonicaClare's Avatar
MonicaClare MonicaClare is offline Offline
Light Poster

please help me.. [info inside]

 
0
  #1
Jul 30th, 2009
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?


  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. }
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: please help me.. [info inside]

 
0
  #2
Jul 30th, 2009
what exactly is the problem? it is a little unclear to me...
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 27
Reputation: MonicaClare is an unknown quantity at this point 
Solved Threads: 0
MonicaClare's Avatar
MonicaClare MonicaClare is offline Offline
Light Poster

Re: please help me.. [info inside]

 
0
  #3
Jul 30th, 2009
Originally Posted by sillyboy View Post
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..
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: please help me.. [info inside]

 
0
  #4
Jul 30th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,568
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 196
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: please help me.. [info inside]

 
0
  #5
Jul 30th, 2009
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.
Out.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 27
Reputation: MonicaClare is an unknown quantity at this point 
Solved Threads: 0
MonicaClare's Avatar
MonicaClare MonicaClare is offline Offline
Light Poster

Re: please help me.. [info inside]

 
0
  #6
Jul 30th, 2009
Originally Posted by sillyboy View Post
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..
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,568
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 196
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: please help me.. [info inside]

 
0
  #7
Jul 30th, 2009
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.
Out.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 27
Reputation: MonicaClare is an unknown quantity at this point 
Solved Threads: 0
MonicaClare's Avatar
MonicaClare MonicaClare is offline Offline
Light Poster

Re: please help me.. [info inside]

 
0
  #8
Jul 30th, 2009
.. can you suggest or show me some code that suit for my program?

hhmm.. just asking for your consideration ..

im really sorry ..
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 24
Reputation: Godstryke is on a distinguished road 
Solved Threads: 2
Godstryke Godstryke is offline Offline
Newbie Poster

Re: please help me.. [info inside]

 
1
  #9
Jul 31st, 2009
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.

  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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: please help me.. [info inside]

 
0
  #10
Jul 31st, 2009
um.... why?

don't do the homework of others.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC