aspose file tools*
The moose likes Java in General and the fly likes Question on Programming Project? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Question on Programming Project?" Watch "Question on Programming Project?" New topic
Author

Question on Programming Project?

Devon Lewis
Greenhorn

Joined: Jun 10, 2012
Posts: 6
I have question on a programming project. Here is the description : Write a program (Class name Pr1a) that prompts user to enter a sentence. The program should display each character on the screen except space character (‘ ‘). For each character, there are three possible outputs to display. They are “Upper case”, “Lower case”, and “Not a letter”. Note that if the character is a space character, then you do not display space character, and you do not display any of the three possible outputs. The program also must show total letter count, total lower case count, and total upper case count. For the total letter count, do not count the space characters, or Non-letter characters.

I was wondering how I would arrange the if else statements, in order to get the output to print whether there upper case, lower case or not a letter.

Here is my code :

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

Hi Devon,

In the future, please UseCodeTags and also not so many blank lines.

I think you're looking for a basic if-else if-else structure like:



Maybe you need an extra else-if in there to handle space characters, but it's best to start simple and then enhance until you meet all the requirements.
Devon Lewis
Greenhorn

Joined: Jun 10, 2012
Posts: 6
Thanks, I am trying to get the output to look something like this :

D : UpperCase

e - Lower Case

v- lower case

o- lower case

n - lowercase

!- not a letter.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11404
    
  16

and...what problem are you having?

Things generally work best around here if you ask SPECIFIC questions. Remember, we can't read your mind. We can't read your code (unless you post it). You should try and make it as EASY as possible for someone to help you.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

I think what you're missing is a loop structure. Have you learned about loops yet?
Devon Lewis
Greenhorn

Joined: Jun 10, 2012
Posts: 6
fred rosenberger wrote:and...what problem are you having?

Things generally work best around here if you ask SPECIFIC questions. Remember, we can't read your mind. We can't read your code (unless you post it). You should try and make it as EASY as possible for someone to help you.

The issue im having is trying to get the output to say whether each specific character in the sentence I enter, is uppercase, lowercase or not a letter. Here is my code again :

import java.util.Scanner;

public class Pr1a
{

public static void main(String[] args)
{

Scanner st = new Scanner(System.in);

String l = " ";


System.out.print("Please enter a sentence: ");

l = st.next();





char x ;

x = ' ';




if(x>='a' && x<='z'){

System.out.print( " : Lowercase" );

System.out.println(l.toLowerCase());




l = st.next();

}


else if(x>='A' && x<='Z') {

System.out.print(" : Uppercase" );

System.out.println(l.toUpperCase());





l = st.next();


}

}

}
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Devon Lewis wrote:
fred rosenberger wrote:and...what problem are you having?

Things generally work best around here if you ask SPECIFIC questions. Remember, we can't read your mind. We can't read your code (unless you post it). You should try and make it as EASY as possible for someone to help you.

The issue im having is trying to get the output to say whether each specific character in the sentence I enter, is uppercase, lowercase or not a letter.


The beginning of your code asks for a sentence, but the rest of your code only handles one letter. As someone already mentioned, you will need to have some sort of loop -- as a sentence is made up of lots of letters.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

Yes, there's no loop in that code. Your book or class must have discussed this structure, or you can just Google for "java while loops".

Also, code has to go between the opening and closing tags. Probably the easiest way to do that is to paste in your code, and then highlight it before hitting the Code button.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Question on Programming Project?