Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Packages ...

  1. #1
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Packages ...

    Create a utility package “Utilities” with the following classes and methods:

    b. StringUtilis
    i. firstLetter()
    ii. reverse()





    package String_package;

    public class StringUtilis {

    public String reverse;
    public String c;


    public StringUtilis() {
    this.reverse = reverse;
    }

    public String reverse() {
    for (char c = 'z'; c <= 'a'; c++);
    return reverse();
    }


    }


    import String_package.StringUtilis;

    class using_StringUtilis {

    public static void main (String [] args) {

    StringUtilis s = new StringUtilis();

    System.out.println(s.reverse);
    }
    }


    Can someone help me again with this one please?

    public StringUtilis(//what shall i put in here?)
    StringUtilis s = new StringUtilis(//what shall i put in here?);

    Thanks.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    According to you're datatyping, you can put any "String" or char array in there.
    Change (or overload) you're constructor to accept a String parameter to which you can assign to this.reverse. According to you're current constructor, you're just missing that parameter signature.
    Code:
    public StringUtils(String reverse)
    {
        this.reverse = reverse
    }
    
    // Call with
    StringUtils s = new StringUtils("This is my string");
    I'm not really sure what the purpose of you're reverse function is though, and it will also give you a circular problem (much like you're previous thread, you're calling a function within a function but not controlling a breakdown for it).
    (This smells like homework :P, so no additional code sorry, tis against our rules)

    To reverse you're string (manually), iterate through each of you're values from right to left (<string>.length), and assign the values to a new char array of size string.length -1 from 0...<string>.length - 1. So, that the last character in you're given string goes into the first value of you're char array. Return you're char array as a string. <string>.charAt gets a character and a specific position in a string.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •