jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes First project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "First project" Watch "First project" New topic
Author

First project

Michael Sakara
Greenhorn

Joined: Mar 14, 2012
Posts: 3

Hi I have a project that I need some help with. I need to create my own StringClass it should be a charcter array using this StringClass array I need to write a method to reverse the charcters in the string on the console I need to show the sting normal and then on the next line show the string reversed. I also need to write a method to change the case to all UPPER then all LOWER. I cannot use methods directly from the JAVA string class. Here is the string I would like in my array:
"Once upon a time in a forest far far away lived three bears."

Thanks for your help in getting me started with my first assignment,
Michael
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

What have you tried so far and what specifically is giving you problems? You need to TellTheDetails(⇐click) and ShowSomeEffort.(⇐click)
Michael Sakara
Greenhorn

Joined: Mar 14, 2012
Posts: 3

Code that I have so far:

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

I put 'code tags' around your post. See how it makes it easier to read and preserves the formatting? Please do this next time...you can highlight your source and click the 'code' button to pop them in.

Now...I have several comments.

first, this can't be all your code. this won't compile - there is no class definition, for one thing. You don't close the main method with a curly brace.

Next...NEVER write this much code before compiling. EVERY time i start a new project, I write exactly this before I compile the first time:


Once I see that works, i take out the System.out.println method, and write AT MOST 3 more lines to do something. you say you " need to write a method to reverse the charcters in the string". That to me means you need a new method. My next iteration would do just that - create a method:




I'd make sure that compiles...then i'd revise it to call that new method:


Then I'd revise the reverseMethod to print the String it gets passed unchanged. THEN i'd work on reversing it.

Only after I was sure the reverse method works would i consider starting the next method, myToUpperCase() (or whatever you want to call it).


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Michael Sakara wrote:Code that I have so far:


That answers part of my question. The part you didn't answer is: What specific problems are you having?
Michael Sakara
Greenhorn

Joined: Mar 14, 2012
Posts: 3

"That answers part of my question. The part you didn't answer is: What specific problems are you having?
Not sure how to get started coding and not using a method provided in JAVA like to.UpperCase or to.LowerCase. I need to write my own.

Thanks for any help,
Michael
Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 171
    
    5

What you know:
1. You need to create an array of characters (char) that stores the contents of the string.
2. You need to be able to tell if a character is uppercase or lowercase.
3. You need to be able to reverse an array.

It sounds like you're stuck on #2. The answer to that is that the char datatype in Java is actually a two-byte number, and each number represents a character such as 'a' or '1'. There are tables on the internet indicating which characters mean what. Unless your string class needs to support funny Russian characters or somesuch, you can probably use the ASCII table. There is a mathematical relationship between each small letter and its corresponding uppercase ( 'a' + 32 = 'A' I believe)
http://www.asciitable.com/

If your only restriction is that you can't use type String, there is a java.lang.Character class you may want to check out.

Hope this gives you a few pointers in the right direction.


Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37953
    
  22
Tina Smith wrote: . . . ( 'a' + 32 = 'A' I believe) . . .
System.out.println((char)('a' - 32)); // Prints A
Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 171
    
    5

Got the 'a' and 'A' mixed around I guess. Thanks for correcting me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: First project
 
Similar Threads
Simple Person Program
Using Logic:iterate with an string array
Viewing contents of tables with ejbs on web
Iterate a String array in Struts
JNI Global reference