Results 1 to 2 of 2
  1. #1
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default I am not able to print Address

    I need help with this program. I am not able to print Address through the main method

    Java Code:
    public class Employee
    {
    private String id;
    private String Address;
    
    public Employee(String id,String fname,String lname,String city,String state,String zip)
    {
    this.id = id;
    Address address = new Address(fname,lname,city,state,zip);
    
    System.out.printf(" %s\n%s\n ",id,address.toString());
    }
    public String toString()
    {
    return String.format("%s\n %s:\n ",id,Address);
    }
    public static void main (String args[])
    {
    Employee e= new Employee("1000","Vijaya","Nimma","Detroit","MI","48334");
    
    System.out.printf(e.toString());
    }
    Thanks
    Albert:rolleyes:

  2. #2
    susan is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

    Default

    First of all, where is the Address class. The following line indicates that you have a class of type Address.
    Java Code:
    Address address = new Address(fname,lname,city,state,zip);
    Second, you have declared a String and you named it Address, but you never assigned any value to it.
    Java Code:
    private String Address;
    Actually, I don't think your class can be compiled, unless you have some other code that you have not posted here.

    Solution: You must either declare a class of type Address that would handle the processing of Employee's addresses and, you must make sure that you stick to Sun Java Conventions so that other developers can read your code.
    For example, a variable should not start with a capital letter etc.

Similar Threads

  1. JSP – getting IP address
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-29-2008, 09:05 AM
  2. Print XML tag
    By DonCash in forum XML
    Replies: 2
    Last Post: 08-07-2007, 06:02 PM
  3. doubt about PRINT API
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 09:51 PM
  4. Print A Pdf
    By Jack in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 05:40 AM
  5. print .doc in java
    By Alan in forum Advanced Java
    Replies: 1
    Last Post: 05-17-2007, 04:05 AM

Posting Permissions

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