Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Please Help!
Hey guys i really need some help. I'm trying to make a program that takes a
string as input e.g "AAABBCCD" and outputs a histogram of this e.g.
A ***
B **
C **
D *
I have this program (below) that simply lists the elements of the string
but doesn't produce the histogram. Does anyone have some code that
finishes it off? I've been trying for ages!
Thanks alot!


import java.io.*;

class Histogram
{
public static void main(String[] args) throws java.io.IOException
{
char c;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
String name = null;

System.out.println("Please input a string and press enter:");
try {
name = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error trying to read your name!");
System.exit(1);
}

//change string to uppercase
name = name.toUpperCase();

for(int i = 0; i < name.length() ; i++ )
{
/*
This for loop would go through each letter in the string.
Everytime you encounter a letter see if you've
already seen the letter or not and keep count of each letter
you have encountered.
*/
//Just default output to show for loops is functional
System.out.println(""+name.charAt(i));
}
}
}


Report this thread to moderator Post Follow-up to this message
Old Post
the_real_g
10-22-04 01:56 PM


Re: Please Help!
On Fri, 22 Oct 2004 07:15:29 -0400, the_real_g wrote:
> I have this program (below) that simply lists the elements of the
> string but doesn't produce the histogram. Does anyone have some code
> that finishes it off? I've been trying for ages!

Show us some of your failed attempts!

It looks like the only code "you" have managed to produce, is the
template your instructor gave you to get you started.

/gordon

--
[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Report this thread to moderator Post Follow-up to this message
Old Post
Gordon Beaton
10-22-04 01:56 PM


Re: Please Help!
"the_real_g" <gregriddle84@hotmail.com> schreef in bericht
 news:19e7bca86b375052219c7648b3bcc057@lo
calhost.talkaboutprogramming.com...
> Hey guys i really need some help. I'm trying to make a program that
> takes a string as input e.g "AAABBCCD" and outputs a histogram of this
> e.g.
> A ***
> B **
> C **
> D *
> I have this program (below) that simply lists the elements of the
> string but doesn't produce the histogram. Does anyone have some code
> that finishes it off? I've been trying for ages!
> Thanks alot!

Try (for yourself) to (re)formulate an algorithm using programming terms, e.
g.
numbers, datastructures and operations on them.  Then test its correctness b
y
going over the algorithm with different inputs.  Finally, implement the
algorithm in a computer program.



Report this thread to moderator Post Follow-up to this message
Old Post
Boudewijn Dijkstra
10-22-04 01:56 PM


Re: Please Help!
the_real_g wrote:

> Hey guys i really need some help. I'm trying to make a program that takes
> a string as input e.g "AAABBCCD" and outputs a histogram of this e.g.
> A ***
> B **
> C **
> D *
> I have this program (below) that simply lists the elements of the string
> but doesn't produce the histogram. Does anyone have some code that
> finishes it off?

"Finishes it off"? Your code doesn't do anything that the assignment
requires.

Rule number one: Stop asking for code.

1. Think about how the program works. What does it have to do, when, with
whst results?

2. Read your Java computer programming textbook from cover to cover.

3. Write your program.

--
Paul Lutus
http://www.arachnoid.com


Report this thread to moderator Post Follow-up to this message
Old Post
Paul Lutus
10-22-04 08:58 PM


Re: Please Help!
"the_real_g" <gregriddle84@hotmail.com> writes:

>      /*
>        This for loop would go through each letter in the string.
>        Everytime you encounter a letter see if you've
>        already seen the letter or not and keep count of each letter
>        you have encountered.
>      */

We don't exist to do your homework, but a couple of hints:

*) If you know you only will get letters, use char-'A' as offset in an
int array which counts occurences
*) Use i+'A' as the "label" afterwards.

Report this thread to moderator Post Follow-up to this message
Old Post
Tor Iver Wilhelmsen
10-23-04 01:57 AM


Re: Please Help!
Paul Lutus wrote:

<snip request for making the_real_g's homework for him>

> 1. Think about how the program works. What does it have to do, when, with
> whst results?

And this, I would stress, is the really, really important part.
The motto "Divide and conquer" is the programmer's best friend.
After you know *what* you want done, it's easy to break it down to a set
of sub-operations (1. do A, 2. do B, 3. do C) and then (with the help of
a textbook) write the code you need to get A, B and C done.

> 2. Read your Java computer programming textbook from cover to cover.
>
> 3. Write your program.

IMHO, it is not necessary to read the textbook from cover to cover
before beginning to write the program. What I would do (and, in some
cases, still do) is start with point 1, then start implementing the
elemants necessary and use the textbook as reference where needed.

--
-Aki "Sus" Laukkanen


Report this thread to moderator Post Follow-up to this message
Old Post
Aki \Sus\ Laukkanen
10-25-04 08:59 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:28 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.