DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2006
    Posts
    1

    Urgent Problem with Display Method in Java

    Hi...I am having some problems with a very basic Java project I am doing.

    I have problems displaying a phone Number with a space after the first four digits.


    The phoneNumber variable was declared like this using Boolean, and it works fine.
    ------------------------
    PhoneNumber
    -----------------------------
    public String getaPhoneNumber ()
    {
    return phoneNumber;
    }

    public boolean setPhoneNumber (String aPhoneNumber)
    {
    if (aPhoneNumber.length () <= 7)
    {
    return false;
    }
    if (aPhoneNumber.length () == 9)
    {
    return false;
    }
    if (aPhoneNumber.length () >= 11)
    {
    return false;
    }else {
    phoneNumber = aPhoneNumber;

    return true;
    }

    }
    -----------------------------------------------------------
    This is the display bit of the code:
    ----------------------------------------------------------------
    public void display()
    {
    System.out.println(name);
    System.out.println(streetAddress);
    System.out.println(suburb + " " + postCode);

    System.out.println("Phone:" + " " + phoneNumber);


    }
    ------------------------------------
    It is supposed to display itself like this in BlueJ:

    Fred
    9451 3353
    25 Brown Street
    Box Hillsborugh
    VIC 3111
    ---------------------------------
    (i cant seem to display the space for the phone number after the first 4 digits as shown above)
    Any help would be appreciated.

    Many Thanks

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    Takes a phone number (7 or 10 digits) and splits it up.
    Code:
    String number = "8004579611";
    		int len = number.length();
    		String end = number.substring(len-4,len);
    		String first = number.substring(len-7,len-4);
    		String area = number.substring(0,len-7);
    		System.out.println(area+"-"+first+"-"+end);

Similar Threads

  1. display problem
    By lacanaupro in forum Java
    Replies: 0
    Last Post: 05-21-2005, 05:00 PM
  2. problem with java frames URGENT!!!!
    By ramanand in forum Java
    Replies: 0
    Last Post: 10-17-2000, 05:34 AM
  3. ODBC Problem (urgent)
    By Ken Mui in forum Web
    Replies: 6
    Last Post: 10-09-2000, 11:46 AM
  4. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 04:50 AM
  5. private and static
    By Mark in forum Java
    Replies: 3
    Last Post: 06-09-2000, 08:18 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links