1 Attachment(s)
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. .
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.
Re: PLEASE Help with developing a class with an overloaded method
Code :
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
Code :
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();
}
}
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:
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();
}
}
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..