Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 9th, 2004, 01:12 PM
Big Reed Big Reed is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 1 Big Reed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Student needs help.

I need help like yesterday. I am in a programing class at vatterott College & We are supposed to create a program on Java that counts how many time each letter in the alphebet appear in the word Supercalifragilisticexpialidocious. How do I get the program to count through a loop in this manner. I am very new to programing and really need help.
thank you.

Reply With Quote
  #2  
Old September 10th, 2004, 10:09 AM
maxpower3141 maxpower3141 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 2 maxpower3141 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
// This is done entirely with raw force..
// So more elegant approaches will exist
// But it works..
// See the Java API at java.sun.com
// if you don't know some of the method
// calls.
// The only "Special" classes I use, are
// String and java.util.Vector
// If you want to learn something
// read it through and then write it
//yourself - and make it better
// (The double loops (that I use)
// often tend to go to these O(n^2)
// Algorithms, but actually in this
// case the complexity
// is asymptotically O(n) - can you see
// why? But of course a much better
// O(n) alg (with smaller coefficient)
// can be
// found that does the same thing.

/*
* Created on Sep 10, 2004
*
*/
package test;

import java.util.Vector;

/**
* @author
*
*/
public class countLetters {

/**
*
*/
public countLetters(String[] args) {
if (args == null || args.length < 0)
System.out.println("No letters");
Vector letters = new Vector();
String s;
Vector words = new Vector();
for (int i=0;i<args.length;i++){
s = args[i];
if (s != null){
putLettersFromStringToVector(s, letters);
words.add(s);
}
}
System.out.println("The words \n\""+words+"\"\n have the following letters:\n");
Letter l;
for (int i=0;i<letters.size();i++){
l = (Letter)letters.get(i);
if (l != null){
System.out.println("The letter \""+l.letter+"\" is repeated "+l.numberOfTimes+" times");
}
}
}

public static void main(String[] args) {
// new countLetters(args);
String[] ss = {"Vittu" ,"Perkele", "SaAaaTana"};
new countLetters(ss);
}

public void putLettersFromStringToVector(String s,Vector v){
if (s == null)
return;
String s2 = s.toLowerCase();
String s3;
Letter l;
boolean found;
for (int i=0;i<s.length();i++){
s3 = s2.substring(i, i+1);
found = false;
for (int j=0;j<v.size() && !found;j++){
l = (Letter)v.get(j);
if (l != null){
if (l.letter.compareTo(s3) == 0){
l.numberOfTimes++;
found = true;
}
}
}
if (!found){
v.add(new Letter(s3,1));
}
}
}

private class Letter {
private String letter;
private int numberOfTimes = 0;

private Letter(String letter,int numberOfTimes){
this.letter = letter;
this.numberOfTimes = numberOfTimes;
}
}
}

// What? The editor doesn't take
// tabs?? The code looks horrible
// without indentations.

Reply With Quote
  #3  
Old September 13th, 2004, 02:04 PM
cup_o_java cup_o_java is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 4 cup_o_java User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
think twice about using posted code in your project

Quote:
Originally Posted by Big Reed
I need help like yesterday. I am in a programing class at vatterott College & We are supposed to create a program on Java that counts how many time each letter in the alphebet appear in the word Supercalifragilisticexpialidocious. How do I get the program to count through a loop in this manner. I am very new to programing and really need help.
thank you.

I have heard of quite students in comp sci classes that ask for code on forums that their teachers read, they get caught using posted code, and they get either expelled or severely reprimanded(including failure of the class).

If you want to use forums, I believe it's ok to ask for specific help such as "How do I instantiate an object in Java?" or "How to I print output to the console?" etc. I suggest checking with your professor first and get their policy on using forums for help with projects. You don't want all your hard work, time , and money you spent going to college to go for nothing if you get kicked out for some silly little java project.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Student needs help.


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT