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:
  #76  
Old February 24th, 2013, 07:25 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
Quote:
Originally Posted by ctroop4ever
*woman and thank you

Well, I Found the Simplest Sol'n.

I can post here, on Demand.

Please , Let Me Know.

Thanks !

Reply With Quote
  #77  
Old February 24th, 2013, 07:35 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,951 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 29 m 42 sec
Reputation Power: 345
@burakaltr Why not let the OP learn how to program? Posting full code doesn't really teach an OP how to solve problems.

See this: Problem with spoonfeeding

Reply With Quote
  #78  
Old February 24th, 2013, 07:36 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
Quote:
Originally Posted by NormR
@burakaltr Why not let the OP learn how to program? Posting full code doesn't really teach an OP how to solve problems.

See this: Problem with spoonfeeding


Yes Sir. OK.

Sorry.

Reply With Quote
  #79  
Old February 25th, 2013, 05:03 AM
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 burakaltr
Yes Sir. OK.

Sorry.


So what was the coding? I wont be using it because I changed my question but I'd like to know

Reply With Quote
  #80  
Old February 25th, 2013, 05:08 AM
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
Quote:
Originally Posted by ctroop4ever
So what was the coding? I wont be using it because I changed my question but I'd like to know



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

		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();
		boolean boo=true;	
 
 
int cnt=0;
boolean bb = true,a = false,b = false;;
 String str="yes";
  
for(int i=0;i<strippedInput1.length()-1;i++){
	
	d = strippedInput1.charAt(i);
	char d2=strippedInput1.charAt(i+1);
	
	boolean dV= (d == 'a' || d == 'A' || d == 'e' || d == 'E' || d == 'i' || d == 'I'
			|| d == 'o' || d == 'O' || d == 'u' || d == 'U')  ;
	boolean dC= (d != 'a' && d != 'A' && d != 'e' &&d != 'E' && d != 'i' && d != 'I'
				&& d != 'o' && d != 'O' && d != 'u' && d != 'U') ; 
	
	
	
	boolean  d2V= (d2 == 'a' || d2 == 'A' || d2 == 'e' || d2 == 'E' || d2 == 'i' || d2 == 'I'
			|| d2 == 'o' || d2 == 'O' || d2 == 'u' || d2 == 'U')  ;
	
	boolean d2C= (d2 != 'a' && d2 != 'A' && d2 != 'e' && d2 != 'E' && d2 != 'i' &&d2 != 'I'
				&&d2 != 'o' && d2 != 'O' &&d2 != 'u' && d2 != 'U') ; 
 


	 //System.out.println(dV&&d2V || dC&&d2C);
	 if(dC&&d2C){
		 str="NOT";
		 ;
	 }
	 
	 
	 if(dV&&d2V){
		 str="NOT";
 ;	 }
	 
	 
	 
	 
	 
	 
	 
	 
	 
/*	if(dV&&d2V ==true){
		
		str="NOT"; }
	
if(dC&&d2C ==true){
	str="NOT"; 
	 }
	
	  */
	/*
	
	 if(dV&&d2V){
		 str="NOT";break;
		 
	 }
	 
	 if(dC&&d2C){
		 str="NOT";break;
		 
	 }	 
	 
	 */
	 
}
	
System.out.println(str);

	}}
Comments on this post
Aurum84 disagrees: remove commented-out code , alot of redundancy in code

Reply With Quote
  #81  
Old February 25th, 2013, 05:33 AM
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 burakaltr
Code:
import javax.swing.JOptionPane;
public class AlternatingVowelsAndConsonants 
{
	public static void main(String[] args)
	{
		String userInput,not = "";

		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();
		boolean boo=true;	
 
 
int cnt=0;
boolean bb = true,a = false,b = false;;
 String str="yes";
  
for(int i=0;i<strippedInput1.length()-1;i++){
	
	d = strippedInput1.charAt(i);
	char d2=strippedInput1.charAt(i+1);
	
	boolean dV= (d == 'a' || d == 'A' || d == 'e' || d == 'E' || d == 'i' || d == 'I'
			|| d == 'o' || d == 'O' || d == 'u' || d == 'U')  ;
	boolean dC= (d != 'a' && d != 'A' && d != 'e' &&d != 'E' && d != 'i' && d != 'I'
				&& d != 'o' && d != 'O' && d != 'u' && d != 'U') ; 
	
	
	
	boolean  d2V= (d2 == 'a' || d2 == 'A' || d2 == 'e' || d2 == 'E' || d2 == 'i' || d2 == 'I'
			|| d2 == 'o' || d2 == 'O' || d2 == 'u' || d2 == 'U')  ;
	
	boolean d2C= (d2 != 'a' && d2 != 'A' && d2 != 'e' && d2 != 'E' && d2 != 'i' &&d2 != 'I'
				&&d2 != 'o' && d2 != 'O' &&d2 != 'u' && d2 != 'U') ; 
 


	 //System.out.println(dV&&d2V || dC&&d2C);
	 if(dC&&d2C){
		 str="NOT";
		 ;
	 }
	 
	 
	 if(dV&&d2V){
		 str="NOT";
 ;	 }
	 
	 
	 
	 
	 
	 
	 
	 
	 
/*	if(dV&&d2V ==true){
		
		str="NOT"; }
	
if(dC&&d2C ==true){
	str="NOT"; 
	 }
	
	  */
	/*
	
	 if(dV&&d2V){
		 str="NOT";break;
		 
	 }
	 
	 if(dC&&d2C){
		 str="NOT";break;
		 
	 }	 
	 
	 */
	 
}
	
System.out.println(str);

	}}


Oh so basically you check if it's not alternating only then say it is if that fails? That is simple I changed my question to checking if a sentence is a palidrome or not, that was easier

Reply With Quote
  #82  
Old February 25th, 2013, 05:34 AM
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
Quote:
Originally Posted by ctroop4ever
Oh so basically you check if it's not alternating only then say it is if that fails? That is simple I changed my question to checking if a sentence is a palidrome or not, that was easier


Yes, You do that !

And

"ta daaa"
Comments on this post
ctroop4ever agrees: Thank you

Reply With Quote
  #83  
Old February 25th, 2013, 05:39 AM
Aurum84 Aurum84 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 74 Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 23 h 5 m 49 sec
Reputation Power: 17
Quote:
Originally Posted by ctroop4ever
So what was the coding? I wont be using it because I changed my question but I'd like to know


Try to approach such problems by first make simulations on paper, then create testcases and then bake code:

Code:
public class alternatingApp
{

	public static void main(String[] args)
	{
	
		runTestCasesAlternate();
	
	}	
	
	public static final String vowels = "aeiou";
	
	public static boolean isVowel(char v)
	{
		return vowels.indexOf(v)>-1;
	}
	
	public static boolean isConsonant(char v)
	{
		return !isVowel(v);
	}
	
	public static boolean isAlternating(String s)
	{
		if(s==null)
		{
			return false;
		}
		if(s.length()==0 || s.length()==1)
		{
			return true;
		}
		for(int index=0;index<s.length()-1;index++)
		{
			char current = s.charAt(index);
			char next = s.charAt(index+1);
			if((isVowel(current) && isVowel(next)) || (isConsonant(current) && isConsonant(next)))
			{
				System.out.println(current + "  " + next);
				return false;
			}
		
		}
		return true;
	}
	
	public static void runTestCasesAlternate()
	{
		String[] alternatingWords = {"baker","ape","animal","a",""};
		boolean expectedResultAlternatingWords = true;
		int correct=0;
		for(String word: alternatingWords)
		{
			System.out.println("testing " + word + " on alternating consonants and vowels");
			boolean alternating = isAlternating(word);
			if(alternating == expectedResultAlternatingWords)
			{
				correct++;
			}
			else
			{
			
			System.out.println();
				System.out.println("expected result: " + expectedResultAlternatingWords);
				System.out.println("gained result " + alternating);	
			}
		}
		
		String[] notAlternatingWords = {"adding","bakery","plus","coffee",null};
		boolean expectedResultNotAlternatingWords = false;
		for(String word: notAlternatingWords)
		{
			System.out.println("testing " + word + " on alternating consonants and vowels");
			boolean alternating = isAlternating(word);
			if(alternating == expectedResultNotAlternatingWords)
			{
				correct++;
			}
			else
			{
				System.out.println();
				System.out.println("expected result: " + expectedResultNotAlternatingWords);
				System.out.println("gained result " + alternating);	
			}
		}
		
		System.out.println("========");
		System.out.println(correct + "/" + (alternatingWords.length + notAlternatingWords.length));
	
	
	}
}


Reply With Quote
  #84  
Old February 25th, 2013, 05:46 AM
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
Quote:
Originally Posted by Aurum84
Try to approach such problems by first make simulations on paper, then create testcases and then bake code:

Code:
public class alternatingApp
{

	public static void main(String[] args)
	{
	
		runTestCasesAlternate();
	
	}	
	
	public static final String vowels = "aeiou";
	
	public static boolean isVowel(char v)
	{
		return vowels.indexOf(v)>-1;
	}
	
	public static boolean isConsonant(char v)
	{
		return !isVowel(v);
	}
	
	public static boolean isAlternating(String s)
	{
		if(s==null)
		{
			return false;
		}
		if(s.length()==0 || s.length()==1)
		{
			return true;
		}
		for(int index=0;index<s.length()-1;index++)
		{
			char current = s.charAt(index);
			char next = s.charAt(index+1);
			if((isVowel(current) && isVowel(next)) || (isConsonant(current) && isConsonant(next)))
			{
				System.out.println(current + "  " + next);
				return false;
			}
		
		}
		return true;
	}
	
	public static void runTestCasesAlternate()
	{
		String[] alternatingWords = {"baker","ape","animal","a",""};
		boolean expectedResultAlternatingWords = true;
		int correct=0;
		for(String word: alternatingWords)
		{
			System.out.println("testing " + word + " on alternating consonants and vowels");
			boolean alternating = isAlternating(word);
			if(alternating == expectedResultAlternatingWords)
			{
				correct++;
			}
			else
			{
			
			System.out.println();
				System.out.println("expected result: " + expectedResultAlternatingWords);
				System.out.println("gained result " + alternating);	
			}
		}
		
		String[] notAlternatingWords = {"adding","bakery","plus","coffee",null};
		boolean expectedResultNotAlternatingWords = false;
		for(String word: notAlternatingWords)
		{
			System.out.println("testing " + word + " on alternating consonants and vowels");
			boolean alternating = isAlternating(word);
			if(alternating == expectedResultNotAlternatingWords)
			{
				correct++;
			}
			else
			{
				System.out.println();
				System.out.println("expected result: " + expectedResultNotAlternatingWords);
				System.out.println("gained result " + alternating);	
			}
		}
		
		System.out.println("========");
		System.out.println(correct + "/" + (alternatingWords.length + notAlternatingWords.length));
	
	
	}
}



Sir, you disagree , but

" Aurum84 disagrees: remove commented-out code , alot of redundancy in code "

I worked on it and after many updates and re-runs I got it to work and was excited to post it sooner.

I think I do not merit that.

(

Reply With Quote
  #85  
Old February 25th, 2013, 05:51 AM
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 burakaltr
Sir, you disagree , but

" Aurum84 disagrees: remove commented-out code , alot of redundancy in code "

I worked on it and after many updates and re-runs I got it to work and was excited to post it sooner.

I think I do not merit that.

(


I am running it now and it is great to see the program actually working! even if i am not using it it would kill me to never see it actually work, thank you for sitting down and actually figuring it out, i never go on these websites but i was desperate, its nice to know there are people out there that like to help others

Reply With Quote
  #86  
Old February 25th, 2013, 05:55 AM
Aurum84 Aurum84 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 74 Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 23 h 5 m 49 sec
Reputation Power: 17
I agree, there is a difference between "disagree" and "disagree".
I certainly acknowledge your willingness to help the OP in his or her quest for the solution of this java-problem. For that I can only applaud!

You were very keen to provide a solution fast. This, offcourse, is nice for an OP, since the problem is solved, yet there is hardly any room for learning of this solution. But good of you that you held yourself back in that.

I understand that you were very happy to provide the solution after the deadline, and you are more than allowed to do so. The only reason I disagreed on it, was because of the quality of the code.

Reply With Quote
  #87  
Old February 25th, 2013, 06:13 AM
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
Thx

Thanks for All Disagree's and Agree's.

This, here, is a Great Community. I anticipate to be improving my JAVA Knowledge a great deal on this site through all the Feedback.

Have A Nice Week, Everyone !

Reply With Quote
  #88  
Old February 25th, 2013, 06: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
Quote:
Originally Posted by ctroop4ever
I am running it now and it is great to see the program actually working! even if i am not using it it would kill me to never see it actually work, thank you for sitting down and actually figuring it out, i never go on these websites but i was desperate, its nice to know there are people out there that like to help others


As Far as Better Coding goes...

Code:
import javax.swing.JOptionPane;
public class AlternatingVowelsAndConsonants 
{
	public static void main(String[] args)
	{
		String userInput,not = "";
		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();
		boolean boo=true;	
 int cnt=0;
boolean bb = true,a = false,b = false;;
 String str="yes";
 for(int i=0;i<strippedInput1.length()-1;i++){
	d = strippedInput1.charAt(i);
	char d2=strippedInput1.charAt(i+1);
	boolean dV= Vowel.indexOf(d)!=-1;
    boolean dC=Conso.indexOf(d)!=-1;
	boolean d2V= Vowel.indexOf(d2)!=-1; 
	boolean d2C=Conso.indexOf(d2)!=-1;
 	 if(dC&&d2C){
		 str="NOT";
		 ;
	 }
	  
	 if(dV&&d2V){
		 str="NOT";
 ;	 } 
	 
}
	
System.out.println(str);

	}
	final static String Vowel=
			"aeiıou";
	final static String Conso=
			"bcdfghjklmnpqrstvwxyz";
}

Reply With Quote
  #89  
Old February 25th, 2013, 07:18 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
AND Still Better

Code:
import javax.swing.JOptionPane;
public class AlternatingVowelsAndConsonants 
{
	public static void main(String[] args)
	{
		final String Vowel=
				"aeiıou";
		String userInput,not = "";
		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();
		boolean boo=true;	
 int cnt=0;
boolean bb = true,a = false,b = false;;
 String str="yes";
 for(int i=0;i<strippedInput1.length()-1;i++){
	d = strippedInput1.charAt(i);
	char d2=strippedInput1.charAt(i+1);
	boolean dV= Vowel.indexOf(d)!=-1;
    boolean dC=Vowel.indexOf(d)==-1;
	boolean d2V= Vowel.indexOf(d2)!=-1; 
	boolean d2C=Vowel.indexOf(d2)==-1;
 	 if(dC&&d2C){
		 str="NOT";
		 ;
	 }
	 	 if(dV&&d2V){
		 str="NOT";
 ;	 } 
}
System.out.println(str);
	}

}

Reply With Quote
  #90  
Old February 25th, 2013, 07:25 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,951 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 29 m 42 sec
Reputation Power: 345
That is poorly documented code.
The variable names could be more descriptive of their purpose.
What value does dC contain?
What are the variables a and b for?

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