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,
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
"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.
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)
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