• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

First project

 
Greenhorn
Posts: 3
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you tried so far and what specifically is giving you problems? You need to TellTheDetails(⇐click) and ShowSomeEffort.(⇐click)
 
Michael Sakara
Greenhorn
Posts: 3
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code that I have so far:

 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Ranch Hand
Posts: 208
9
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tina Smith wrote: . . . ( 'a' + 32 = 'A' I believe) . . .

System.out.println((char)('a' - 32)); // Prints A
 
Tina Smith
Ranch Hand
Posts: 208
9
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got the 'a' and 'A' mixed around I guess. Thanks for correcting me.
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic