Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #31  
Old February 24th, 2013, 03:38 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Quote:
the string can only contain Vowels and Consonants

Then the code only needs to test for vowels. If the letter is NOT a vowel, it is a consonant.

The code only needs ONE loop that looks at each letter and the next letter and makes sure they are different.
The type of the first letter is not important. What needs to be tested is that the types of two adjacent letters is different.

Reply With Quote
  #32  
Old February 24th, 2013, 03:41 PM
ctroop4ever ctroop4ever is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 39 ctroop4ever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 15 m 8 sec
Reputation Power: 1
Facebook
Quote:
Originally Posted by NormR
Then the code only needs to test for vowels. If the letter is NOT a vowel, it is a consonant.

The code only needs ONE loop that looks at each letter and the next letter and makes sure they are different.
The type of the first letter is not important. What needs to be tested is that the types of two adjacent letters is different.


I actually can't do it, this has to be finished tonight and im obviously not getting this, I know what to do but when I look at the codes I just go blank, thank you for trying though.
Best wishes

Reply With Quote
  #33  
Old February 24th, 2013, 03:46 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Put the current program to rest for a while.
Write a simpler testing program that takes a String, and in a loop gets each letter of the String and prints out a message saying if that letter is a vowel or a consonant.

When that works, you can move on to the next step.

Reply With Quote
  #34  
Old February 24th, 2013, 04:15 PM
ctroop4ever ctroop4ever is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 39 ctroop4ever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 15 m 8 sec
Reputation Power: 1
Facebook
Quote:
Originally Posted by NormR
Put the current program to rest for a while.
Write a simpler testing program that takes a String, and in a loop gets each letter of the String and prints out a message saying if that letter is a vowel or a consonant.

When that works, you can move on to the next step.


Okay, I will try do that first

Reply With Quote
  #35  
Old February 24th, 2013, 04:28 PM
ctroop4ever ctroop4ever is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 39 ctroop4ever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 15 m 8 sec
Reputation Power: 1
Facebook
Okay I have that done, I created a program like that a view days ago

Reply With Quote
  #36  
Old February 24th, 2013, 04:31 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Post the code and its output.

Reply With Quote
  #37  
Old February 24th, 2013, 04:33 PM
ctroop4ever ctroop4ever is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 39 ctroop4ever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 15 m 8 sec
Reputation Power: 1
Facebook
Quote:
Originally Posted by NormR
Post the code and its output.


Code:
import javax.swing.JOptionPane;
public class AlternatingVowelsAndConsonants 
{
	public static void main(String[] args)
	{
		String userInput;

		char d;
		
		int vow = 0, con = 0;

		userInput = JOptionPane.showInputDialog(null, "Enter a word ");

		String strippedInput = userInput.replaceAll("\\W", "");

		String strippedInput1 = strippedInput.toLowerCase();

		int c = strippedInput1.length();
		
if (userInput.equals(""))
			
		{
			JOptionPane.showMessageDialog(null, "Invalid. Input is required.");
		}

else 
	
	
	for(int index = 0; index <= c-1; index++)
		
	{
		
	d = strippedInput1.charAt(index);
	
	if (d == 'a' || d == 'A' || d == 'e' || d == 'E' || d == 'i' || d == 'I'
			|| d == 'o' || d == 'O' || d == 'u' || d == 'U')
	
	{
	vow++;
	
	}
	
	else
	{
	con++;
	}
	}
	System.out.println("The no of vowels are " + vow);
	System.out.println("the no of consonants are " + con);
	}
}

Reply With Quote
  #38  
Old February 24th, 2013, 04:40 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Now add code immediately following where the counters (vow and con) are incremented to look at the next letter (at index+1) and test that its type (vowel or consonant) is different than the type just found. You'll need to change the looping control to use < vs <= to keep from going past the end of the String.

Reply With Quote
  #39  
Old February 24th, 2013, 04:48 PM
ctroop4ever ctroop4ever is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 39 ctroop4ever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 15 m 8 sec
Reputation Power: 1
Facebook
Quote:
Originally Posted by NormR
Now add code immediately following where the counters (vow and con) are incremented to look at the next letter (at index+1) and test that its type (vowel or consonant) is different than the type just found. You'll need to change the looping control to use < vs <= to keep from going past the end of the String.


I dont know how to do that, how do I test that its type is different from the type just found??

Reply With Quote
  #40  
Old February 24th, 2013, 04:53 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Quote:
test that its type is different from the type just found??

When you have found a vowel and are incrementing the vow variable, you know that the current type is a vowel. The different type will be a consonant. So look at the next letter and see if it a consonant.

If you have found a consonant and are incrementing the con variable, you know that the current type is a consonant. The different type will be a vowel. Look at the next letter and see if it is a vowel.

Reply With Quote
  #41  
Old February 24th, 2013, 04:56 PM
burakaltr burakaltr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 46 burakaltr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 55 m 44 sec
Reputation Power: 0
Sorry to interrupt but code below might get you negative score from your instructor

Code:
d = strippedInput1.charAt(index);
	
	if (d == 'a' || d == 'A' || d == 'e' || d == 'E' || d == 'i' || d == 'I'
			|| d == 'o' || d == 'O' || d == 'u' || d == 'U')



since d is already LowerCase

Reply With Quote
  #42  
Old February 24th, 2013, 04:58 PM
ctroop4ever ctroop4ever is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 39 ctroop4ever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 15 m 8 sec
Reputation Power: 1
Facebook
Quote:
Originally Posted by NormR
When you have found a vowel and are incrementing the vow variable, you know that the current type is a vowel. The different type will be a consonant. So look at the next letter and see if it a consonant.

If you have found a consonant and are incrementing the con variable, you know that the current type is a consonant. The different type will be a vowel. Look at the next letter and see if it is a vowel.


I honestly dont know how to code that, you must think im so slow i use index + 1 yes, where do I put that though? on its on? twice like once after the vow and once after the con, or what? and how do I make it say basically this letter is a vowel, if the next letter is a consonant keep checking the rest to see if the pattern continues?? i dont know how to finish coding this

Reply With Quote
  #43  
Old February 24th, 2013, 05:02 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Quote:
once after the vow and once after the con

Yes there needs to be a test after each.

Quote:
keep checking the rest

The looping will take care of testing the rest of the letters.

Reply With Quote
  #44  
Old February 24th, 2013, 05:05 PM
burakaltr burakaltr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 46 burakaltr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 55 m 44 sec
Reputation Power: 0
You Must implement a method, may be static

isVoWel(char c)

or else

isConsonant(char c)

Otherwise, there seems to be no way to a Sol'n

Reply With Quote
  #45  
Old February 24th, 2013, 05:05 PM
ctroop4ever ctroop4ever is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 39 ctroop4ever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 15 m 8 sec
Reputation Power: 1
Facebook
Quote:
Originally Posted by NormR
Yes there needs to be a test after each.


The looping will take care of testing the rest of the letters.


How would I alter it to say it is alternating, or its not?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Homework - Alternating vowels and consonants

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap