• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

need help

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI HOW'S EVERYBODY DOIN?

I AM WORKING ON THIS CODE, THERE ARE SOME ERROR PLS HELP ME FIX THESE.
THE PROGRAM SUPPOSE TO DO.
1. Ask the user to type in a sentence, using a JOptionPane.showInputDialog().
2. The program will scan the string and count how many upper-case letters appear, and how many
lower-case letters appear.
3. Tell the user how many upper/lower case letters there were using a
JOptionPane.showMessageDialog()
4. Repeat this process until the user types the word "Stop".

here's the program

public class project {
public static void main (String [] args)
{
String sentece = JOptionPane.showinputDialog ( "Please enter a sentence.")
While (! line.equals ("STOP")
System.out.println("Your string contains "
+ lowercaseLCVowelCount(line)
+ " Number of lower case letters:");
System.out.println("Your string contains "
+ uppercaseLCVowelCount(line)
+ " Number of lower case letters");
System.exit(0);
}

public static int lowercasepro(String text)
{
int count = 0;
for ( int i = 0; i < text.length(); i++ )
{
char x = text.charAt(i);
if ( x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u'
)
count++;
}

public static int uppercasepro(String text)
{
int count = 0;
for ( int i = 0; i < text.length(); i++ )
{
char x = text.charAt(i);
if ( x == 'A' || x == 'E' || x == 'I' || x == 'O' || x == 'U'
)
count++;
return count;
}
}
 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't quite make sense,
You're using JOptionPane, which is a swing class, so you need to import the class, or all the classes...
either of these is fine:
A) import javax.swing.JOptionPane;
B) import javax.swing.*;

The String line, hasn't been declared or initialized in main,
and sentence is spelt wrong.

You have the called the methods:
lowercaseLCVowelCount(String line),
uppercaseLCVowelCount(String line), but they don't appear in the code.

For the method you defined:
public static int lowercasepro(String text)
it should return an int, maybe you need return count;

Also, when posting code on here, its better to use the CODE tags,
underneath, so that the code is indented properly, and is easier to read.

The program is very simple, if you put it together first, so it makes more sense, then I can tell you where your error(s) are.


The code is very nearly correct, I see you have created 2 methods, one to scan for uppercase letters, and one for lowercase.
Theres many of ways of doing this, you could use 1 scan with one void method, so that it increments the two static class members upper, and lower, instead of returning anything.

The choice is yours
[ September 24, 2006: Message edited by: colin shuker ]
 
samen jaames
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have fixed the code little (as far as i understood), i think this method is wroing "lowercaseLCVowelCount(String line)" becuase i am suppose to be counting number of letters in upper and lowercase,
here's the new code




import javax.swing.*;

public class project {
public static void main (String [] args)
{
String line = JOptionPane.showinputDialog ( "Please enter a sentence.")
While (! line.equals ("STOP")
System.out.println("Your string contains "
+ lowercaseLCVowelCount(line)
+ " Number of lower case letters:");
System.out.println("Your string contains "
+ uppercaseLCVowelCount(line)
+ " Number of Upper case letters");
System.exit(0);
}

public static int lowercasepro(String text)
{
int count = 0;
for ( int i = 0; i < text.length(); i++ )
{
char x = text.charAt(i);
if ( x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u'
)
count++;
}

public static int uppercasepro(String text)
{
int count = 0;
for ( int i = 0; i < text.length(); i++ )
{
char x = text.charAt(i);
if ( x == 'A' || x == 'E' || x == 'I' || x == 'O' || x == 'U'
)
count++;
return count;
}
}


please fix this code and put the notes on the codes what i am doing wrong , i really appericate this,thanks bro
 
samen jaames
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
messed up let me put the code in codes:

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those methods are very clearly counting the numbers of upper and lower case vowels -- i.e., only the letters aeiou or AEIOU. That doesn't seem to be what the problem is asking for!
 
samen jaames
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i know my code is messed up, and i don't have much of the kownlege to fix this, so please help me fix this.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks like an assignment that you are supposed to do, so that you learn something about programming in Java. So we won't just do the work for you. You'll have to describe what you think the code is doing so far, and what it is actually doing, and where you are stuck fixing it so that it does what you think it should do. Given that, we'll be glad to help you get going again.
 
samen jaames
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, i'll do it, here's new version of program , please tell me what to do next, and how many things i need to fix
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's certainly an improvement as far as upper and lower case goes, but it's really not a very "Java-like" solution. Java characters are 16-bit Unicode characters; they can represent many alphabets besides just the Roman "ASCII" character set. Check out the java.lang.Character class for some methods that will help you do this in a more Java-like way.

As far as getting the whole thing to compile: there are some missing close-braces ("}"), and some missing or misplaced "return" statements. Remember that each method or block both begins and ends with a curly brace, and "return" is the last thing a method will do.
your
In the future, you might try writing these kinds of programs one method at a time: write your "lowercase" method, get it to compile, write a little main() that just tests it; then write the next function, and don't proceed until it compiles and you've tested that it works. Continue like this until you've written the whole thing. Don't write everything at once, and then try to fix the compiler errors; that can be rather overwhelming. Just take little steps.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, first your method names need to match.
Your calling a method that doesn't exist.

Your while loop isn't right either
Since you want to continuously accept input,
the line=JOptionPane... should be inside the while loop,
somehting like this.


Notice that when you enter STOP, it will give tell you had 4 uppercase letters. So you will have to tweak it a little, maybe use a DO-WHILE.
 
samen jaames
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok i am doing this from last 6 hours , still no luck yet please can somebody do this for me, i know i am asking for to do my assignment but i changed my school this semster and in new school i am supposed to do this program from old class knowlege but i didn't learn in this from my old school, and i have to hand this in tomrr. pleasse somebody help me out. i am happy to help somebody else out in this forum, like computer hardware or softerware problems. please help me out

 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, we've given you a lot of advice, but it doesn't look like you took any of it. Try making the changes we suggested, and see how that works out for you.

Note that if someone just does the work for you, then you still don't learn anything, and you're in even more trouble the next time.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this..., but next time, try and figure out why your program doesn't work!

[ September 24, 2006: Message edited by: colin shuker ]
 
samen jaames
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks man really aperciate it, thanks
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Colin --

Next time you do that, I'll lock your account and block your IP address. I mean it.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, thats not very nice. I was only helping him.
I understand that getting it on a plate is not the best way to learn.
I think he tried pretty hard, but just hasn't got to grips with it yet.
Anyway, he had practically done it already, except his while loop didn't make sense.
If he wasn't in a rush to get it done, I wouldn't have given him the whole solution, but just guided him towards it more.
Maybe its just me, but I don't think people learn very well when they are stressed out and in a rush to get things completed.
I never realised it was a crime to help someone in need.

I just read a quote from the link above about homework...


If you see a post that you suspect is school-related work, and you believe that it is wrong to help students with their homework, then do not help.


Well in this instance I did not think it was wrong, considering the code was pretty much already there. So according to that quote I did nothing wrong, so why am I being threatened with being taken off?
[ September 24, 2006: Message edited by: colin shuker ]
 
samen jaames
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think you have been on my postion, that's why you understood and helped me out, i just want thanks again and pls don't stop helping other people out.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doing other people's work for them is not helping them; it's hurting them. It might be helping them to pass an assignment or a course; but it's not helping them learn anything. You're robbing the person of the opportunity to learn.

I'm sorry if you don't understand. Take an ethics class when you have the chance.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, why spend 6 hours learning something, when you can learn it in 30 mins.
I hope you figured out how the while block works now.
Be careful not to do...

since the semi-colon will stop the block executing.
That applies to FOR , DO-WHILE, IF blocks too.
Make sure when you call a method, it exists first, your method names weren't matching.
If a method is void, you can't return anything, but otherwise you must return whatever the return-type is.
In fact, if the return type is double, you can return an int, since an int fits into a double.
You might want to try rewriting program with a DO-WHILE loop instead, I'm assuming you have a book/notes on java.
Good luck!
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I disagree to some extent, seeing a solution to a problem and then following up the solution and making sure you understand it makes learning a lot easier.
For example, I've just been learning how to save files using JFileChooser, it would have taken me a long time to figure out without seeing an example of it, and I wouldn't know if I was doing it the standard way if I didn't look at a complete solution of it.
Anyway, I learnt how to do it much more efficiently by seeing how it was done first.
I never forced this individual to use my code, they have the right to learn or not learn how they choose.
If he uses the code correctly by making sure he understands it, and then trying more examples it will help him learn.
Whereas if he just uses it to pass the assignment, it won't help him learn since its the easy way out.
Surely thats upto the programmer how they choose to learn.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He won't make sure he understands it. He previously demonstrated unwillingness to take even simple suggestions, such as fixing unbalanced braces; he was waiting for someone to simply do the assignment for him. And so you finally did. When he comes back the next time, don't expect the state of his knowledge to have advanced.
 
samen jaames
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first thing i understood, and next time i'll post a code here, it will be more advanced and much improved. remembere learning is not a one-way street, it's two-way.
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic