Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: PLEASE Help with developing a class with an overloaded method

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PLEASE Help with developing a class with an overloaded method

    Listed below is the whole problem I am working on. I have completed my Customer Class and now I am having trouble with my CustomerTest class. I am not sure if I declared my phone number variable correctly.

    In this task, you write a Customer class with an overloaded method called
    setCustomerInfo.
    Create a class called Customer and save the file as Customer.java Within the Customer class, add two overloaded methods called setCustomerInfo.
    Depending on how the setCustomerInfo method is called, it does
    one of the following:
    ● Sets the ID, name, address, and phone number for a Customer
    object. (This is the minimum information needed for a new
    Customer.)
    ● Sets the ID, name, address, phone number, and email address
    for a Customer object.
    Create a display method to display the values of all the member
    variables of the Customer class.

    This is what I am having major trouble on. I am not sure how to create two object references.

    7. In the main method of CustomerTest class write code to perform the
    following tasks:
    a. Create two object references to different Customer objects.
    b. Use each variation of the setCustomerInfo method to provide
    information for each Customer object.
    c. Display the contents of each Customer object.

    My code is attached below.. I appreciate any help I am stuck and I think I am almost done. .
    Attached Files Attached Files


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: PLEASE Help with developing a class with an overloaded method

    Hello crzyblndgrl

    Welcome to the forums.

    Can you please paste your code within the [code] [ /code] tags..

    I will hopefully help you move forward shortly.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE Help with developing a class with an overloaded method

    public class Customer {
     
     
    public int customerID = 0; //Default value for Customer ID
    public String customerName = "Bentley";
    public String customerAddress = "Fort Lauderdale, FL";
    public int phoneNumber = 954-555-555;
    public String emailAddress = "beachgirl@yahoo.com";
     
    public void setCustomerInfo(int ID, String name, String address, int number){
    	customerID = ID;
    	customerName = name;
    	customerAddress = address;
    	phoneNumber = number;
    }
     
    public void setCustomerInfo(int ID, String name, String address, int number, String email){
    	customerID = ID;
    	customerName = name;
    	customerAddress = address;
    	phoneNumber = number;
    	emailAddress = email;
    }
     
    //This method displays the values for an item
     
    public void display() {
    	System.out.println("Customer ID: " + customerID);
    	System.out.println("Customer Name: " + customerName);
    	System.out.println("Customer Address: " + customerAddress);
    	System.out.println("Customer Phone Number: " + phoneNumber);
    	System.out.println("Customer Email Address: " + emailAddress);
     
    	} // end of display method
    } // end of class

    public class CustomerTest {
     
    public static void main (String args[]) {
     
    	/* Need to create two object references to different Customer ojbects.
    	   Use each variable of the setCustomerInfo method to provide information for each Customer Ojbect.
    	   Display the contents of each Customer ojbect
    	*/
     
    	Customer CustomerTest = new Customer();
        Customer.displayCustomer();
     
    }
    }

  4. #4
    Junior Member
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE Help with developing a class with an overloaded method

    Ok so I have figured out my CustomerTest a little bit. I also changed my phone number to a string. The only problem I am having now is that it is pulling the email in the first setCustomerInfo when it shouldn't be.
    One should display
    public void setCustomerInfo(int ID, String name, String address, String number){
    And the other should display:
    public void setCustomerInfo(int ID, String name, String address, String number, String email){
    But it is displaying the same thing for both, Here is my CustomerTest Code:
    public class CustomerTest {
     
    	public static void main (String args[]) {
     
    		/* Need to create two object references to different Customer objects.
    		   Use each variable of the setCustomerInfo method to provide information for each Customer Ojbect.
    		   Display the contents of each Customer ojbect
    		*/
    		Customer c1 = new Customer();//first objct reference
    		Customer c2 = new Customer();//second object reeference
    		c1.setCustomerInfo(1, "Peter", "5 Independence Way", "609-628-3327");//using each variable and displaying
    		c2.setCustomerInfo(2, "Nancy", "38 Washington Road", "301-325-4738", "nancy@yahoo.com");//using each variable and displaying
    		c1.display();
    		c2.display();
     
    	}
    }

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: PLEASE Help with developing a class with an overloaded method

    Hello crzyblndgrl,

    Please post your entire updated code and I will take a look at it..
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Accessing a method of one class in another class
    By Sai in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 23rd, 2010, 04:06 PM
  2. Help Calling Method From Another Class
    By CheekySpoon in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 15th, 2010, 10:24 AM
  3. How overloaded paint() works?
    By maikeru in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 21st, 2009, 06:13 PM
  4. (.readLine() method) of BufferedReader class
    By chronoz13 in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: October 13th, 2009, 06:59 PM
  5. How to develop plugins in Netbeans?
    By haygaurav in forum Web Frameworks
    Replies: 1
    Last Post: May 27th, 2009, 04:49 PM

Tags for this Thread